testutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntegrationEnabled

func IntegrationEnabled() bool

IntegrationEnabled returns true when integration tests are enabled via the NUDGEBEE_INTEGRATION env var.

func RequireIntegration

func RequireIntegration(t testing.TB)

RequireIntegration checks environment and calls t.Skip when integration tests should not run. It also initializes config so viper reads env vars.

func RequireNoError

func RequireNoError(t testing.TB, err error)

RequireNoError fails the test if err is non-nil.

func RequireNotEmpty

func RequireNotEmpty(t testing.TB, s string)

RequireNotEmpty fails the test if s is empty.

func RunCommandCaptureOutput

func RunCommandCaptureOutput(command *cobra.Command, args []string) (string, error)

RunCommandCaptureOutput runs a cobra command and returns its stdout output as a string and an error from the command.

func RunWithMockServer

func RunWithMockServer(handler http.HandlerFunc, viperOverrides map[string]any, cmd *cobra.Command, args []string) (string, error)

RunWithMockServer starts an httptest server with handler, applies viper overrides, runs the provided cobra command, and tears down everything. It returns the captured output and any error from running the command.

func RunWithSimpleGraphQL

func RunWithSimpleGraphQL(mockData any, cmd *cobra.Command, args []string) (string, error)

RunWithSimpleGraphQL is a convenience helper that starts a mock server which automatically handles the token endpoint and serves the provided mockData as the GraphQL response payload under the "data" field. It's suitable for the common case where tests only need to mock returned data.

func StartMockServer

func StartMockServer(handler http.HandlerFunc) (string, func())

StartMockServer starts an httptest.Server with the provided handler and returns its URL and a teardown function.

func WithViper

func WithViper(overrides map[string]any) func()

WithViper sets keys temporarily on viper and returns a restore function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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