Skip to content

Commit

Permalink
Error panic (#8)
Browse files Browse the repository at this point in the history
* cov1: update to octocov-action@v4

* cov1: revert

* error_panic: done
  • Loading branch information
mysiar authored May 23, 2024
1 parent fd2ddda commit 3b9b299
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
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

0 comments on commit 3b9b299

Please sign in to comment.