Skip to content

Commit

Permalink
Remove testify dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sj14 committed Aug 3, 2024
1 parent f1a76a1 commit d492aac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
8 changes: 0 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
50 changes: 33 additions & 17 deletions pkg/epoch/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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())
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit d492aac

Please sign in to comment.