MCPcopy
hub / github.com/dosco/graphjin / TestExpandSpecConfigDefaultsEnv

Function TestExpandSpecConfigDefaultsEnv

core/openapi/loader_test.go:5–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestExpandSpecConfigDefaultsEnv(t *testing.T) {
6 t.Setenv("TEST_OAPI_DEFAULT_REGION", "us-west")
7
8 in := SpecConfig{
9 Operations: map[string]OperationOverride{
10 "listWidgets": {
11 ExposeTopLevel: true,
12 Defaults: map[string]string{
13 "region": "${TEST_OAPI_DEFAULT_REGION}",
14 "format": "json",
15 "missing": "${TEST_OAPI_UNSET_VALUE}",
16 },
17 },
18 },
19 }
20
21 out := expandSpecConfig(in)
22 got := out.Operations["listWidgets"].Defaults
23 if got["region"] != "us-west" {
24 t.Errorf("region = %q, want us-west", got["region"])
25 }
26 if got["format"] != "json" {
27 t.Errorf("format = %q, want json (literal pass-through)", got["format"])
28 }
29 if got["missing"] != "" {
30 t.Errorf("missing = %q, want empty (unset env → empty, matching auth behaviour)", got["missing"])
31 }
32
33 // Caller's input map must be untouched.
34 if in.Operations["listWidgets"].Defaults["region"] != "${TEST_OAPI_DEFAULT_REGION}" {
35 t.Errorf("expandSpecConfig mutated the caller's Defaults map")
36 }
37}

Callers

nothing calls this directly

Calls 1

expandSpecConfigFunction · 0.85

Tested by

no test coverage detected