MCPcopy Create free account
hub / github.com/basecamp/hey-cli / TestWriteOKIncludesStats

Function TestWriteOKIncludesStats

internal/cmd/writeok_test.go:34–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func TestWriteOKIncludesStats(t *testing.T) {
35 oldWriter, oldStats, oldSDKStats := writer, statsFlag, sdkStats
36 defer func() { writer, statsFlag, sdkStats = oldWriter, oldStats, oldSDKStats }()
37
38 var buf bytes.Buffer
39 writer = output.New(output.Options{Format: output.FormatJSON, Stdout: &buf})
40 sdkStats = &statsHooks{}
41 statsFlag = true
42
43 if err := writeOK(map[string]string{"hello": "world"}, output.WithSummary("test")); err != nil {
44 t.Fatalf("writeOK: %v", err)
45 }
46
47 var resp output.Response
48 if err := json.Unmarshal(buf.Bytes(), &resp); err != nil {
49 t.Fatalf("unmarshal: %v", err)
50 }
51
52 if !resp.OK {
53 t.Error("expected ok=true")
54 }
55 if resp.Summary != "test" {
56 t.Errorf("summary = %q, want %q", resp.Summary, "test")
57 }
58 if resp.Meta == nil {
59 t.Fatal("expected meta to be present")
60 }
61 if _, ok := resp.Meta["stats"]; !ok {
62 t.Error("expected meta.stats to be present when --stats is set")
63 }
64}
65
66func TestWriteOKOmitsStatsWhenFlagOff(t *testing.T) {
67 oldWriter, oldStats, oldSDKStats := writer, statsFlag, sdkStats

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
WithSummaryFunction · 0.92
writeOKFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected