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
|
//go:build !integration
// +build !integration
package machine
import (
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitlab-runner/common"
dns_test "gitlab.com/gitlab-org/gitlab-runner/helpers/dns/test"
)
func TestNewMachineName(t *testing.T) {
testCases := map[string]struct {
token string
}{
"DNS-1123 compatible token": {
token: "token-of",
},
"non DNS-1123 compatible token": {
token: "ToK3_?OF",
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
config := &common.RunnerConfig{
RunnerCredentials: common.RunnerCredentials{
Token: testCase.token,
},
RunnerSettings: common.RunnerSettings{
Machine: &common.DockerMachine{
MachineName: "test-machine-%s",
},
},
}
name := newMachineName(config)
dns_test.AssertRFC1123Compatibility(t, name)
})
}
}
func TestNewMachineNameIsUnique(t *testing.T) {
config := &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Machine: &common.DockerMachine{
MachineName: "test-machine-%s",
},
},
}
a := newMachineName(config)
b := newMachineName(config)
assert.NotEqual(t, a, b)
}
func TestMachineFilter(t *testing.T) {
filter := "machine-template-%s"
machines := []string{
"test-machine",
"machine-template-10",
}
filtered := filterMachineList(machines, filter)
assert.NotContains(t, filtered, machines[0])
assert.Contains(t, filtered, machines[1])
}
|