Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add more examples #128

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/shoenig/test/wait"
)

var t = new(myT)
Expand Down Expand Up @@ -467,14 +470,58 @@ func ExampleTrue() {
// Output:
}

// UUIDv4
func ExampleUUIDv4() {
UUIDv4(t, "60bf6bb2-dceb-c986-2d47-07ac5d14f247")
// Output:
}

// Unreachable
func ExampleUnreachable() {
if "foo" < "bar" {
Unreachable(t)
}
// Output:
}

// ValidJSON
func ExampleValidJSON() {
js := `{"key": ["v1", "v2"]}`
ValidJSON(t, js)
// Output:
}

// ValidJSONBytes
func ExampleValidJSONBytes() {
js := []byte(`{"key": ["v1", "v2"]}`)
ValidJSONBytes(t, js)
// Output:
}

func ExampleWait_initial_success() {
Wait(t, wait.InitialSuccess(
wait.BoolFunc(func() bool {
// will be retried until returns true
// or timeout is exceeded
return true
}),
wait.Timeout(1*time.Second),
wait.Gap(100*time.Millisecond),
))
// Output:
}

// Wait
func ExampleWait_continual_success() {
Wait(t, wait.ContinualSuccess(
wait.BoolFunc(func() bool {
// will be retried until timeout expires
// and will fail test if false is ever returned
return true
}),
wait.Timeout(1*time.Second),
wait.Gap(100*time.Millisecond),
))
// Output:
}

// Zero
func ExampleZero() {
Zero(t, 0)
Zero(t, 0.0)
// Output:
}
59 changes: 53 additions & 6 deletions must/examples_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.