| 1 | package change |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // The choice SelectNotes makes is the contract the integrator and approve |
| 6 | // share, so each part of it is pinned: the first note that verifies is |
| 7 | // kept whatever it records, and until one verifies the last note read |
| 8 | // stands. |
| 9 | func TestSelectNotes(t *testing.T) { |
| 10 | type note struct { |
| 11 | check, what string |
| 12 | verifies bool |
| 13 | } |
| 14 | notes := []note{ |
| 15 | {"a", "a forgery", false}, |
| 16 | {"a", "a failure that verifies", true}, |
| 17 | {"a", "a pass that verifies", true}, |
| 18 | {"b", "a pass that verifies", true}, |
| 19 | {"b", "a forgery", false}, |
| 20 | {"c", "a forgery", false}, |
| 21 | {"c", "an unknown signer", false}, |
| 22 | } |
| 23 | got := SelectNotes(notes, func(n note) string { return n.check }, func(n note) bool { return n.verifies }) |
| 24 | want := map[string]string{ |
| 25 | "a": "a failure that verifies", |
| 26 | "b": "a pass that verifies", |
| 27 | "c": "an unknown signer", |
| 28 | } |
| 29 | if len(got) != len(want) { |
| 30 | t.Fatalf("picked %d checks, want %d: %v", len(got), len(want), got) |
| 31 | } |
| 32 | for check, what := range want { |
| 33 | if got[check].what != what { |
| 34 | t.Errorf("check %s: picked %q, want %q", check, got[check].what, what) |
| 35 | } |
| 36 | } |
| 37 | } |