github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/docker/helperimage/linux_info_test.go (about) 1 package helperimage 2 3 import ( 4 "fmt" 5 "runtime" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_linuxInfo_create(t *testing.T) { 12 tests := map[string]struct { 13 dockerArch string 14 revision string 15 expectedInfo Info 16 }{ 17 "When dockerArch not specified we fallback to runtime arch": { 18 dockerArch: "", 19 revision: "2923a43", 20 expectedInfo: Info{ 21 Architecture: getExpectedArch(), 22 Name: name, 23 Tag: fmt.Sprintf("%s-2923a43", getExpectedArch()), 24 IsSupportingLocalImport: true, 25 Cmd: bashCmd, 26 }, 27 }, 28 "Docker runs on armv6l": { 29 dockerArch: "armv6l", 30 revision: "2923a43", 31 expectedInfo: Info{ 32 Architecture: "arm", 33 Name: name, 34 Tag: "arm-2923a43", 35 IsSupportingLocalImport: true, 36 Cmd: bashCmd, 37 }, 38 }, 39 "Docker runs on amd64": { 40 dockerArch: "amd64", 41 revision: "2923a43", 42 expectedInfo: Info{ 43 Architecture: "x86_64", 44 Name: name, 45 Tag: "x86_64-2923a43", 46 IsSupportingLocalImport: true, 47 Cmd: bashCmd, 48 }, 49 }, 50 "Configured architecture is unknown": { 51 dockerArch: "some-random-arch", 52 revision: "2923a43", 53 expectedInfo: Info{ 54 Architecture: "some-random-arch", 55 Name: name, 56 Tag: "some-random-arch-2923a43", 57 IsSupportingLocalImport: true, 58 Cmd: bashCmd, 59 }, 60 }, 61 } 62 63 for name, test := range tests { 64 t.Run(name, func(t *testing.T) { 65 l := new(linuxInfo) 66 67 image, err := l.Create(test.revision, Config{Architecture: test.dockerArch}) 68 69 assert.NoError(t, err) 70 assert.Equal(t, test.expectedInfo, image) 71 }) 72 } 73 } 74 75 // We re write amd64 to x86_64 for the helper image, and we don't want this test 76 // to be runtime dependant. 77 func getExpectedArch() string { 78 if runtime.GOARCH == "amd64" { 79 return "x86_64" 80 81 } 82 83 return runtime.GOARCH 84 }