2023-11-14 04:03:01 -05:00
|
|
|
/*
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2024-06-11 10:25:24 -04:00
|
|
|
func TestVersionListMarshalUnmarshalJSON(t *testing.T) {
|
2023-11-14 04:03:01 -05:00
|
|
|
tests := map[string]struct {
|
2024-06-12 10:30:03 -04:00
|
|
|
input List
|
|
|
|
output List
|
2023-11-14 04:03:01 -05:00
|
|
|
wantDiff bool
|
|
|
|
}{
|
|
|
|
"success": {
|
2024-06-12 10:30:03 -04:00
|
|
|
input: List{List: []string{"v1", "v2"}},
|
|
|
|
output: List{List: []string{"v1", "v2"}},
|
2023-11-14 04:03:01 -05:00
|
|
|
},
|
|
|
|
"variant is lost": {
|
2024-06-12 10:30:03 -04:00
|
|
|
input: List{List: []string{"v1", "v2"}, Variant: variant.AzureSEVSNP{}},
|
|
|
|
output: List{List: []string{"v1", "v2"}},
|
2023-11-14 04:03:01 -05:00
|
|
|
},
|
|
|
|
"wrong order": {
|
2024-06-12 10:30:03 -04:00
|
|
|
input: List{List: []string{"v1", "v2"}},
|
|
|
|
output: List{List: []string{"v2", "v1"}},
|
2023-11-14 04:03:01 -05:00
|
|
|
wantDiff: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range tests {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
inputRaw, err := tc.input.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-06-12 10:30:03 -04:00
|
|
|
var actual List
|
2023-11-14 04:03:01 -05:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-11 10:25:24 -04:00
|
|
|
func TestVersionListAddVersion(t *testing.T) {
|
2023-11-14 04:03:01 -05:00
|
|
|
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) {
|
2024-06-12 10:30:03 -04:00
|
|
|
v := List{List: tc.versions}
|
2024-06-11 08:50:38 -04:00
|
|
|
v.AddVersion(tc.new)
|
2023-11-14 04:03:01 -05:00
|
|
|
|
2024-06-11 08:50:38 -04:00
|
|
|
assert.Equal(t, tc.expected, v.List)
|
2023-11-14 04:03:01 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|