internal/control/dashboard_test.go
70 lines · 2216 bytes
1package control
2
3import (
4 "bytes"
5 "strings"
6 "testing"
7
8 "gitbay.org/gitbay/internal/protocol"
9 "gitbay.org/gitbay/internal/store"
10)
11
12func TestDashboardEmptySectionsSayNone(t *testing.T) {
13 st, _, uid := newQueueTestRepo(t)
14 c, errOut := pruneCtx(st, t.TempDir(), store.User{ID: uid})
15 if code := Dispatch(c, []string{"dashboard"}); code != protocol.ExitOK {
16 t.Fatalf("exit %d: %s", code, errOut)
17 }
18 out := c.Stdout.(*bytes.Buffer).String()
19 for _, h := range []string{"waiting on your review:", "assigned to you:", "open merge requests:", "open issues:"} {
20 if !strings.Contains(out, h+"\n none\n") {
21 t.Errorf("%q not followed by none:\n%s", h, out)
22 }
23 }
24}
25
26// The push queue is the one worker queue whose worst failure — a key_id
27// or team_id Apple did not issue, which config validation cannot check —
28// dead-letters every row on its first attempt with nothing but a log
29// line. dashboard is where an admin would see that, so it reports push
30// beside the other five queues.
31func TestDashboardReportsThePushQueue(t *testing.T) {
32 c := notifTestCtx(t, "cmc")
33 c.User.IsAdmin = true
34 uid := c.User.ID
35 if _, err := c.Store.AddPushDevice(uid, "tok-a", "iphone"); err != nil {
36 t.Fatal(err)
37 }
38 if err := c.Store.EnqueuePush(uid, "krz/gitbay", "cmc opened issue #1", "krz/gitbay/issues/1"); err != nil {
39 t.Fatal(err)
40 }
41 due, err := c.Store.DuePush(20)
42 if err != nil || len(due) != 1 {
43 t.Fatalf("DuePush: %v %+v", err, due)
44 }
45 if err := c.Store.MarkPushFailed(due[0].ID, "apns 403 InvalidProviderToken", nil); err != nil {
46 t.Fatal(err)
47 }
48
49 var out bytes.Buffer
50 c.Stdout, c.Stderr = &out, &out
51 if code := runDashboard(c, nil); code != 0 {
52 t.Fatalf("exit %d: %s", code, out.String())
53 }
54 got := out.String()
55 if !strings.Contains(got, "push\tpending 0\tretrying 0\tfailed 1") {
56 t.Fatalf("no push queue row:\n%s", got)
57 }
58 if !strings.Contains(got, "apns 403 InvalidProviderToken") {
59 t.Fatalf("dead-lettered row not listed:\n%s", got)
60 }
61
62 out.Reset()
63 c.JSON = true
64 if code := runDashboard(c, nil); code != 0 {
65 t.Fatalf("exit %d: %s", code, out.String())
66 }
67 if !strings.Contains(out.String(), `"push":{`) {
68 t.Fatalf("no push key in the queues object:\n%s", out.String())
69 }
70}