Commit 9c8b8f41 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Merge branch '4179-refactor-helperimage-package-tests' into 'master'

Refactor helperimage package tests

Closes #4179

See merge request !1327
parents 47038114 7ac782e8
Pipeline #57978469 passed with stages
in 62 minutes and 15 seconds
......@@ -9,7 +9,7 @@ import (
)
func TestGetInfo(t *testing.T) {
testCases := []struct {
tests := []struct {
osType string
expectedHelperImageType interface{}
expectedError interface{}
......@@ -19,11 +19,11 @@ func TestGetInfo(t *testing.T) {
{osType: "unsupported", expectedError: errors.NewErrOSNotSupported("unsupported")},
}
for _, testCase := range testCases {
t.Run(testCase.osType, func(t *testing.T) {
_, err := Get(headRevision, Config{OSType: testCase.osType})
for _, test := range tests {
t.Run(test.osType, func(t *testing.T) {
_, err := Get(headRevision, Config{OSType: test.osType})
assert.Equal(t, testCase.expectedError, err)
assert.Equal(t, test.expectedError, err)
})
}
}
......@@ -38,7 +38,7 @@ func TestContainerImage_String(t *testing.T) {
}
func Test_imageRevision(t *testing.T) {
testCases := []struct {
tests := []struct {
revision string
expectedTag string
}{
......@@ -52,9 +52,9 @@ func Test_imageRevision(t *testing.T) {
},
}
for _, testCase := range testCases {
t.Run(testCase.revision, func(t *testing.T) {
assert.Equal(t, testCase.expectedTag, imageRevision(testCase.revision))
for _, test := range tests {
t.Run(test.revision, func(t *testing.T) {
assert.Equal(t, test.expectedTag, imageRevision(test.revision))
})
}
......
......@@ -9,14 +9,12 @@ import (
)
func Test_linuxInfo_create(t *testing.T) {
cases := []struct {
name string
tests := map[string]struct {
dockerArch string
revision string
expectedInfo Info
}{
{
name: "When dockerArch not specified we fallback to runtime arch",
"When dockerArch not specified we fallback to runtime arch": {
dockerArch: "",
revision: "2923a43",
expectedInfo: Info{
......@@ -26,8 +24,7 @@ func Test_linuxInfo_create(t *testing.T) {
IsSupportingLocalImport: true,
},
},
{
name: "Docker runs on armv6l",
"Docker runs on armv6l": {
dockerArch: "armv6l",
revision: "2923a43",
expectedInfo: Info{
......@@ -37,8 +34,7 @@ func Test_linuxInfo_create(t *testing.T) {
IsSupportingLocalImport: true,
},
},
{
name: "Docker runs on amd64",
"Docker runs on amd64": {
dockerArch: "amd64",
revision: "2923a43",
expectedInfo: Info{
......@@ -50,14 +46,14 @@ func Test_linuxInfo_create(t *testing.T) {
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
l := new(linuxInfo)
image, err := l.Create(c.revision, Config{Architecture: c.dockerArch})
image, err := l.Create(test.revision, Config{Architecture: test.dockerArch})
assert.NoError(t, err)
assert.Equal(t, c.expectedInfo, image)
assert.Equal(t, test.expectedInfo, image)
})
}
}
......
......@@ -9,7 +9,7 @@ import (
func Test_windowsInfo_create(t *testing.T) {
revision := "4011f186"
cases := []struct {
tests := []struct {
operatingSystem string
expectedInfo Info
expectedErr error
......@@ -19,7 +19,7 @@ func Test_windowsInfo_create(t *testing.T) {
expectedInfo: Info{
Architecture: windowsSupportedArchitecture,
Name: name,
Tag: fmt.Sprintf("%s-%s-%s", "x86_64", revision, baseImage1809),
Tag: fmt.Sprintf("%s-%s-%s", windowsSupportedArchitecture, revision, baseImage1809),
IsSupportingLocalImport: false,
},
expectedErr: nil,
......@@ -29,7 +29,7 @@ func Test_windowsInfo_create(t *testing.T) {
expectedInfo: Info{
Architecture: windowsSupportedArchitecture,
Name: name,
Tag: fmt.Sprintf("%s-%s-%s", "x86_64", revision, baseImage1809),
Tag: fmt.Sprintf("%s-%s-%s", windowsSupportedArchitecture, revision, baseImage1809),
IsSupportingLocalImport: false,
},
expectedErr: nil,
......@@ -39,7 +39,7 @@ func Test_windowsInfo_create(t *testing.T) {
expectedInfo: Info{
Architecture: windowsSupportedArchitecture,
Name: name,
Tag: fmt.Sprintf("%s-%s-%s", "x86_64", revision, baseImage1803),
Tag: fmt.Sprintf("%s-%s-%s", windowsSupportedArchitecture, revision, baseImage1803),
IsSupportingLocalImport: false,
},
expectedErr: nil,
......@@ -50,14 +50,14 @@ func Test_windowsInfo_create(t *testing.T) {
},
}
for _, c := range cases {
t.Run(c.operatingSystem, func(t *testing.T) {
for _, test := range tests {
t.Run(test.operatingSystem, func(t *testing.T) {
w := new(windowsInfo)
image, err := w.Create(revision, Config{OperatingSystem: c.operatingSystem})
image, err := w.Create(revision, Config{OperatingSystem: test.operatingSystem})
assert.Equal(t, c.expectedInfo, image)
assert.Equal(t, c.expectedErr, err)
assert.Equal(t, test.expectedInfo, image)
assert.Equal(t, test.expectedErr, err)
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment