File view with blame information shown in the left gutter beside each line.

barerepo / server / internal/store/labels_test.go
46 lines · 1.9kb · 133728eaa05486504991b230f9d4c7e986b7defc
log files threads runs releases config jump to file t
133728e barerepo 1mo
1
package store
133728e barerepo 1mo
2
133728e barerepo 1mo
3
import "testing"
133728e barerepo 1mo
4
133728e barerepo 1mo
5
// Chapter 15A: a job names a machine the GitHub way, and barerepo answers with what it actually has.
133728e barerepo 1mo
6
func TestSatisfiesTranslatesHostedLabels(t *testing.T) {
133728e barerepo 1mo
7
linux := Runner{OS: "linux", Arch: "amd64"}
133728e barerepo 1mo
8
mac := Runner{OS: "darwin", Arch: "arm64", Labels: []string{"big"}}
133728e barerepo 1mo
9
133728e barerepo 1mo
10
cases := []struct {
133728e barerepo 1mo
11
runner Runner
133728e barerepo 1mo
12
want []string
133728e barerepo 1mo
13
ok bool
133728e barerepo 1mo
14
why string
133728e barerepo 1mo
15
}{
133728e barerepo 1mo
16
{linux, nil, true, "a job that asks for nothing runs anywhere"},
133728e barerepo 1mo
17
{linux, []string{"ubuntu-latest"}, true, "ubuntu-latest is a linux machine"},
133728e barerepo 1mo
18
{linux, []string{"ubuntu-22.04"}, true, "any ubuntu image is still linux"},
133728e barerepo 1mo
19
{linux, []string{"self-hosted"}, true, "every barerepo runner is self-hosted"},
133728e barerepo 1mo
20
{linux, []string{"self-hosted", "linux"}, true, "both hold"},
133728e barerepo 1mo
21
{linux, []string{"macos-latest"}, false, "a linux machine is not a mac"},
133728e barerepo 1mo
22
{linux, []string{"windows-latest"}, false, "a linux machine is not windows"},
133728e barerepo 1mo
23
{linux, []string{"amd64"}, true, "the architecture answers too"},
133728e barerepo 1mo
24
{linux, []string{"gpu"}, false, "a label nobody declared is not satisfied"},
133728e barerepo 1mo
25
{mac, []string{"macos-14"}, true, "any macos image is darwin"},
133728e barerepo 1mo
26
{mac, []string{"big"}, true, "a declared label answers"},
133728e barerepo 1mo
27
{mac, []string{"big", "macos-latest"}, true, "every label has to hold, and both do"},
133728e barerepo 1mo
28
{mac, []string{"big", "ubuntu-latest"}, false, "every label has to hold, and one does not"},
133728e barerepo 1mo
29
}
133728e barerepo 1mo
30
for _, c := range cases {
133728e barerepo 1mo
31
if got := c.runner.Satisfies(c.want); got != c.ok {
133728e barerepo 1mo
32
t.Errorf("%s: Satisfies(%v) on %s = %v, want %v",
133728e barerepo 1mo
33
c.why, c.want, c.runner.OS, got, c.ok)
133728e barerepo 1mo
34
}
133728e barerepo 1mo
35
}
133728e barerepo 1mo
36
}
133728e barerepo 1mo
37
133728e barerepo 1mo
38
// Case must not decide whether a build runs.
133728e barerepo 1mo
39
func TestSatisfiesIgnoresCase(t *testing.T) {
133728e barerepo 1mo
40
r := Runner{OS: "Linux", Labels: []string{"GPU"}}
133728e barerepo 1mo
41
for _, want := range [][]string{{"ubuntu-latest"}, {"gpu"}, {"LINUX"}, {" self-hosted "}} {
133728e barerepo 1mo
42
if !r.Satisfies(want) {
133728e barerepo 1mo
43
t.Errorf("Satisfies(%v) was false on a runner that has it", want)
133728e barerepo 1mo
44
}
133728e barerepo 1mo
45
}
133728e barerepo 1mo
46
}
history · rawbarerepo 0.1.0