MCPcopy Index your code
hub / github.com/ddev/ddev / TestJSONValidation

Function TestJSONValidation

cmd/ddev/cmd/debug-remote-data_test.go:199–241  ·  view source on GitHub ↗

TestJSONValidation tests that the output is always valid JSON

(t *testing.T)

Source from the content-addressed store, hash-verified

197
198// TestJSONValidation tests that the output is always valid JSON
199func TestJSONValidation(t *testing.T) {
200 t.Run("RemoteConfigValidJSON", func(t *testing.T) {
201 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "remote-data", "--type=remote-config", "--update-storage=false")
202 require.NoError(t, err, "Should successfully download remote config, output='%v'", out)
203
204 // Test that it's valid JSON by unmarshaling to interface{}
205 var jsonData any
206 err = json.Unmarshal([]byte(out), &jsonData)
207 require.NoError(t, err, "Output should be valid JSON")
208
209 // Test that it can be re-marshaled (round-trip test)
210 _, err = json.Marshal(jsonData)
211 require.NoError(t, err, "JSON should be serializable")
212 })
213
214 t.Run("SponsorshipDataValidJSON", func(t *testing.T) {
215 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "remote-data", "--type=sponsorship-data", "--update-storage=false")
216 require.NoError(t, err, "Should successfully download sponsorship data, output='%v'", out)
217
218 // Test that it's valid JSON
219 var jsonData any
220 err = json.Unmarshal([]byte(out), &jsonData)
221 require.NoError(t, err, "Output should be valid JSON")
222
223 // Test round-trip
224 _, err = json.Marshal(jsonData)
225 require.NoError(t, err, "JSON should be serializable")
226 })
227
228 t.Run("AddonDataValidJSON", func(t *testing.T) {
229 out, err := exec.RunHostCommandSeparateStreams(DdevBin, "utility", "remote-data", "--type=addon-data", "--update-storage=false")
230 require.NoError(t, err, "Should successfully download add-on data, output='%v'", out)
231
232 // Test that it's valid JSON
233 var jsonData any
234 err = json.Unmarshal([]byte(out), &jsonData)
235 require.NoError(t, err, "Output should be valid JSON")
236
237 // Test round-trip
238 _, err = json.Marshal(jsonData)
239 require.NoError(t, err, "JSON should be serializable")
240 })
241}

Callers

nothing calls this directly

Calls 2

UnmarshalMethod · 0.65

Tested by

no test coverage detected