testutil

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides shared test helper utilities for occ sub-packages. It is intended to be imported only from *_test.go files.

Index

Constants

View Source
const NonExpiredJWT = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJleHAiOjk5OTk5OTk5OTl9." //nolint:gosec // test token

NonExpiredJWT is a minimal unsigned JWT with exp=9999999999 (year 2286). header: {"alg":"none","typ":"JWT"}, payload: {"exp":9999999999}

Variables

This section is empty.

Functions

func AssertYAMLEquals

func AssertYAMLEquals(t *testing.T, expectedYAML, actualYAML string)

AssertYAMLEquals parses both expected and actual YAML strings and compares the resulting structures for equality, independent of key ordering or formatting.

func CaptureStdout

func CaptureStdout(t *testing.T, fn func()) string

CaptureStdout runs fn while redirecting os.Stdout and returns what was written.

func ExtractYAML

func ExtractYAML(out string) string

ExtractYAML strips non-YAML prefix lines (e.g. "Loading index...") from captured stdout and returns only the YAML document(s).

func JSONResp

func JSONResp(status int, body any) *http.Response

JSONResp builds an *http.Response with the given status and JSON body.

func SetOSArgs

func SetOSArgs(t *testing.T, args []string)

SetOSArgs replaces os.Args for the duration of the test and restores the original value via t.Cleanup.

func SetTransport

func SetTransport(t *testing.T, rt http.RoundTripper)

SetTransport replaces http.DefaultTransport for the duration of the test.

func SetupTestHome

func SetupTestHome(t *testing.T) string

SetupTestHome creates a temp HOME directory so LoadStoredConfig reads from an isolated location. It overrides HOME/USERPROFILE for the duration of the test.

func WriteOCConfig

func WriteOCConfig(t *testing.T, home string, cfg any)

WriteOCConfig writes a config YAML to ~/.openchoreo/config. The cfg parameter is marshaled to YAML and written to disk.

func WriteYAML

func WriteYAML(t *testing.T, repoDir, relPath, content string)

WriteYAML writes a YAML file to the given relative path under repoDir, creating intermediate directories as needed.

Types

type RoundTripFunc

type RoundTripFunc func(*http.Request) (*http.Response, error)

RoundTripFunc lets a plain function satisfy http.RoundTripper.

func (RoundTripFunc) RoundTrip

func (f RoundTripFunc) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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