Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Nov 1, 2023
1 parent 3e36196 commit 8f3e345
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/example/03_setup_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package example_test

import (
"testing"
"time"

"github.com/ysmood/got"
Expand All @@ -12,7 +13,18 @@ func init() {
got.DefaultFlags("timeout=10s")
}

var setup = got.Setup(func(g got.G) {
// G is your custom test context.
type G struct {
got.G

// You can add your own fields, usually data you want init before each test.
time string
}

// setup is a helper function to setup your test context G.
var setup = func(t *testing.T) G {
g := got.T(t)

// The function passed to it will be surely executed after the test
g.Cleanup(func() {})

Expand All @@ -24,4 +36,13 @@ var setup = got.Setup(func(g got.G) {

// Timeout for each test
g.PanicAfter(time.Second)
})

return G{g, time.Now().Format(time.DateTime)}
}

func TestSetup(t *testing.T) {
g := setup(t)

// Here we use the custom field we have defined in G
g.Gt(g.time, "2023-01-02 15:04:05")
}

0 comments on commit 8f3e345

Please sign in to comment.