gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+incompatible/executors/docker/machine/name_test.go (about) 1 package machine 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "gitlab.com/gitlab-org/gitlab-runner/common" 9 dns_test "gitlab.com/gitlab-org/gitlab-runner/helpers/dns/test" 10 ) 11 12 func TestNewMachineName(t *testing.T) { 13 testCases := map[string]struct { 14 token string 15 }{ 16 "DNS-1123 compatible token": { 17 token: "token-of", 18 }, 19 "non DNS-1123 compatible token": { 20 token: "ToK3_?OF", 21 }, 22 } 23 24 for name, testCase := range testCases { 25 t.Run(name, func(t *testing.T) { 26 config := &common.RunnerConfig{ 27 RunnerCredentials: common.RunnerCredentials{ 28 Token: testCase.token, 29 }, 30 RunnerSettings: common.RunnerSettings{ 31 Machine: &common.DockerMachine{ 32 MachineName: "test-machine-%s", 33 }, 34 }, 35 } 36 37 name := newMachineName(config) 38 dns_test.AssertRFC1123Compatibility(t, name) 39 }) 40 } 41 } 42 43 func TestNewMachineNameIsUnique(t *testing.T) { 44 config := &common.RunnerConfig{ 45 RunnerSettings: common.RunnerSettings{ 46 Machine: &common.DockerMachine{ 47 MachineName: "test-machine-%s", 48 }, 49 }, 50 } 51 a := newMachineName(config) 52 b := newMachineName(config) 53 assert.NotEqual(t, a, b) 54 } 55 56 func TestMachineFilter(t *testing.T) { 57 filter := "machine-template-%s" 58 machines := []string{ 59 "test-machine", 60 "machine-template-10", 61 } 62 filtered := filterMachineList(machines, filter) 63 64 assert.NotContains(t, filtered, machines[0]) 65 assert.Contains(t, filtered, machines[1]) 66 }