| 1 | // Copyright 2022 The Go Authors. All rights reserved. |
|---|---|
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package bug |
| 6 | |
| 7 | import ( |
| 8 | "fmt" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func resetForTesting() { |
| 13 | exemplars = nil |
| 14 | waiters = nil |
| 15 | } |
| 16 | |
| 17 | func TestListBugs(t *testing.T) { |
| 18 | defer resetForTesting() |
| 19 | |
| 20 | Report("bad", nil) |
| 21 | |
| 22 | wantBugs(t, "bad") |
| 23 | |
| 24 | for i := 0; i < 3; i++ { |
| 25 | Report(fmt.Sprintf("index:%d", i), nil) |
| 26 | } |
| 27 | |
| 28 | wantBugs(t, "bad", "index:0") |
| 29 | } |
| 30 | |
| 31 | func wantBugs(t *testing.T, want ...string) { |
| 32 | t.Helper() |
| 33 | |
| 34 | bugs := List() |
| 35 | if got, want := len(bugs), len(want); got != want { |
| 36 | t.Errorf("List(): got %d bugs, want %d", got, want) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | for i, b := range bugs { |
| 41 | if got, want := b.Description, want[i]; got != want { |
| 42 | t.Errorf("bug.List()[%d] = %q, want %q", i, got, want) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestBugNotification(t *testing.T) { |
| 48 | defer resetForTesting() |
| 49 | |
| 50 | Report("unseen", nil) |
| 51 | |
| 52 | notify1 := Notify() |
| 53 | notify2 := Notify() |
| 54 | |
| 55 | Report("seen", Data{"answer": 42}) |
| 56 | |
| 57 | for _, got := range []Bug{<-notify1, <-notify2} { |
| 58 | if got, want := got.Description, "seen"; got != want { |
| 59 | t.Errorf("Saw bug %q, want %q", got, want) |
| 60 | } |
| 61 | if got, want := got.Data["answer"], 42; got != want { |
| 62 | t.Errorf(`bug.Data["answer"] = %v, want %v`, got, want) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 |
Members