Skip to content

Commit

Permalink
updated tfenv unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
psihachina committed Sep 22, 2022
1 parent 5c0cbfd commit 7f86ae4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/commands/tfenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ func TestTfenv(t *testing.T) {
env map[string]string
mockS3Client func(m *mocks.MockS3API)
mockSTSClient func(m *mocks.MockSTSAPI)
withECS bool
}{
{
name: "success (only config file)",
args: []string{"gen", "tfenv"},
env: map[string]string{"ENV": "test", "AWS_PROFILE": "test"},
withConfigFile: true,
wantErr: false,
withECS: true,
mockS3Client: func(m *mocks.MockS3API) {
m.EXPECT().HeadBucket(gomock.Any()).Return(nil, nil).AnyTimes()
},
Expand Down Expand Up @@ -90,6 +92,7 @@ root_domain_name = "examples.ize.sh"
m.EXPECT().HeadBucket(gomock.Any()).Return(nil, nil).AnyTimes()
},
mockSTSClient: func(m *mocks.MockSTSAPI) {},
withECS: true,
wantBackend: `provider "aws" {
profile = var.aws_profile
region = var.aws_region
Expand Down Expand Up @@ -132,6 +135,7 @@ root_domain_name = "examples.ize.sh"
mockS3Client: func(m *mocks.MockS3API) {
m.EXPECT().HeadBucket(gomock.Any()).Return(nil, nil).AnyTimes()
},
withECS: true,
mockSTSClient: func(m *mocks.MockSTSAPI) {},
wantBackend: `provider "aws" {
profile = var.aws_profile
Expand Down Expand Up @@ -205,9 +209,7 @@ terraform {
aws_profile = "test"
aws_region = "us-east-1"
ec2_key_pair_name = "test-testnut"
docker_image_tag = "test"
ssh_public_key =
docker_registry = "0.dkr.ecr.us-east-1.amazonaws.com"
namespace = "testnut"
`,
},
Expand Down Expand Up @@ -243,9 +245,7 @@ terraform {
aws_profile = "test"
aws_region = "us-east-1"
ec2_key_pair_name = "test-testnut"
docker_image_tag = "test"
ssh_public_key =
docker_registry = "0.dkr.ecr.us-east-1.amazonaws.com"
namespace = "testnut"
`,
},
Expand Down Expand Up @@ -288,9 +288,7 @@ terraform {
aws_profile = "test"
aws_region = "us-west-2"
ec2_key_pair_name = "test-testnut"
docker_image_tag = "test"
ssh_public_key =
docker_registry = "0.dkr.ecr.us-west-2.amazonaws.com"
namespace = "testnut"
`,
},
Expand Down Expand Up @@ -323,6 +321,16 @@ namespace = "testnut"

if tt.withConfigFile {
setConfigFile(filepath.Join(temp, "ize.toml"), tfenvToml, t)
if tt.withECS {
f, err := os.OpenFile(filepath.Join(temp, "ize.toml"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
panic(err)
}
defer f.Close()
if _, err = f.WriteString("\n\n[ecs.squibby]\ntimeout = 0"); err != nil {
panic(err)
}
}
}

t.Setenv("HOME", temp)
Expand Down

0 comments on commit 7f86ae4

Please sign in to comment.