mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-07-22 06:50:43 -04:00
Pin container image hashes
This commit is contained in:
parent
884c46179a
commit
4ccd96bf64
4 changed files with 86 additions and 24 deletions
46
internal/versions/versions_test.go
Normal file
46
internal/versions/versions_test.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package versions
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestVersionFromDockerImage(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
imageName string
|
||||
wantVersion string
|
||||
wantPanic bool
|
||||
}{
|
||||
"valid image name": {
|
||||
imageName: "k8s.gcr.io/kube-apiserver:v1.18.0",
|
||||
wantVersion: "v1.18.0",
|
||||
},
|
||||
"valid image name with sha": {
|
||||
imageName: "k8s.gcr.io/kube-apiserver:v1.18.0@sha256:1234567890abcdef",
|
||||
wantVersion: "v1.18.0",
|
||||
},
|
||||
"invalid image name": {
|
||||
imageName: "k8s.gcr.io/kube-apiserver",
|
||||
wantPanic: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
if tc.wantPanic {
|
||||
assert.Panics(func() { versionFromDockerImage(tc.imageName) })
|
||||
} else {
|
||||
assert.Equal(tc.wantVersion, versionFromDockerImage(tc.imageName))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue