MCPcopy Index your code
hub / github.com/docker/docker-agent / TestSaveRunJSON

Function TestSaveRunJSON

pkg/evaluation/eval_test.go:324–363  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

322}
323
324func TestSaveRunJSON(t *testing.T) {
325 t.Parallel()
326
327 outputDir := t.TempDir()
328
329 run := &EvalRun{
330 Name: "test-run-001",
331 Timestamp: time.Date(2024, 1, 15, 10, 30, 0, 0, time.UTC),
332 Duration: 5 * time.Minute,
333 Results: []Result{
334 {Title: "test1", Cost: 0.01},
335 {Title: "test2", Cost: 0.02, Error: "failed"},
336 },
337 Summary: Summary{
338 TotalEvals: 2,
339 TotalCost: 0.03,
340 },
341 }
342
343 // Save the run
344 resultsPath, err := SaveRunJSON(run, outputDir)
345 require.NoError(t, err)
346
347 // Verify file path
348 assert.Equal(t, filepath.Join(outputDir, "test-run-001.json"), resultsPath)
349
350 // Verify file exists and contains valid JSON
351 data, err := os.ReadFile(resultsPath)
352 require.NoError(t, err)
353
354 var loaded EvalRun
355 err = json.Unmarshal(data, &loaded)
356 require.NoError(t, err)
357
358 // Verify content
359 assert.Equal(t, run.Name, loaded.Name)
360 assert.Len(t, loaded.Results, len(run.Results))
361 assert.Equal(t, run.Summary.TotalEvals, loaded.Summary.TotalEvals)
362 assert.InDelta(t, run.Summary.TotalCost, loaded.Summary.TotalCost, 0.0001)
363}
364
365func TestSaveRunJSONCreatesDirectory(t *testing.T) {
366 t.Parallel()

Callers

nothing calls this directly

Calls 3

SaveRunJSONFunction · 0.85
ReadFileMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected