Contract: --set-json takes a JSON object string and merges it onto the value tree. Lower precedence than --set / --set-string, higher than -f. (Sanity-check by setting both -f and --set-json.)
(t *testing.T)
| 173 | // the value tree. Lower precedence than --set / --set-string, higher |
| 174 | // than -f. (Sanity-check by setting both -f and --set-json.) |
| 175 | func TestContract_LoadValues_JsonValues(t *testing.T) { |
| 176 | dir := t.TempDir() |
| 177 | file := filepath.Join(dir, "v.yaml") |
| 178 | err := os.WriteFile(file, []byte("a: 1\n"), 0o644) |
| 179 | if err != nil { |
| 180 | t.Fatal(err) |
| 181 | } |
| 182 | out, err := loadValues(Options{ |
| 183 | ValueFiles: []string{file}, |
| 184 | JsonValues: []string{`{"b": {"c": 3}}`}, |
| 185 | }) |
| 186 | if err != nil { |
| 187 | t.Fatal(err) |
| 188 | } |
| 189 | if out["a"] != 1 { |
| 190 | t.Errorf("file value lost: %v", out) |
| 191 | } |
| 192 | bMap, ok := out["b"].(map[string]any) |
| 193 | if !ok { |
| 194 | t.Fatalf("expected b to be map, got %T (%v)", out["b"], out["b"]) |
| 195 | } |
| 196 | // JSON numbers unmarshal to float64. |
| 197 | if bMap["c"] != float64(3) { |
| 198 | t.Errorf("expected b.c=3, got %v (%T)", bMap["c"], bMap["c"]) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | // Contract: malformed JSON in --set-json surfaces a precise error |
| 203 | // naming the bad value. |
nothing calls this directly
no test coverage detected