Documentation
¶
Overview ¶
Package testutil provides common test utilities and helpers for the Nylas CLI.
Package testutil provides common test utilities and helpers to reduce duplication across test files.
Index ¶
- func AssertContains(t *testing.T, haystack, needle, msg string)
- func AssertEmpty[T any](t *testing.T, slice []T, msg string)
- func AssertEqual[T comparable](t *testing.T, got, want T, msg string)
- func AssertError(t *testing.T, err error, msg string)
- func AssertFalse(t *testing.T, condition bool, msg string)
- func AssertLen[T any](t *testing.T, slice []T, expected int, msg string)
- func AssertNil(t *testing.T, value any, msg string)
- func AssertNoError(t *testing.T, err error, msg string)
- func AssertNotContains(t *testing.T, haystack, needle, msg string)
- func AssertNotEmpty[T any](t *testing.T, slice []T, msg string)
- func AssertNotEqual[T comparable](t *testing.T, got, unwanted T, msg string)
- func AssertNotNil(t *testing.T, value any, msg string)
- func AssertTrue(t *testing.T, condition bool, msg string)
- func BoolPtr(b bool) *bool
- func IntPtr(i int) *int
- func LongTestContext(t *testing.T) context.Context
- func QuickTestContext(t *testing.T) context.Context
- func RequireEnv(t *testing.T, key string) string
- func StringPtr(s string) *string
- func TempConfig(t *testing.T, content string) string
- func TempDir(t *testing.T) string
- func TempFile(t *testing.T, name, content string) string
- func TestContext(t *testing.T) context.Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertContains ¶
AssertContains fails the test if haystack does not contain needle.
Example:
testutil.AssertContains(t, output, "Success", "output should contain success message")
func AssertEmpty ¶
AssertEmpty fails the test if slice is not empty.
Example:
testutil.AssertEmpty(t, errors, "should have no errors")
func AssertEqual ¶
func AssertEqual[T comparable](t *testing.T, got, want T, msg string)
AssertEqual fails the test if got != want.
Example:
testutil.AssertEqual(t, user.Name, "John", "user name")
func AssertError ¶
AssertError fails the test if err is nil.
Example:
testutil.AssertError(t, err, "expected error for invalid input")
func AssertFalse ¶
AssertFalse fails the test if condition is true.
Example:
testutil.AssertFalse(t, user.IsDeleted, "user should not be deleted")
func AssertLen ¶
AssertLen fails the test if the length of slice is not equal to expected.
Example:
testutil.AssertLen(t, users, 5, "should have 5 users")
func AssertNil ¶
AssertNil fails the test if value is not nil.
Example:
testutil.AssertNil(t, err, "error should be nil")
func AssertNoError ¶
AssertNoError fails the test if err is not nil.
Example:
testutil.AssertNoError(t, err, "failed to create user")
func AssertNotContains ¶
AssertNotContains fails the test if haystack contains needle.
Example:
testutil.AssertNotContains(t, output, "Error", "output should not contain error")
func AssertNotEmpty ¶
AssertNotEmpty fails the test if slice is empty.
Example:
testutil.AssertNotEmpty(t, results, "should have results")
func AssertNotEqual ¶
func AssertNotEqual[T comparable](t *testing.T, got, unwanted T, msg string)
AssertNotEqual fails the test if got == want.
Example:
testutil.AssertNotEqual(t, user.ID, "", "user ID should not be empty")
func AssertNotNil ¶
AssertNotNil fails the test if value is nil.
Example:
testutil.AssertNotNil(t, user, "user should not be nil")
func AssertTrue ¶
AssertTrue fails the test if condition is false.
Example:
testutil.AssertTrue(t, user.IsActive, "user should be active")
func BoolPtr ¶
BoolPtr returns a pointer to the given boolean value. This is useful for test data that requires *bool fields.
func IntPtr ¶
IntPtr returns a pointer to the given integer value. This is useful for test data that requires *int fields.
func LongTestContext ¶
LongTestContext creates a 120-second timeout context with automatic cleanup. Use this for integration tests that may take longer (e.g., multiple API calls).
func QuickTestContext ¶
QuickTestContext creates a 5-second timeout context with automatic cleanup. Use this for unit tests that should complete quickly (e.g., no network calls).
func RequireEnv ¶
RequireEnv retrieves an environment variable and skips the test if not set. This is useful for integration tests that require specific configuration.
func StringPtr ¶
StringPtr returns a pointer to the given string value. This is useful for test data that requires *string fields.
func TempConfig ¶
TempConfig creates a temporary config file with the given content for testing. The file is automatically cleaned up when the test completes.
Example:
configPath := testutil.TempConfig(t, `region: "us"\ncallback_port: 8080`) store := config.NewFileStore(configPath)
func TempDir ¶
TempDir creates a temporary directory for testing. The directory is automatically cleaned up when the test completes.
Note: This is just a wrapper around t.TempDir() for consistency.
Types ¶
This section is empty.