testutil

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, haystack, needle, msg string)

AssertContains fails the test if haystack does not contain needle.

Example:

testutil.AssertContains(t, output, "Success", "output should contain success message")

func AssertEmpty

func AssertEmpty[T any](t *testing.T, slice []T, msg string)

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

func AssertError(t *testing.T, err error, msg string)

AssertError fails the test if err is nil.

Example:

testutil.AssertError(t, err, "expected error for invalid input")

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse fails the test if condition is true.

Example:

testutil.AssertFalse(t, user.IsDeleted, "user should not be deleted")

func AssertLen

func AssertLen[T any](t *testing.T, slice []T, expected int, msg string)

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

func AssertNil(t *testing.T, value any, msg string)

AssertNil fails the test if value is not nil.

Example:

testutil.AssertNil(t, err, "error should be nil")

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string)

AssertNoError fails the test if err is not nil.

Example:

testutil.AssertNoError(t, err, "failed to create user")

func AssertNotContains

func AssertNotContains(t *testing.T, haystack, needle, msg string)

AssertNotContains fails the test if haystack contains needle.

Example:

testutil.AssertNotContains(t, output, "Error", "output should not contain error")

func AssertNotEmpty

func AssertNotEmpty[T any](t *testing.T, slice []T, msg string)

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

func AssertNotNil(t *testing.T, value any, msg string)

AssertNotNil fails the test if value is nil.

Example:

testutil.AssertNotNil(t, user, "user should not be nil")

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue fails the test if condition is false.

Example:

testutil.AssertTrue(t, user.IsActive, "user should be active")

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to the given boolean value. This is useful for test data that requires *bool fields.

func IntPtr

func IntPtr(i int) *int

IntPtr returns a pointer to the given integer value. This is useful for test data that requires *int fields.

func LongTestContext

func LongTestContext(t *testing.T) context.Context

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

func QuickTestContext(t *testing.T) context.Context

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

func RequireEnv(t *testing.T, key string) string

RequireEnv retrieves an environment variable and skips the test if not set. This is useful for integration tests that require specific configuration.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to the given string value. This is useful for test data that requires *string fields.

func TempConfig

func TempConfig(t *testing.T, content string) string

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

func TempDir(t *testing.T) string

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.

func TempFile

func TempFile(t *testing.T, name, content string) string

TempFile creates a temporary file with the given content for testing. The file is automatically cleaned up when the test completes.

Example:

filePath := testutil.TempFile(t, "test.txt", "file contents")

func TestContext

func TestContext(t *testing.T) context.Context

TestContext creates a 30-second timeout context with automatic cleanup. This is the standard context for most tests that interact with the API.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL