diff --git a/base58/base58_test.go b/base58/base58_test.go index 59f3304..8524643 100644 --- a/base58/base58_test.go +++ b/base58/base58_test.go @@ -7,42 +7,58 @@ import ( "time" "github.com/osamingo/indigo/base58" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestStdSource(t *testing.T) { - require.Equal(t, base58.StdSource(), "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") + const expect = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" + if base58.StdSource() != expect { + t.Error("should be", expect) + } } func TestMustNewEncoder(t *testing.T) { - var enc *base58.Encoder - require.NotPanics(t, func() { - enc = base58.MustNewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") - }) - require.NotNil(t, enc) + enc := base58.MustNewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") + if enc == nil { + t.Error("should not be nil") + } - require.Panics(t, func() { + func() { + defer func() { + recover() + }() base58.MustNewEncoder("") - }) + t.Error("should be panic") + }() - require.Panics(t, func() { + func() { + defer func() { + recover() + }() base58.MustNewEncoder("test") - }) + t.Error("should be panic") + }() } func TestNewEncoder(t *testing.T) { enc, err := base58.NewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") - require.NoError(t, err) - require.NotNil(t, enc) + if err != nil { + t.Error("should be nil") + } + if enc == nil { + t.Error("should not be nil") + } _, err = base58.NewEncoder("") - require.Error(t, err) + if err == nil { + t.Error("should not be nil") + } _, err = base58.NewEncoder("test") - require.Error(t, err) + if err == nil { + t.Error("should not be nil") + } } func TestEncoder_Encode(t *testing.T) { @@ -58,10 +74,14 @@ func TestEncoder_Encode(t *testing.T) { enc := base58.MustNewEncoder(base58.StdSource()) id := enc.Encode(0) - assert.Equal(t, "1", id) + if id != "1" { + t.Error("should be", "1") + } for k, v := range bc { - assert.Equal(t, v, enc.Encode(k)) + if enc.Encode(k) != v { + t.Error("should be", v) + } } } @@ -78,15 +98,23 @@ func TestEncoder_Decode(t *testing.T) { enc := base58.MustNewEncoder(base58.StdSource()) _, err := enc.Decode("") - require.Error(t, err) + if err == nil { + t.Error("should not be nil") + } _, err = enc.Decode("0") - require.Error(t, err) + if err == nil { + t.Error("should not be nil") + } for k, v := range bc { r, err := enc.Decode(v) - require.NoError(t, err) - assert.Equal(t, k, r) + if err != nil { + t.Error("should be nil") + } + if r != k { + t.Error("should be", k) + } } } diff --git a/go.mod b/go.mod index f9fb4d2..2b4b105 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,5 @@ module github.com/osamingo/indigo -go 1.13 +go 1.15 -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/kr/pretty v0.1.0 // indirect - github.com/sony/sonyflake v1.0.1-0.20200827011719-848d664ceea4 - github.com/stretchr/testify v1.6.1 - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect -) +require github.com/sony/sonyflake v1.0.1-0.20200827011719-848d664ceea4 diff --git a/go.sum b/go.sum index dcc4132..684abda 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,2 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sony/sonyflake v1.0.1-0.20200827011719-848d664ceea4 h1:KPf4aWX4JGEdMICunm9A0YTFbD6OL23G14BR7cL/0wg= github.com/sony/sonyflake v1.0.1-0.20200827011719-848d664ceea4/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/indigo_test.go b/indigo_test.go index 17fd172..f2ee5d6 100644 --- a/indigo_test.go +++ b/indigo_test.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "math/rand" + "reflect" "sort" "sync" "testing" @@ -11,8 +12,6 @@ import ( "github.com/osamingo/indigo" "github.com/osamingo/indigo/base58" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNew(t *testing.T) { @@ -22,7 +21,9 @@ func TestNew(t *testing.T) { indigo.MachineID(func() (uint16, error) { return math.MaxUint16, nil }), indigo.CheckMachineID(nil), ) - require.NotNil(t, g) + if g == nil { + t.Error("should not be nil") + } } func TestGenerator_NextID(t *testing.T) { @@ -35,13 +36,25 @@ func TestGenerator_NextID(t *testing.T) { ) id1, err := g.NextID() - require.NoError(t, err) - assert.NotEmpty(t, id1) + if err != nil { + t.Error("should be nil") + } + if id1 == "" { + t.Error("should not be empty") + } id2, err := g.NextID() - require.NoError(t, err) - assert.NotEmpty(t, id2) - assert.NotEqual(t, id1, id2) + if err != nil { + t.Error("should be nil") + } + + if id2 == "" { + t.Error("should not be empty") + } + + if id1 == id2 { + t.Error("should not be equal") + } } func TestGenerator_Decompose(t *testing.T) { @@ -54,12 +67,20 @@ func TestGenerator_Decompose(t *testing.T) { ) m, err := g.Decompose("KGuFE14P") - require.NoError(t, err) - require.NotEmpty(t, m) - assert.NotEmpty(t, m["id"]) + if err != nil { + t.Error("should be nil") + } + if len(m) == 0 { + t.Error("should not be empty") + } + if _, ok := m["id"]; !ok { + t.Error("should not be empty") + } _, err = g.Decompose("") - require.Error(t, err) + if err == nil { + t.Error("should not be nil") + } } func TestGenerator_NextID_Race(t *testing.T) { @@ -79,8 +100,12 @@ func TestGenerator_NextID_Race(t *testing.T) { go func() { defer wg.Done() id, err := g.NextID() - require.NoError(t, err) - require.NotEmpty(t, id) + if err != nil { + t.Error("should be nil") + } + if id == "" { + t.Error("should not be empty") + } }() } @@ -112,7 +137,9 @@ func TestGenerator_NextID_SortIDs(t *testing.T) { for j := 0; j < th; j++ { time.Sleep(10*time.Millisecond + time.Duration(r.Intn(1e9))) id, err := g.NextID() - require.NoError(t, err) + if err != nil { + t.Error("should be nil") + } s = append(s, id) } @@ -126,10 +153,14 @@ func TestGenerator_NextID_SortIDs(t *testing.T) { old := make([]string, 100) copy(old, ids) - require.Equal(t, old, ids) + if !reflect.DeepEqual(ids, old) { + t.Error("should be equal") + } sort.Strings(ids) - require.NotEqual(t, old, ids) + if reflect.DeepEqual(ids, old) { + t.Error("should not be equal") + } g := indigo.New( nil, @@ -140,8 +171,12 @@ func TestGenerator_NextID_SortIDs(t *testing.T) { var prev uint64 for i := range ids { m, err := g.Decompose(ids[i]) - require.NoError(t, err) - require.True(t, prev <= m["time"]) + if err != nil { + t.Error("should be nil") + } + if !(prev <= m["time"]) { + t.Error("should be true") + } prev = m["time"] } }