aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/commit_poll_test.go
blob: 5f80db8262cd6af5718b64b08059e51a9a0cbc8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2019 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package main

import (
	"sort"
	"testing"

	"github.com/google/syzkaller/dashboard/dashapi"
)

func TestCommitPoll(t *testing.T) {
	c := NewCtx(t)
	defer c.Close()

	build1 := testBuild(1)
	c.client.UploadBuild(build1)

	crash1 := testCrash(build1, 1)
	c.client.ReportCrash(crash1)
	rep1 := c.client.pollBug()

	crash2 := testCrash(build1, 2)
	c.client.ReportCrash(crash2)
	rep2 := c.client.pollBug()

	// No commits in commit poll.
	commitPollResp, err := c.client.CommitPoll()
	c.expectOK(err)
	c.expectEQ(len(commitPollResp.Repos), 2)
	c.expectEQ(commitPollResp.Repos[0].URL, testConfig.Namespaces["test1"].Repos[0].URL)
	c.expectEQ(commitPollResp.Repos[0].Branch, testConfig.Namespaces["test1"].Repos[0].Branch)
	c.expectEQ(commitPollResp.Repos[1].URL, testConfig.Namespaces["test1"].Repos[1].URL)
	c.expectEQ(commitPollResp.Repos[1].Branch, testConfig.Namespaces["test1"].Repos[1].Branch)
	c.expectEQ(len(commitPollResp.Commits), 0)

	// Specify fixing commit for the bug.
	reply, _ := c.client.ReportingUpdate(&dashapi.BugUpdate{
		ID:         rep1.ID,
		Status:     dashapi.BugStatusOpen,
		FixCommits: []string{"foo: fix1", "foo: fix2"},
	})
	c.expectEQ(reply.OK, true)

	// The commit should appear in commit poll.
	for i := 0; i < 2; i++ {
		commitPollResp, err = c.client.CommitPoll()
		c.expectOK(err)
		c.expectEQ(len(commitPollResp.Commits), 2)
		sort.Strings(commitPollResp.Commits)
		c.expectEQ(commitPollResp.Commits[0], "foo: fix1")
		c.expectEQ(commitPollResp.Commits[1], "foo: fix2")
	}

	// Upload hash for the first commit and fixing commit for the second bug.
	c.expectOK(c.client.UploadCommits([]dashapi.Commit{
		{Hash: "hash1", Title: "foo: fix1"},
		{Hash: "hash2", Title: "bar: fix3", BugIDs: []string{rep2.ID}},
		{Hash: "hash3", Title: "some unrelated commit", BugIDs: []string{"does not exist"}},
		{Hash: "hash4", Title: "another unrelated commit"},
	}))

	commitPollResp, err = c.client.CommitPoll()
	c.expectOK(err)
	c.expectEQ(len(commitPollResp.Commits), 2)
	sort.Strings(commitPollResp.Commits)
	c.expectEQ(commitPollResp.Commits[0], "foo: fix1")
	c.expectEQ(commitPollResp.Commits[1], "foo: fix2")

	// Upload hash for the second commit and a new fixing commit for the second bug.
	c.expectOK(c.client.UploadCommits([]dashapi.Commit{
		{Hash: "hash5", Title: "foo: fix2"},
		{Title: "bar: fix4", BugIDs: []string{rep2.ID}},
	}))

	commitPollResp, err = c.client.CommitPoll()
	c.expectOK(err)
	c.expectEQ(len(commitPollResp.Commits), 1)
	c.expectEQ(commitPollResp.Commits[0], "bar: fix4")

	// Upload hash for the second commit and a new fixing commit for the second bug.
	c.expectOK(c.client.UploadCommits([]dashapi.Commit{
		{Hash: "hash1", Title: "foo: fix1"},
		{Hash: "hash5", Title: "foo: fix2"},
		{Hash: "hash6", Title: "bar: fix4"},
	}))

	commitPollResp, err = c.client.CommitPoll()
	c.expectOK(err)
	c.expectEQ(len(commitPollResp.Commits), 0)
}