MCPcopy Create free account
hub / github.com/cozystack/talm / TestContract_LoadValues_JsonValues

Function TestContract_LoadValues_JsonValues

pkg/engine/contract_loadvalues_test.go:175–200  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

173// the value tree. Lower precedence than --set / --set-string, higher
174// than -f. (Sanity-check by setting both -f and --set-json.)
175func 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.

Callers

nothing calls this directly

Calls 1

loadValuesFunction · 0.85

Tested by

no test coverage detected