mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-20 15:10:28 -04:00
cli: upgrade errors for microservice (#1259)
Handle invalid upgrade errors similarly as for images and k8s.
This commit is contained in:
parent
6b9065b444
commit
984f0589d2
6 changed files with 72 additions and 134 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/compatibility"
|
||||
"github.com/edgelesssys/constellation/v2/internal/config"
|
||||
"github.com/edgelesssys/constellation/v2/internal/logger"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -18,83 +19,33 @@ import (
|
|||
"helm.sh/helm/v3/pkg/release"
|
||||
)
|
||||
|
||||
func TestIsUpgrade(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
currentVersion string
|
||||
newVersion string
|
||||
wantUpgrade bool
|
||||
}{
|
||||
"upgrade": {
|
||||
currentVersion: "0.1.0",
|
||||
newVersion: "0.2.0",
|
||||
wantUpgrade: true,
|
||||
},
|
||||
"downgrade": {
|
||||
currentVersion: "0.2.0",
|
||||
newVersion: "0.1.0",
|
||||
wantUpgrade: false,
|
||||
},
|
||||
"equal": {
|
||||
currentVersion: "0.1.0",
|
||||
newVersion: "0.1.0",
|
||||
wantUpgrade: false,
|
||||
},
|
||||
"invalid current version": {
|
||||
currentVersion: "asdf",
|
||||
newVersion: "0.1.0",
|
||||
wantUpgrade: false,
|
||||
},
|
||||
"invalid new version": {
|
||||
currentVersion: "0.1.0",
|
||||
newVersion: "asdf",
|
||||
wantUpgrade: false,
|
||||
},
|
||||
"patch version": {
|
||||
currentVersion: "0.1.0",
|
||||
newVersion: "0.1.1",
|
||||
wantUpgrade: true,
|
||||
},
|
||||
"pre-release version": {
|
||||
currentVersion: "0.1.0",
|
||||
newVersion: "0.1.1-rc1",
|
||||
wantUpgrade: true,
|
||||
},
|
||||
"pre-release version downgrade": {
|
||||
currentVersion: "0.1.1-rc1",
|
||||
newVersion: "0.1.0",
|
||||
wantUpgrade: false,
|
||||
},
|
||||
"pre-release of same version": {
|
||||
currentVersion: "0.1.0",
|
||||
newVersion: "0.1.0-rc1",
|
||||
wantUpgrade: false,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
upgrade := isUpgrade(tc.currentVersion, tc.newVersion)
|
||||
assert.Equal(tc.wantUpgrade, upgrade)
|
||||
|
||||
upgrade = isUpgrade("v"+tc.currentVersion, "v"+tc.newVersion)
|
||||
assert.Equal(tc.wantUpgrade, upgrade)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpgradeRelease(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
allowDestructive bool
|
||||
wantError bool
|
||||
allowDestructive bool
|
||||
version string
|
||||
assertCorrectError func(t *testing.T, err error) bool
|
||||
wantError bool
|
||||
}{
|
||||
"allow": {
|
||||
allowDestructive: true,
|
||||
version: "1.9.0",
|
||||
},
|
||||
"not a valid upgrade": {
|
||||
allowDestructive: true,
|
||||
version: "1.0.0",
|
||||
assertCorrectError: func(t *testing.T, err error) bool {
|
||||
target := &compatibility.InvalidUpgradeError{}
|
||||
return assert.ErrorAs(t, err, &target)
|
||||
},
|
||||
wantError: true,
|
||||
},
|
||||
"deny": {
|
||||
allowDestructive: false,
|
||||
wantError: true,
|
||||
version: "1.9.0",
|
||||
assertCorrectError: func(t *testing.T, err error) bool {
|
||||
return assert.ErrorIs(t, err, ErrConfirmationMissing)
|
||||
},
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -102,10 +53,10 @@ func TestUpgradeRelease(t *testing.T) {
|
|||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
client := Client{kubectl: nil, actions: &stubActionWrapper{}, log: logger.NewTest(t)}
|
||||
client := Client{kubectl: nil, actions: &stubActionWrapper{version: tc.version}, log: logger.NewTest(t)}
|
||||
err := client.upgradeRelease(context.Background(), 0, config.Default(), certManagerPath, certManagerReleaseName, false, tc.allowDestructive)
|
||||
if tc.wantError {
|
||||
assert.ErrorIs(err, ErrConfirmationMissing)
|
||||
tc.assertCorrectError(t, err)
|
||||
return
|
||||
}
|
||||
assert.NoError(err)
|
||||
|
@ -113,11 +64,13 @@ func TestUpgradeRelease(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type stubActionWrapper struct{}
|
||||
type stubActionWrapper struct {
|
||||
version string
|
||||
}
|
||||
|
||||
// listAction returns a list of len 1 with a release that has only it's version set.
|
||||
func (a *stubActionWrapper) listAction(_ string) ([]*release.Release, error) {
|
||||
return []*release.Release{{Chart: &chart.Chart{Metadata: &chart.Metadata{Version: "1.0.0"}}}}, nil
|
||||
return []*release.Release{{Chart: &chart.Chart{Metadata: &chart.Metadata{Version: a.version}}}}, nil
|
||||
}
|
||||
|
||||
func (a *stubActionWrapper) getValues(release string) (map[string]any, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue