mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-26 15:10:43 -04:00
api: refactor attestationconfigapi client/fetcher
There is now one SEVSNPVersions type that has a variant property. That property is used to build the correct JSON path. The surrounding methods handling the version objects are also updated to receive a variant argument and work for multiple variants. This simplifies adding AWS support.
This commit is contained in:
parent
5542f9c63c
commit
350397923f
16 changed files with 411 additions and 262 deletions
77
internal/api/attestationconfigapi/snp_test.go
Normal file
77
internal/api/attestationconfigapi/snp_test.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package attestationconfigapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSEVSNPVersionListMarshalUnmarshalJSON(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
input SEVSNPVersionList
|
||||
output SEVSNPVersionList
|
||||
wantDiff bool
|
||||
}{
|
||||
"success": {
|
||||
input: SEVSNPVersionList{list: []string{"v1", "v2"}},
|
||||
output: SEVSNPVersionList{list: []string{"v1", "v2"}},
|
||||
},
|
||||
"variant is lost": {
|
||||
input: SEVSNPVersionList{list: []string{"v1", "v2"}, variant: variant.AzureSEVSNP{}},
|
||||
output: SEVSNPVersionList{list: []string{"v1", "v2"}},
|
||||
},
|
||||
"wrong order": {
|
||||
input: SEVSNPVersionList{list: []string{"v1", "v2"}},
|
||||
output: SEVSNPVersionList{list: []string{"v2", "v1"}},
|
||||
wantDiff: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
inputRaw, err := tc.input.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
var actual SEVSNPVersionList
|
||||
err = actual.UnmarshalJSON(inputRaw)
|
||||
require.NoError(t, err)
|
||||
|
||||
if tc.wantDiff {
|
||||
assert.NotEqual(t, tc.output, actual, "Objects are equal, expected unequal")
|
||||
} else {
|
||||
assert.Equal(t, tc.output, actual, "Objects are not equal, expected equal")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSEVSNPVersionListAddVersion(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
versions []string
|
||||
new string
|
||||
expected []string
|
||||
}{
|
||||
"success": {
|
||||
versions: []string{"v1", "v2"},
|
||||
new: "v3",
|
||||
expected: []string{"v3", "v2", "v1"},
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
v := SEVSNPVersionList{list: tc.versions}
|
||||
v.addVersion(tc.new)
|
||||
|
||||
assert.Equal(t, tc.expected, v.list)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue