(t *testing.T)
| 3 | import "testing" |
| 4 | |
| 5 | func 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 | } |
nothing calls this directly
no test coverage detected