Download this file
| 1 | package heartbeat |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/rastrillo/rastrillo/budget" |
| 5 | "encoding/json" |
| 6 | "errors" |
| 7 | "os" |
| 8 | "reflect" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |
| 13 | func TestRepositoryNames(t *testing.T) { |
| 14 | names := []string{"amadan.net/oficina/a", "amadan.net/oficina/z"} |
| 15 | q, err := Request(nil, func() ([]string, error) { return names, nil }) |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | raw, err := json.Marshal(q) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | var wire struct { |
| 24 | Repositories []string `json:"repositories"` |
| 25 | } |
| 26 | if err = json.Unmarshal(raw, &wire); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if !reflect.DeepEqual(wire.Repositories, names) { |
| 30 | t.Fatal("names missing", string(raw)) |
| 31 | } |
| 32 | q, err = Request(nil, func() ([]string, error) { return names, errors.New("unreadable") }) |
| 33 | if err != nil || len(q.Repositories) != 0 { |
| 34 | t.Fatal("retained stale discovery", err) |
| 35 | } |
| 36 | } |
| 37 | |