mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-05 07:45:27 -04:00
cli: fix iam rollback (#1148)
* AB#2897 rename DestroyCluster * #AB2897 error if terraform dir exists * AB#2897 reword DestroyResources
This commit is contained in:
parent
94245416ca
commit
7410cf8038
11 changed files with 92 additions and 32 deletions
|
@ -67,15 +67,18 @@ func TestParseIDFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIAMCreateAWS(t *testing.T) {
|
||||
defaultFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs {
|
||||
defaultFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs {
|
||||
fs := afero.NewMemMapFs()
|
||||
fileHandler := file.NewHandler(fs)
|
||||
for _, f := range existingFiles {
|
||||
require.NoError(fileHandler.Write(f, []byte{1, 2, 3}, file.OptNone))
|
||||
}
|
||||
for _, d := range existingDirs {
|
||||
require.NoError(fs.MkdirAll(d, 0o755))
|
||||
}
|
||||
return fs
|
||||
}
|
||||
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs {
|
||||
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs {
|
||||
fs := afero.NewReadOnlyFs(afero.NewMemMapFs())
|
||||
return fs
|
||||
}
|
||||
|
@ -88,7 +91,7 @@ func TestIAMCreateAWS(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
setupFs func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs
|
||||
setupFs func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs
|
||||
creator *stubIAMCreator
|
||||
provider cloudprovider.Provider
|
||||
zoneFlag string
|
||||
|
@ -97,6 +100,7 @@ func TestIAMCreateAWS(t *testing.T) {
|
|||
generateConfigFlag bool
|
||||
configFlag string
|
||||
existingFiles []string
|
||||
existingDirs []string
|
||||
stdin string
|
||||
wantAbort bool
|
||||
wantErr bool
|
||||
|
@ -153,6 +157,16 @@ func TestIAMCreateAWS(t *testing.T) {
|
|||
configFlag: "custom-config.yaml",
|
||||
existingFiles: []string{"custom-config.yaml"},
|
||||
},
|
||||
"iam create aws existing terraform dir": {
|
||||
setupFs: defaultFs,
|
||||
creator: &stubIAMCreator{id: validIAMIDFile},
|
||||
provider: cloudprovider.AWS,
|
||||
zoneFlag: "us-east-2a",
|
||||
prefixFlag: "test",
|
||||
yesFlag: true,
|
||||
wantErr: true,
|
||||
existingDirs: []string{constants.TerraformIAMWorkingDir},
|
||||
},
|
||||
"interactive": {
|
||||
setupFs: defaultFs,
|
||||
creator: &stubIAMCreator{id: validIAMIDFile},
|
||||
|
@ -244,7 +258,7 @@ func TestIAMCreateAWS(t *testing.T) {
|
|||
require.NoError(cmd.Flags().Set("config", tc.configFlag))
|
||||
}
|
||||
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider, tc.existingFiles))
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider, tc.existingFiles, tc.existingDirs))
|
||||
|
||||
iamCreator := &iamCreator{
|
||||
cmd: cmd,
|
||||
|
@ -285,15 +299,18 @@ func TestIAMCreateAWS(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIAMCreateAzure(t *testing.T) {
|
||||
defaultFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs {
|
||||
defaultFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs {
|
||||
fs := afero.NewMemMapFs()
|
||||
fileHandler := file.NewHandler(fs)
|
||||
for _, f := range existingFiles {
|
||||
require.NoError(fileHandler.Write(f, []byte{1, 2, 3}, file.OptNone))
|
||||
}
|
||||
for _, d := range existingDirs {
|
||||
require.NoError(fs.MkdirAll(d, 0o755))
|
||||
}
|
||||
return fs
|
||||
}
|
||||
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs {
|
||||
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs {
|
||||
fs := afero.NewReadOnlyFs(afero.NewMemMapFs())
|
||||
return fs
|
||||
}
|
||||
|
@ -309,7 +326,7 @@ func TestIAMCreateAzure(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
setupFs func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs
|
||||
setupFs func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs
|
||||
creator *stubIAMCreator
|
||||
provider cloudprovider.Provider
|
||||
regionFlag string
|
||||
|
@ -319,6 +336,7 @@ func TestIAMCreateAzure(t *testing.T) {
|
|||
generateConfigFlag bool
|
||||
configFlag string
|
||||
existingFiles []string
|
||||
existingDirs []string
|
||||
stdin string
|
||||
wantAbort bool
|
||||
wantErr bool
|
||||
|
@ -380,6 +398,17 @@ func TestIAMCreateAzure(t *testing.T) {
|
|||
yesFlag: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"iam create azure existing terraform dir": {
|
||||
setupFs: defaultFs,
|
||||
creator: &stubIAMCreator{id: validIAMIDFile},
|
||||
provider: cloudprovider.Azure,
|
||||
regionFlag: "westus",
|
||||
servicePrincipalFlag: "constell-test-sp",
|
||||
resourceGroupFlag: "constell-test-rg",
|
||||
yesFlag: true,
|
||||
wantErr: true,
|
||||
existingDirs: []string{constants.TerraformIAMWorkingDir},
|
||||
},
|
||||
"interactive": {
|
||||
setupFs: defaultFs,
|
||||
creator: &stubIAMCreator{id: validIAMIDFile},
|
||||
|
@ -469,7 +498,7 @@ func TestIAMCreateAzure(t *testing.T) {
|
|||
require.NoError(cmd.Flags().Set("config", tc.configFlag))
|
||||
}
|
||||
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider, tc.existingFiles))
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider, tc.existingFiles, tc.existingDirs))
|
||||
|
||||
iamCreator := &iamCreator{
|
||||
cmd: cmd,
|
||||
|
@ -513,15 +542,18 @@ func TestIAMCreateAzure(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIAMCreateGCP(t *testing.T) {
|
||||
defaultFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs {
|
||||
defaultFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs {
|
||||
fs := afero.NewMemMapFs()
|
||||
fileHandler := file.NewHandler(fs)
|
||||
for _, f := range existingFiles {
|
||||
require.NoError(fileHandler.Write(f, []byte{1, 2, 3}, file.OptNone))
|
||||
}
|
||||
for _, d := range existingDirs {
|
||||
require.NoError(fs.MkdirAll(d, 0o755))
|
||||
}
|
||||
return fs
|
||||
}
|
||||
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs {
|
||||
readOnlyFs := func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs {
|
||||
fs := afero.NewReadOnlyFs(afero.NewMemMapFs())
|
||||
return fs
|
||||
}
|
||||
|
@ -539,7 +571,7 @@ func TestIAMCreateGCP(t *testing.T) {
|
|||
}
|
||||
|
||||
testCases := map[string]struct {
|
||||
setupFs func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string) afero.Fs
|
||||
setupFs func(require *require.Assertions, provider cloudprovider.Provider, existingFiles []string, existingDirs []string) afero.Fs
|
||||
creator *stubIAMCreator
|
||||
provider cloudprovider.Provider
|
||||
zoneFlag string
|
||||
|
@ -549,6 +581,7 @@ func TestIAMCreateGCP(t *testing.T) {
|
|||
generateConfigFlag bool
|
||||
configFlag string
|
||||
existingFiles []string
|
||||
existingDirs []string
|
||||
stdin string
|
||||
wantAbort bool
|
||||
wantErr bool
|
||||
|
@ -610,6 +643,18 @@ func TestIAMCreateGCP(t *testing.T) {
|
|||
yesFlag: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"iam create gcp existing terraform dir": {
|
||||
setupFs: defaultFs,
|
||||
creator: &stubIAMCreator{id: validIAMIDFile},
|
||||
provider: cloudprovider.GCP,
|
||||
zoneFlag: "europe-west1-a",
|
||||
serviceAccountIDFlag: "constell-test",
|
||||
projectIDFlag: "constell-1234",
|
||||
|
||||
existingDirs: []string{constants.TerraformIAMWorkingDir},
|
||||
yesFlag: true,
|
||||
wantErr: true,
|
||||
},
|
||||
"iam create gcp invalid flags": {
|
||||
setupFs: defaultFs,
|
||||
creator: &stubIAMCreator{id: validIAMIDFile},
|
||||
|
@ -718,7 +763,7 @@ func TestIAMCreateGCP(t *testing.T) {
|
|||
require.NoError(cmd.Flags().Set("config", tc.configFlag))
|
||||
}
|
||||
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider, tc.existingFiles))
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider, tc.existingFiles, tc.existingDirs))
|
||||
|
||||
iamCreator := &iamCreator{
|
||||
cmd: cmd,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue