2023-01-31 05:45:31 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-07-25 08:20:25 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/semver"
|
2023-01-31 05:45:31 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestValidateVersionCompatibilityHelper checks that basic version and image short paths are correctly validated.
|
|
|
|
func TestValidateVersionCompatibilityHelper(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2023-07-25 08:20:25 -04:00
|
|
|
cli semver.Semver
|
2023-01-31 05:45:31 -05:00
|
|
|
target string
|
|
|
|
wantError bool
|
|
|
|
}{
|
|
|
|
"full version works": {
|
2023-07-25 08:20:25 -04:00
|
|
|
cli: semver.NewFromInt(0, 1, 0, ""),
|
2023-01-31 05:45:31 -05:00
|
|
|
target: "v0.0.0",
|
|
|
|
},
|
|
|
|
"short path works": {
|
2023-07-25 08:20:25 -04:00
|
|
|
cli: semver.NewFromInt(0, 1, 0, ""),
|
2023-01-31 05:45:31 -05:00
|
|
|
target: "ref/main/stream/debug/v0.0.0-pre.0.20230109121528-d24fac00f018",
|
|
|
|
},
|
|
|
|
"minor version difference > 1": {
|
2023-07-25 08:20:25 -04:00
|
|
|
cli: semver.NewFromInt(0, 0, 0, ""),
|
2023-01-31 05:45:31 -05:00
|
|
|
target: "ref/main/stream/debug/v0.2.0-pre.0.20230109121528-d24fac00f018",
|
|
|
|
wantError: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2023-07-25 08:20:25 -04:00
|
|
|
err := validateImageCompatibilityHelper(tc.cli, "image", tc.target)
|
|
|
|
if tc.wantError {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateMicroserviceVersion(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
cli semver.Semver
|
|
|
|
services semver.Semver
|
|
|
|
wantError bool
|
|
|
|
}{
|
|
|
|
"success": {
|
|
|
|
cli: semver.NewFromInt(0, 1, 0, ""),
|
|
|
|
services: semver.NewFromInt(0, 0, 0, ""),
|
|
|
|
},
|
|
|
|
"minor version difference > 1": {
|
|
|
|
cli: semver.NewFromInt(0, 0, 0, ""),
|
|
|
|
services: semver.NewFromInt(0, 2, 0, "pre.0.20230109121528-d24fac00f018"),
|
|
|
|
wantError: true,
|
|
|
|
},
|
|
|
|
"major version difference": {
|
|
|
|
cli: semver.NewFromInt(0, 0, 0, ""),
|
|
|
|
services: semver.NewFromInt(1, 0, 0, ""),
|
|
|
|
wantError: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
err := validateMicroserviceVersion(tc.cli, tc.services)
|
2023-01-31 05:45:31 -05:00
|
|
|
if tc.wantError {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|