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

Function TestWriteOKOmitsStatsWhenFlagOff

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

Source from the content-addressed store, hash-verified

64}
65
66func TestWriteOKOmitsStatsWhenFlagOff(t *testing.T) {
67 oldWriter, oldStats, oldSDKStats := writer, statsFlag, sdkStats
68 defer func() { writer, statsFlag, sdkStats = oldWriter, oldStats, oldSDKStats }()
69
70 var buf bytes.Buffer
71 writer = output.New(output.Options{Format: output.FormatJSON, Stdout: &buf})
72 sdkStats = &statsHooks{}
73 statsFlag = false
74
75 if err := writeOK(map[string]string{"hello": "world"}); err != nil {
76 t.Fatalf("writeOK: %v", err)
77 }
78
79 var resp output.Response
80 if err := json.Unmarshal(buf.Bytes(), &resp); err != nil {
81 t.Fatalf("unmarshal: %v", err)
82 }
83
84 if resp.Meta != nil {
85 if _, ok := resp.Meta["stats"]; ok {
86 t.Error("expected meta.stats to be absent when --stats is off")
87 }
88 }
89}

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
writeOKFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected