diff --git a/go.mod b/go.mod index 5fe5445..52850c7 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,3 @@ module github.com/sj14/epoch go 1.22 retract [v1.2.0, v1.2.3] - -require github.com/stretchr/testify v1.9.0 - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/go.sum b/go.sum index 60ce688..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +0,0 @@ -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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -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/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/epoch/epoch_test.go b/pkg/epoch/epoch_test.go index c10b119..3150ec9 100644 --- a/pkg/epoch/epoch_test.go +++ b/pkg/epoch/epoch_test.go @@ -2,12 +2,29 @@ package epoch import ( "errors" + "reflect" "testing" "time" - - "github.com/stretchr/testify/require" ) +func equalError(t *testing.T, got, want error) { + t.Helper() + + if (got == nil && want != nil) || + (got != nil && want == nil) || + (got.Error() != want.Error()) { + t.Fatalf("got %q, want %q\n", got, want) + } +} + +func equal[T any](t *testing.T, got, want T) { + t.Helper() + + if !reflect.DeepEqual(got, want) { + t.Fatalf("got '%#v', want '%#v\n", got, want) + } +} + func TestParseUnit(t *testing.T) { testCases := []struct { description string @@ -46,14 +63,13 @@ func TestParseUnit(t *testing.T) { t.Run(tt.description, func(t *testing.T) { unit, err := ParseUnit(tt.given) if err != nil { - require.EqualError(t, tt.expectedErr, err.Error(), err) + equalError(t, err, tt.expectedErr) return } else if tt.expectedErr != nil { - require.EqualError(t, err, tt.expectedErr.Error(), tt.expectedErr) + equalError(t, err, tt.expectedErr) return } - - require.Equal(t, tt.expected, unit) + equal(t, unit, tt.expected) }) } } @@ -109,14 +125,14 @@ func TestToTimestamp(t *testing.T) { t.Run(tt.description, func(t *testing.T) { timestamp, err := ToTimestamp(tt.given.time, tt.given.unit) if err != nil { - require.EqualError(t, tt.expected.err, err.Error(), err) + equalError(t, err, tt.expected.err) return } else if tt.expected.err != nil { - require.EqualError(t, err, tt.expected.err.Error(), tt.expected.err) + equalError(t, err, tt.expected.err) return } - require.Equal(t, tt.expected.timestamp, timestamp) + equal(t, timestamp, tt.expected.timestamp) }) } } @@ -172,14 +188,14 @@ func TestParseTimestamp(t *testing.T) { t.Run(tt.description, func(t *testing.T) { timestamp, err := ParseTimestamp(tt.given.timestamp, tt.given.unit) if err != nil { - require.EqualError(t, tt.expected.err, err.Error(), err) + equalError(t, err, tt.expected.err) return } else if tt.expected.err != nil { - require.EqualError(t, err, tt.expected.err.Error(), tt.expected.err) + equalError(t, err, tt.expected.err) return } - require.Equal(t, tt.expected.time.UTC(), timestamp.UTC()) + equal(t, timestamp.UTC(), tt.expected.time.UTC()) }) } } @@ -230,7 +246,7 @@ func TestGuessUnit(t *testing.T) { for _, tt := range testCases { t.Run(tt.description, func(t *testing.T) { unit := GuessUnit(tt.given.timestamp, tt.given.ref) - require.Equal(t, tt.expected.unit, unit) + equal(t, unit, tt.expected.unit) }) } } @@ -266,16 +282,16 @@ func TestParseFormatted(t *testing.T) { for _, tt := range testCases { t.Run(tt.description, func(t *testing.T) { parsed, layout, err := ParseFormatted(tt.given.formatted) - require.Equal(t, tt.expected.layout, layout) + equal(t, layout, tt.expected.layout) if err != nil { - require.EqualError(t, tt.expected.err, err.Error(), err) + equalError(t, err, tt.expected.err) return } else if tt.expected.err != nil { - require.EqualError(t, err, tt.expected.err.Error(), tt.expected.err) + equalError(t, err, tt.expected.err) return } - require.Equal(t, tt.expected.time, parsed) + equal(t, parsed, tt.expected.time) }) } }