From 94bcb7f9084c284fb90204c1e1e77211c91f1819 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Fri, 5 May 2023 20:33:54 -0500 Subject: [PATCH] docs: add more examples (#128) --- examples_test.go | 59 ++++++++++++++++++++++++++++++++++++++----- must/examples_test.go | 59 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/examples_test.go b/examples_test.go index 01951e9..cd0ce88 100644 --- a/examples_test.go +++ b/examples_test.go @@ -7,6 +7,9 @@ import ( "fmt" "os" "strings" + "time" + + "github.com/shoenig/test/wait" ) var t = new(myT) @@ -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: +} diff --git a/must/examples_test.go b/must/examples_test.go index 68bee3f..b4f2052 100644 --- a/must/examples_test.go +++ b/must/examples_test.go @@ -9,6 +9,9 @@ import ( "fmt" "os" "strings" + "time" + + "github.com/shoenig/test/wait" ) var t = new(myT) @@ -469,14 +472,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: +}