Skip to content

Commit

Permalink
error_panic: done
Browse files Browse the repository at this point in the history
  • Loading branch information
mysiar committed May 23, 2024
1 parent a05b21a commit e41030b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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

0 comments on commit e41030b

Please sign in to comment.