mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-26 16:09:45 -05:00
e66cb84d6e
* Dont clean up workspace if rollback fails * Remove dependency on CSP from terminate Signed-off-by: Daniel Weiße <dw@edgeless.systems>
113 lines
2.4 KiB
Go
113 lines
2.4 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package cloudcmd
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRollbackTerraform(t *testing.T) {
|
|
someErr := errors.New("failed")
|
|
|
|
testCases := map[string]struct {
|
|
tfClient *stubTerraformClient
|
|
wantErr bool
|
|
}{
|
|
"success": {
|
|
tfClient: &stubTerraformClient{},
|
|
},
|
|
"destroy cluster error": {
|
|
tfClient: &stubTerraformClient{destroyClusterErr: someErr},
|
|
wantErr: true,
|
|
},
|
|
"clean up workspace error": {
|
|
tfClient: &stubTerraformClient{cleanUpWorkspaceErr: someErr},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
rollbacker := &rollbackerTerraform{
|
|
client: tc.tfClient,
|
|
}
|
|
|
|
err := rollbacker.rollback(context.Background())
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
if tc.tfClient.cleanUpWorkspaceErr == nil {
|
|
assert.False(tc.tfClient.cleanUpWorkspaceCalled)
|
|
}
|
|
return
|
|
}
|
|
assert.NoError(err)
|
|
assert.True(tc.tfClient.destroyClusterCalled)
|
|
assert.True(tc.tfClient.cleanUpWorkspaceCalled)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRollbackQEMU(t *testing.T) {
|
|
someErr := errors.New("failed")
|
|
|
|
testCases := map[string]struct {
|
|
libvirt *stubLibvirtRunner
|
|
tfClient *stubTerraformClient
|
|
wantErr bool
|
|
}{
|
|
"success": {
|
|
libvirt: &stubLibvirtRunner{},
|
|
tfClient: &stubTerraformClient{},
|
|
},
|
|
"stop libvirt error": {
|
|
libvirt: &stubLibvirtRunner{stopErr: someErr},
|
|
tfClient: &stubTerraformClient{},
|
|
wantErr: true,
|
|
},
|
|
"destroy cluster error": {
|
|
libvirt: &stubLibvirtRunner{stopErr: someErr},
|
|
tfClient: &stubTerraformClient{destroyClusterErr: someErr},
|
|
wantErr: true,
|
|
},
|
|
"clean up workspace error": {
|
|
libvirt: &stubLibvirtRunner{},
|
|
tfClient: &stubTerraformClient{cleanUpWorkspaceErr: someErr},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
rollbacker := &rollbackerQEMU{
|
|
libvirt: tc.libvirt,
|
|
client: tc.tfClient,
|
|
}
|
|
|
|
err := rollbacker.rollback(context.Background())
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
if tc.tfClient.cleanUpWorkspaceErr == nil {
|
|
assert.False(tc.tfClient.cleanUpWorkspaceCalled)
|
|
}
|
|
return
|
|
}
|
|
assert.NoError(err)
|
|
assert.True(tc.libvirt.stopCalled)
|
|
assert.True(tc.tfClient.destroyClusterCalled)
|
|
assert.True(tc.tfClient.cleanUpWorkspaceCalled)
|
|
})
|
|
}
|
|
}
|