-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEVOPS-123] Added optional ability to perform supported image versio…
…ns checks. (#32) * Added image versions checks to enable optional control over supported packages. * Adjusted version checks. * Added Utils function tests. * Renamed check function to be less ambiguous. --------- Co-authored-by: Roman Barbun <[email protected]>
- Loading branch information
Showing
8 changed files
with
139 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,35 @@ func TestDockerfileCheck(t *testing.T) { | |
func TestInvalidDockerfileCheck(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
Allowed: []string{"bitnami/redis"}, | ||
Allowed: []string{"bitnami/redis@latest"}, | ||
Paths: []string{"./fixtures/compose-dockerfile"}, | ||
} | ||
c.RunCheck() | ||
assert.Equal(result.Fail, c.Result.Status) | ||
assert.EqualValues( | ||
[]string{"service1 is using invalid base image bitnami/kubectl"}, | ||
c.Result.Failures, | ||
) | ||
} | ||
|
||
func TestValidDockerfileImageVersion(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
Allowed: []string{"bitnami/[email protected]"}, | ||
Paths: []string{"./fixtures/compose-dockerfile"}, | ||
} | ||
c.RunCheck() | ||
assert.Equal(result.Pass, c.Result.Status) | ||
assert.EqualValues( | ||
[]string{"service1 is using valid base images"}, | ||
c.Result.Passes, | ||
) | ||
} | ||
|
||
func TestInvalidDockerfileImageVersion(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
Allowed: []string{"bitnami/kubectl:1.26"}, | ||
Paths: []string{"./fixtures/compose-dockerfile"}, | ||
} | ||
c.RunCheck() | ||
|
@@ -84,6 +112,30 @@ func TestValidImage(t *testing.T) { | |
) | ||
} | ||
|
||
func TestValidImageVersions(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
Allowed: []string{ | ||
"bitnami/[email protected]", | ||
"bitnami/postgresql:15", | ||
"bitnami/redis", | ||
"bitnami/mongodb@latest", | ||
}, | ||
Paths: []string{"./fixtures/compose-image"}, | ||
} | ||
c.RunCheck() | ||
assert.Equal(result.Pass, c.Result.Status) | ||
assert.ElementsMatch( | ||
[]string{ | ||
"service1 is using valid base images", | ||
"service2 is using valid base images", | ||
"service3 is using valid base images", | ||
"service4 is using valid base images", | ||
}, | ||
c.Result.Passes, | ||
) | ||
} | ||
|
||
func TestInvalidImageCheck(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
|
@@ -102,6 +154,27 @@ func TestInvalidImageCheck(t *testing.T) { | |
) | ||
} | ||
|
||
func TestInvalidImageVersions(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
Allowed: []string{ | ||
"bitnami/kubectl@latest", | ||
"bitnami/postgresql:17", | ||
"bitnami/redis", | ||
}, | ||
Paths: []string{"./fixtures/compose-image"}, | ||
} | ||
c.RunCheck() | ||
assert.Equal(result.Fail, c.Result.Status) | ||
assert.EqualValues( | ||
[]string{ | ||
"service2 is using invalid base image bitnami/postgresql", | ||
"service4 is using invalid base image bitnami/mongodb", | ||
}, | ||
c.Result.Failures, | ||
) | ||
} | ||
|
||
func TestDockerfileWarning(t *testing.T) { | ||
assert := assert.New(t) | ||
c := docker.BaseImageCheck{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
FROM bitnami/kubectl | ||
FROM bitnami/kubectl:1.25.12-debian-11-r6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,3 +477,12 @@ func TestHasComposerDependency(t *testing.T) { | |
t.Errorf("expected file not found got %s", err) | ||
} | ||
} | ||
|
||
func TestPackageCheckString(t *testing.T) { | ||
assert := assert.New(t) | ||
assert.False(PackageCheckString([]string{}, "bitnami/kubectl", "")) | ||
assert.False(PackageCheckString([]string{"bitnami/postgresql@16"}, "bitnami/kubectl", "1.24")) | ||
assert.False(PackageCheckString([]string{"bitnami/postgresql@16", "bitnami/[email protected]"}, "bitnami/kubectl", "1.23-alpha")) | ||
assert.True(PackageCheckString([]string{"bitnami/postgresql@16", "bitnami/kubectl"}, "bitnami/kubectl", "1.24")) | ||
assert.True(PackageCheckString([]string{"bitnami/postgresql@16", "bitnami/kubectl:1.24"}, "bitnami/kubectl", "1.25")) | ||
} |