internal/control/dashboard_test.go

419f6dfdc5489a0c6374e36dd1ebbfca68040056
gitbay/internal/control/dashboard_test.go history · blame · raw

53 lines · 1605 bytes

 1package control
 2
 3import (
 4	"bytes"
 5	"strings"
 6	"testing"
 7)
 8
 9// The push queue is the one worker queue whose worst failure — a key_id
10// or team_id Apple did not issue, which config validation cannot check —
11// dead-letters every row on its first attempt with nothing but a log
12// line. dashboard is where an admin would see that, so it reports push
13// beside the other five queues.
14func TestDashboardReportsThePushQueue(t *testing.T) {
15	c := notifTestCtx(t, "cmc")
16	c.User.IsAdmin = true
17	uid := c.User.ID
18	if _, err := c.Store.AddPushDevice(uid, "tok-a", "iphone"); err != nil {
19		t.Fatal(err)
20	}
21	if err := c.Store.EnqueuePush(uid, "krz/gitbay", "cmc opened issue #1", "krz/gitbay/issues/1"); err != nil {
22		t.Fatal(err)
23	}
24	due, err := c.Store.DuePush(20)
25	if err != nil || len(due) != 1 {
26		t.Fatalf("DuePush: %v %+v", err, due)
27	}
28	if err := c.Store.MarkPushFailed(due[0].ID, "apns 403 InvalidProviderToken", nil); err != nil {
29		t.Fatal(err)
30	}
31
32	var out bytes.Buffer
33	c.Stdout, c.Stderr = &out, &out
34	if code := runDashboard(c, nil); code != 0 {
35		t.Fatalf("exit %d: %s", code, out.String())
36	}
37	got := out.String()
38	if !strings.Contains(got, "push\tpending 0\tretrying 0\tfailed 1") {
39		t.Fatalf("no push queue row:\n%s", got)
40	}
41	if !strings.Contains(got, "apns 403 InvalidProviderToken") {
42		t.Fatalf("dead-lettered row not listed:\n%s", got)
43	}
44
45	out.Reset()
46	c.JSON = true
47	if code := runDashboard(c, nil); code != 0 {
48		t.Fatalf("exit %d: %s", code, out.String())
49	}
50	if !strings.Contains(out.String(), `"push":{`) {
51		t.Fatalf("no push key in the queues object:\n%s", out.String())
52	}
53}