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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//go:build !integration
// +build !integration
package helperimage
import (
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitlab-runner/shells"
)
func Test_linuxInfo_create(t *testing.T) {
t.Skip("DM-disabled");
for _, shell := range []string{"sh", "bash", shells.SNPwsh} {
expectedTagSuffix := ""
expectedCmd := bashCmd
if shell == shells.SNPwsh {
expectedTagSuffix = "-pwsh"
expectedCmd = getPowerShellCmd(shell)
}
tests := map[string]struct {
shell string
dockerArch string
revision string
gitlabRegistry bool
flavor string
expectedInfo Info
}{
"When dockerArch not specified we fallback to runtime arch": {
shell: shell,
dockerArch: "",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: getExpectedArch(),
Name: GitLabRegistryName,
Tag: fmt.Sprintf("%s-2923a43%s", getExpectedArch(), expectedTagSuffix),
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Docker runs on armv6l": {
shell: shell,
dockerArch: "armv6l",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: "arm",
Name: GitLabRegistryName,
Tag: "arm-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Docker runs on amd64": {
shell: shell,
dockerArch: "amd64",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: "x86_64",
Name: GitLabRegistryName,
Tag: "x86_64-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Docker runs on arm64": {
shell: shell,
dockerArch: "aarch64",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: "arm64",
Name: GitLabRegistryName,
Tag: "arm64-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Docker runs on s390x": {
shell: shell,
dockerArch: "s390x",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: "s390x",
Name: GitLabRegistryName,
Tag: "s390x-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Docker runs on ppc64le": {
shell: shell,
dockerArch: "ppc64le",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: "ppc64le",
Name: GitLabRegistryName,
Tag: "ppc64le-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Configured architecture is unknown": {
shell: shell,
dockerArch: "some-random-arch",
revision: "2923a43",
gitlabRegistry: true,
expectedInfo: Info{
Architecture: "some-random-arch",
Name: GitLabRegistryName,
Tag: "some-random-arch-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"DockerHub registry configured": {
dockerArch: "amd64",
revision: "2923a43",
gitlabRegistry: false,
expectedInfo: Info{
Architecture: "x86_64",
Name: DockerHubName,
Tag: "x86_64-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Flavor configured default registry": {
dockerArch: "amd64",
revision: "2923a43",
gitlabRegistry: true,
flavor: "ubuntu",
expectedInfo: Info{
Architecture: "x86_64",
Name: GitLabRegistryName,
Tag: "ubuntu-x86_64-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Flavor configured DockerHub registry": {
dockerArch: "amd64",
revision: "2923a43",
gitlabRegistry: false,
flavor: "ubuntu",
expectedInfo: Info{
Architecture: "x86_64",
Name: DockerHubName,
Tag: "ubuntu-x86_64-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
"Alpine3.13 flavor configured DockerHub registry": {
dockerArch: "amd64",
revision: "2923a43",
gitlabRegistry: false,
flavor: "alpine3.13",
expectedInfo: Info{
Architecture: "x86_64",
Name: DockerHubName,
Tag: "alpine3.13-x86_64-2923a43" + expectedTagSuffix,
IsSupportingLocalImport: true,
Cmd: expectedCmd,
},
},
}
t.Run(shell, func(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
l := new(linuxInfo)
image, err := l.Create(
test.revision,
Config{
Architecture: test.dockerArch,
Shell: shell,
GitLabRegistry: test.gitlabRegistry,
Flavor: test.flavor,
},
)
assert.NoError(t, err)
assert.Equal(t, test.expectedInfo, image)
})
}
})
}
}
// We re write amd64 to x86_64 for the helper image, and we don't want this test
// to be runtime dependant.
func getExpectedArch() string {
if runtime.GOARCH == "amd64" {
return "x86_64"
}
return runtime.GOARCH
}
|