Skip to content

Commit

Permalink
Merge pull request #8 from newmo-oss/use-gotestingmock
Browse files Browse the repository at this point in the history
Use gotestingmock package
  • Loading branch information
tenntenn authored Jan 8, 2025
2 parents fb24881 + d3486c2 commit 2d9bfec
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions ctxtimetest/ctxtimetest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (

"github.com/google/uuid"

"github.com/newmo-oss/gotestingmock"
"github.com/newmo-oss/testid"

"github.com/newmo-oss/ctxtime"
"github.com/newmo-oss/ctxtime/ctxtimetest"
"github.com/newmo-oss/testid"
)

func TestSetFixedNow(t *testing.T) {
Expand Down Expand Up @@ -82,12 +84,14 @@ func TestSetFixedNow(t *testing.T) {
t.Run("unset test ID", func(t *testing.T) {
t.Parallel()

ctx := context.Background()
fakeT := &testingT{T: t}
now := ctxtime.Now(ctx)
ctxtimetest.SetFixedNow(fakeT, ctx, now)
if !fakeT.callFailNow {
t.Error("ctxtimetest.SetFixedNow must call t.Fatal/t.Fatalf/t.FailNow when test id was not related to the context")
got := gotestingmock.Run(func(tb *gotestingmock.TB) {
ctx := context.Background()
now := ctxtime.Now(ctx)
ctxtimetest.SetFixedNow(tb, ctx, now)
})

if !(got.Failed && got.Goexit) {
t.Error("ctxtimetest.SetFixedNow must mark failed and exit goroutine of the test when the test id was not related to the context")
}
})

Expand All @@ -114,20 +118,3 @@ func TestSetFixedNow(t *testing.T) {
}
})
}

type testingT struct {
*testing.T
callFailNow bool
}

func (t *testingT) FailNow() {
t.callFailNow = true
}

func (t *testingT) Fatal(args ...any) {
t.callFailNow = true
}

func (t *testingT) Fatalf(format string, args ...any) {
t.callFailNow = true
}

0 comments on commit 2d9bfec

Please sign in to comment.