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
- func AssertYAMLEquals(t *testing.T, expectedYAML, actualYAML string)
- func CaptureStdout(t *testing.T, fn func()) string
- func ExtractYAML(out string) string
- func JSONResp(status int, body any) *http.Response
- func SetOSArgs(t *testing.T, args []string)
- func SetTransport(t *testing.T, rt http.RoundTripper)
- func SetupTestHome(t *testing.T) string
- func WriteOCConfig(t *testing.T, home string, cfg any)
- func WriteYAML(t *testing.T, repoDir, relPath, content string)
- type RoundTripFunc
Constants ¶
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 ¶
AssertYAMLEquals parses both expected and actual YAML strings and compares the resulting structures for equality, independent of key ordering or formatting.
func CaptureStdout ¶
CaptureStdout runs fn while redirecting os.Stdout and returns what was written.
func ExtractYAML ¶
ExtractYAML strips non-YAML prefix lines (e.g. "Loading index...") from captured stdout and returns only the YAML document(s).
func SetOSArgs ¶
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 ¶
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 ¶
WriteOCConfig writes a config YAML to ~/.openchoreo/config. The cfg parameter is marshaled to YAML and written to disk.