mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
26305e8f80
* init * fixup! init * gcp working? * fixup! fixup! init * azure cfg for microService installation * fixup! azure cfg for microService installation * fixup! azure cfg for microService installation * cleanup bootstrapper code * cleanup helminstall code * fixup! cleanup helminstall code * Update internal/deploy/helm/install.go Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com> * daniel feedback * TODO add provider (also to CreateCluster) so we can ensure that provider specific output * fixup! daniel feedback * use debugLog in helm installer * placeholderHelmInstaller * rename to stub --------- Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package cloudcmd
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/edgelesssys/constellation/v2/cli/internal/terraform"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTerminator(t *testing.T) {
|
|
someErr := errors.New("failed")
|
|
|
|
testCases := map[string]struct {
|
|
tfClient tfResourceClient
|
|
newTfClientErr error
|
|
libvirt *stubLibvirtRunner
|
|
wantErr bool
|
|
}{
|
|
"gcp": {
|
|
libvirt: &stubLibvirtRunner{},
|
|
tfClient: &stubTerraformClient{},
|
|
},
|
|
"newTfClientErr": {
|
|
libvirt: &stubLibvirtRunner{},
|
|
newTfClientErr: someErr,
|
|
wantErr: true,
|
|
},
|
|
"destroy cluster error": {
|
|
tfClient: &stubTerraformClient{destroyErr: someErr},
|
|
libvirt: &stubLibvirtRunner{},
|
|
wantErr: true,
|
|
},
|
|
"clean up workspace error": {
|
|
tfClient: &stubTerraformClient{cleanUpWorkspaceErr: someErr},
|
|
libvirt: &stubLibvirtRunner{},
|
|
wantErr: true,
|
|
},
|
|
"qemu stop libvirt error": {
|
|
tfClient: &stubTerraformClient{},
|
|
libvirt: &stubLibvirtRunner{stopErr: someErr},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
terminator := &Terminator{
|
|
newTerraformClient: func(ctx context.Context) (tfResourceClient, error) {
|
|
return tc.tfClient, tc.newTfClientErr
|
|
},
|
|
newLibvirtRunner: func() libvirtRunner {
|
|
return tc.libvirt
|
|
},
|
|
}
|
|
|
|
err := terminator.Terminate(context.Background(), terraform.LogLevelNone)
|
|
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
return
|
|
}
|
|
assert.NoError(err)
|
|
cl := tc.tfClient.(*stubTerraformClient)
|
|
assert.True(cl.destroyCalled)
|
|
assert.True(cl.removeInstallerCalled)
|
|
assert.True(tc.libvirt.stopCalled)
|
|
})
|
|
}
|
|
}
|