|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strings" |
4 | 5 | "testing" |
5 | 6 | ) |
6 | 7 |
|
@@ -62,3 +63,40 @@ func TestFilterTestsIntegration(t *testing.T) { |
62 | 63 | }) |
63 | 64 | } |
64 | 65 | } |
| 66 | + |
| 67 | +func TestRunsOnSelfHostedID(t *testing.T) { |
| 68 | + tests := []CITestConf{ |
| 69 | + {ID: "foo", TestEnvType: "typeA", RunsOnSelfHosted: "runs-on/cpu=0/ram=0"}, |
| 70 | + {ID: "bar", TestEnvType: "typeA", RunsOnSelfHosted: "runs-on/cpu=1/ram=1"}, |
| 71 | + {ID: "baz", TestEnvType: "typeB", RunsOnSelfHosted: "runs-on=foo/cpu=2/ram=2"}, |
| 72 | + {ID: "qux", TestEnvType: "typeC"}, |
| 73 | + } |
| 74 | + |
| 75 | + cases := []struct { |
| 76 | + description string |
| 77 | + inputTestType string |
| 78 | + expectedSelfHosted bool |
| 79 | + }{ |
| 80 | + {"Insert epoch time", "typeA", true}, |
| 81 | + {"Dont insert epoch time", "typeB", true}, |
| 82 | + {"No self-hosted label", "typeC", false}, |
| 83 | + } |
| 84 | + |
| 85 | + for _, c := range cases { |
| 86 | + t.Run(c.description, func(t *testing.T) { |
| 87 | + filtered := filterTests(tests, "", c.inputTestType, "", false) |
| 88 | + for _, test := range filtered { |
| 89 | + t.Logf("Test ID: %s, RunsOnSelfHosted: %s", test.ID, test.RunsOnSelfHosted) |
| 90 | + if c.expectedSelfHosted { |
| 91 | + if !strings.HasPrefix(test.RunsOnSelfHosted, "runs-on=") { |
| 92 | + t.Errorf("Expected RunsOnSelfHosted to start with 'runs-on='. Got: %s", test.RunsOnSelfHosted) |
| 93 | + } |
| 94 | + } else { |
| 95 | + if test.RunsOnSelfHosted != "" { |
| 96 | + t.Errorf("Expected RunsOnSelfHosted to be empty. Got: %s", test.RunsOnSelfHosted) |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + }) |
| 101 | + } |
| 102 | +} |
0 commit comments