mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-08 23:12:18 -04:00
versionsapi: merging of ImageInfo
This commit is contained in:
parent
d0e53cbb59
commit
874c4b76cf
2 changed files with 223 additions and 0 deletions
|
@ -281,3 +281,183 @@ func TestImageInfoValidateRequest(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeImageInfos(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
infos []ImageInfo
|
||||
wantInfo ImageInfo
|
||||
wantErr bool
|
||||
}{
|
||||
"only one element": {
|
||||
infos: []ImageInfo{
|
||||
{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantInfo: ImageInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"valid image info": {
|
||||
infos: []ImageInfo{
|
||||
{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "gcp",
|
||||
AttestationVariant: "gcp-sev-es",
|
||||
Reference: "image-123",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantInfo: ImageInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
{
|
||||
CSP: "gcp",
|
||||
AttestationVariant: "gcp-sev-es",
|
||||
Reference: "image-123",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"sorting": {
|
||||
infos: []ImageInfo{
|
||||
{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "gcp",
|
||||
AttestationVariant: "gcp-sev-es",
|
||||
Reference: "image-123",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantInfo: ImageInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
{
|
||||
CSP: "gcp",
|
||||
AttestationVariant: "gcp-sev-es",
|
||||
Reference: "image-123",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"mismatch in base info": {
|
||||
infos: []ImageInfo{
|
||||
{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "gcp",
|
||||
AttestationVariant: "gcp-sev-es",
|
||||
Reference: "image-123",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Ref: "other-ref",
|
||||
Stream: "stable",
|
||||
Version: "v2.0.0",
|
||||
List: []ImageInfoEntry{
|
||||
{
|
||||
CSP: "aws",
|
||||
AttestationVariant: "aws-nitro-tpm",
|
||||
Reference: "ami-123",
|
||||
Region: "us-east-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"empty list": {
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
gotInfo, err := MergeImageInfos(tc.infos...)
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.wantInfo, gotInfo)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue