Skip to content

Commit

Permalink
Remove matryer/is replace with simple internal lib (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman authored May 19, 2022
1 parent b44efc3 commit 4a10c2c
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 400 deletions.
24 changes: 11 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ module github.com/pressly/goose/v3
go 1.16

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/ClickHouse/clickhouse-go v1.5.4
github.com/denisenkom/go-mssqldb v0.12.0
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/denisenkom/go-mssqldb v0.12.2
github.com/docker/cli v20.10.14+incompatible // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/lib/pq v1.10.4
github.com/matryer/is v1.4.0
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/ory/dockertest/v3 v3.8.2-0.20220414165644-e38b9742dc7d
github.com/lib/pq v1.10.6
github.com/opencontainers/runc v1.1.1 // indirect
github.com/ory/dockertest/v3 v3.8.2-0.20220425141607-148c3da5afe5
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.1 // indirect
github.com/ziutek/mymysql v1.5.4
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/tools v0.1.10 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/sqlite v1.17.0
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
modernc.org/sqlite v1.17.2
)
239 changes: 71 additions & 168 deletions go.sum

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions internal/check/check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package check

import (
"errors"
"fmt"
"reflect"
"strings"
"testing"
)

func NoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}

func HasError(t *testing.T, err error) {
t.Helper()
if err == nil {
t.Fatal("expecting an error: got nil")
}
}

func IsError(t *testing.T, err, target error) {
t.Helper()
if !errors.Is(err, target) {
t.Fatalf("expecting specific error:\ngot: %v\nwant: %v", err, target)

}
}

func Number(t *testing.T, got, want interface{}) {
t.Helper()
gotNumber, err := reflectToInt64(got)
if err != nil {
t.Fatal(err)
}
wantNumber, err := reflectToInt64(want)
if err != nil {
t.Fatal(err)
}
if gotNumber != wantNumber {
t.Fatalf("unexpected number value: got:%d want:%d ", gotNumber, wantNumber)
}
}

func NumberNotZero(t *testing.T, got interface{}) {
t.Helper()
gotNumber, err := reflectToInt64(got)
if err != nil {
t.Fatal(err)
}
if gotNumber == 0 {
t.Fatalf("unexpected number value: got:%d want non-zero ", gotNumber)
}
}

func Bool(t *testing.T, got, want bool) {
t.Helper()
if got != want {
t.Fatalf("unexpected boolean value: got:%t want:%t", got, want)
}
}

func Contains(t *testing.T, got, want string) {
t.Helper()
if !strings.Contains(got, want) {
t.Errorf("failed to find substring %q in string value %q", got, want)
}
}

func reflectToInt64(v interface{}) (int64, error) {
switch typ := v.(type) {
case int, int8, int16, int32, int64:
return reflect.ValueOf(typ).Int(), nil
}
return 0, fmt.Errorf("invalid number: must be int64 type: got:%T", v)
}
Loading

0 comments on commit 4a10c2c

Please sign in to comment.