mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-06 08:15:48 -04:00
cli: fix Azure SEV-SNP latest version logic (#2343)
This commit is contained in:
parent
2776e40df7
commit
118f789c2f
26 changed files with 547 additions and 245 deletions
|
@ -16,11 +16,11 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFetchLatestAzureSEVSNPVersion(t *testing.T) {
|
||||
now := time.Date(2023, 6, 12, 0, 0, 0, 0, time.UTC)
|
||||
latestStr := "2023-06-11-14-09.json"
|
||||
olderStr := "2019-01-01-01-01.json"
|
||||
testcases := map[string]struct {
|
||||
|
@ -29,21 +29,10 @@ func TestFetchLatestAzureSEVSNPVersion(t *testing.T) {
|
|||
wantErr bool
|
||||
want AzureSEVSNPVersionAPI
|
||||
}{
|
||||
"get latest version if older than 2 weeks": {
|
||||
"get latest version": {
|
||||
fetcherVersions: []string{latestStr, olderStr},
|
||||
timeAtTest: now.Add(days(15)),
|
||||
want: latestVersion,
|
||||
},
|
||||
"get older version if latest version is not older than minimum age": {
|
||||
fetcherVersions: []string{"2023-06-11-14-09.json", "2019-01-01-01-01.json"},
|
||||
timeAtTest: now.Add(days(7)),
|
||||
want: olderVersion,
|
||||
},
|
||||
"fail when no version is older minimum age": {
|
||||
fetcherVersions: []string{"2021-02-21-01-01.json", "2021-02-20-00-00.json"},
|
||||
timeAtTest: now.Add(days(2)),
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for name, tc := range testcases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
@ -54,8 +43,8 @@ func TestFetchLatestAzureSEVSNPVersion(t *testing.T) {
|
|||
olderVersion: olderStr,
|
||||
},
|
||||
}
|
||||
fetcher := newFetcherWithClientAndVerifier(client, dummyVerifier{})
|
||||
res, err := fetcher.FetchAzureSEVSNPVersionLatest(context.Background(), tc.timeAtTest)
|
||||
fetcher := newFetcherWithClientAndVerifier(client, dummyVerifier{}, constants.CDNRepositoryURL)
|
||||
res, err := fetcher.FetchAzureSEVSNPVersionLatest(context.Background())
|
||||
assert := assert.New(t)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -85,10 +74,6 @@ var olderVersion = AzureSEVSNPVersionAPI{
|
|||
},
|
||||
}
|
||||
|
||||
func days(days int) time.Duration {
|
||||
return time.Duration(days*24) * time.Hour
|
||||
}
|
||||
|
||||
type fakeConfigAPIHandler struct {
|
||||
versions []string
|
||||
latestVersion string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue