Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error panic #8

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Run tests with coverage report output
run: make coverage

- uses: k1LoW/octocov-action@v1
- uses: k1LoW/octocov-action@v1
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.6] - 2024/05/23
### Changed
- Error function now panics on error


## [0.0.5] - 2024/05/22
### Added
- MIT license
Expand Down
2 changes: 1 addition & 1 deletion go_sql_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type RawSqlType map[string]interface{}

func Error(err error) {
if err != nil {
log.Fatal(err)
log.Panic(err)
}
}

Expand Down
16 changes: 15 additions & 1 deletion tests/go_sql_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package tests

import (
"database/sql"
"errors"
"fmt"
_ "github.com/mattn/go-sqlite3"
"github.com/mysiar-org/go-sql-raw"
"github.com/stretchr/testify/assert"
"testing"
)

func Test(t *testing.T) {
func TestRows2Map(t *testing.T) {
db := setupDb()
rows, err := db.Query("SELECT * FROM album ORDER BY id")
chkError(err)
Expand All @@ -33,6 +34,19 @@ func Test(t *testing.T) {
}
}

func TestError(t *testing.T) {

err := errors.New("Dummy error.")
t.Run("panics", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("function should panic")
}
}()
go_sql_raw.Error(err)
})
}

func setupDb() *sql.DB {
const file string = "test.db?mode=memory"
db, err := sql.Open("sqlite3", file)
Expand Down
Loading