(t *testing.T)
| 32 | } |
| 33 | |
| 34 | func 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 | |
| 66 | func TestWriteOKOmitsStatsWhenFlagOff(t *testing.T) { |
| 67 | oldWriter, oldStats, oldSDKStats := writer, statsFlag, sdkStats |
nothing calls this directly
no test coverage detected