package store import "testing" // Chapter 15A: a job names a machine the GitHub way, and barerepo answers with what it actually has. func TestSatisfiesTranslatesHostedLabels(t *testing.T) { linux := Runner{OS: "linux", Arch: "amd64"} mac := Runner{OS: "darwin", Arch: "arm64", Labels: []string{"big"}} cases := []struct { runner Runner want []string ok bool why string }{ {linux, nil, true, "a job that asks for nothing runs anywhere"}, {linux, []string{"ubuntu-latest"}, true, "ubuntu-latest is a linux machine"}, {linux, []string{"ubuntu-22.04"}, true, "any ubuntu image is still linux"}, {linux, []string{"self-hosted"}, true, "every barerepo runner is self-hosted"}, {linux, []string{"self-hosted", "linux"}, true, "both hold"}, {linux, []string{"macos-latest"}, false, "a linux machine is not a mac"}, {linux, []string{"windows-latest"}, false, "a linux machine is not windows"}, {linux, []string{"amd64"}, true, "the architecture answers too"}, {linux, []string{"gpu"}, false, "a label nobody declared is not satisfied"}, {mac, []string{"macos-14"}, true, "any macos image is darwin"}, {mac, []string{"big"}, true, "a declared label answers"}, {mac, []string{"big", "macos-latest"}, true, "every label has to hold, and both do"}, {mac, []string{"big", "ubuntu-latest"}, false, "every label has to hold, and one does not"}, } for _, c := range cases { if got := c.runner.Satisfies(c.want); got != c.ok { t.Errorf("%s: Satisfies(%v) on %s = %v, want %v", c.why, c.want, c.runner.OS, got, c.ok) } } } // Case must not decide whether a build runs. func TestSatisfiesIgnoresCase(t *testing.T) { r := Runner{OS: "Linux", Labels: []string{"GPU"}} for _, want := range [][]string{{"ubuntu-latest"}, {"gpu"}, {"LINUX"}, {" self-hosted "}} { if !r.Satisfies(want) { t.Errorf("Satisfies(%v) was false on a runner that has it", want) } } }