Skip to content

Commit

Permalink
Use dummy state for testing to clarify not depending on contents
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Jul 23, 2020
1 parent 5e72ab3 commit e5b3dc0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 306 deletions.
10 changes: 1 addition & 9 deletions tfexec/terraform_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import (
)

func TestTerraformCLIPlan(t *testing.T) {
state := NewState([]byte(`{
"version": 4,
"terraform_version": "0.12.28",
"serial": 0,
"lineage": "3d2cf549-8051-c117-aaa7-f93cda2674e8",
"outputs": {},
"resources": []
}
`))
state := NewState([]byte("dummy state"))

// mock writing plan to a temporary file.
plan := NewPlan([]byte("dummy plan"))
Expand Down
94 changes: 1 addition & 93 deletions tfexec/terraform_state_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestTerraformCLIStateList(t *testing.T) {
state := NewState([]byte(testStateListState))
state := NewState([]byte("dummy state"))
stdout := `aws_security_group.bar
aws_security_group.foo
`
Expand Down Expand Up @@ -140,95 +140,3 @@ aws_security_group.foo
})
}
}

const testStateListState = `
{
"version": 4,
"terraform_version": "0.12.28",
"serial": 1,
"lineage": "a19299f0-68d7-3763-56ca-15ae05f60684",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_security_group",
"name": "bar",
"provider": "provider.aws",
"instances": [
{
"schema_version": 1,
"attributes": {
"arn": "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-ecde6356",
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "",
"from_port": 0,
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"protocol": "-1",
"security_groups": [],
"self": false,
"to_port": 0
}
],
"id": "sg-ecde6356",
"ingress": [],
"name": "bar",
"name_prefix": null,
"owner_id": "000000000000",
"revoke_rules_on_delete": false,
"tags": null,
"timeouts": null,
"vpc_id": ""
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0="
}
]
},
{
"mode": "managed",
"type": "aws_security_group",
"name": "foo",
"provider": "provider.aws",
"instances": [
{
"schema_version": 1,
"attributes": {
"arn": "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-d1ff4d60",
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "",
"from_port": 0,
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"protocol": "-1",
"security_groups": [],
"self": false,
"to_port": 0
}
],
"id": "sg-d1ff4d60",
"ingress": [],
"name": "foo",
"name_prefix": null,
"owner_id": "000000000000",
"revoke_rules_on_delete": false,
"tags": {},
"timeouts": null,
"vpc_id": ""
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0="
}
]
}
]
}
`
188 changes: 2 additions & 186 deletions tfexec/terraform_state_mv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func TestTerraformCLIStateMv(t *testing.T) {
state := NewState([]byte(testStateMvState))
stateOut := NewState([]byte(testStateMvStateOut))
state := NewState([]byte("dummy state"))
stateOut := NewState([]byte("dummy state out"))

// mock writing state to a temporary file.
runFunc := func(args ...string) error {
Expand Down Expand Up @@ -154,187 +154,3 @@ func TestTerraformCLIStateMv(t *testing.T) {
})
}
}

const testStateMvState = `
{
"version": 4,
"terraform_version": "0.12.28",
"serial": 1,
"lineage": "a19299f0-68d7-3763-56ca-15ae05f60684",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_security_group",
"name": "bar",
"provider": "provider.aws",
"instances": [
{
"schema_version": 1,
"attributes": {
"arn": "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-ecde6356",
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "",
"from_port": 0,
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"protocol": "-1",
"security_groups": [],
"self": false,
"to_port": 0
}
],
"id": "sg-ecde6356",
"ingress": [],
"name": "bar",
"name_prefix": null,
"owner_id": "000000000000",
"revoke_rules_on_delete": false,
"tags": null,
"timeouts": null,
"vpc_id": ""
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0="
}
]
},
{
"mode": "managed",
"type": "aws_security_group",
"name": "foo",
"provider": "provider.aws",
"instances": [
{
"schema_version": 1,
"attributes": {
"arn": "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-d1ff4d60",
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "",
"from_port": 0,
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"protocol": "-1",
"security_groups": [],
"self": false,
"to_port": 0
}
],
"id": "sg-d1ff4d60",
"ingress": [],
"name": "foo",
"name_prefix": null,
"owner_id": "000000000000",
"revoke_rules_on_delete": false,
"tags": {},
"timeouts": null,
"vpc_id": ""
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0="
}
]
}
]
}
`

const testStateMvStateOut = `
{
"version": 4,
"terraform_version": "0.12.28",
"serial": 2,
"lineage": "a19299f0-68d7-3763-56ca-15ae05f60684",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_security_group",
"name": "bar",
"provider": "provider.aws",
"instances": [
{
"schema_version": 1,
"attributes": {
"arn": "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-ecde6356",
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "",
"from_port": 0,
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"protocol": "-1",
"security_groups": [],
"self": false,
"to_port": 0
}
],
"id": "sg-ecde6356",
"ingress": [],
"name": "bar",
"name_prefix": null,
"owner_id": "000000000000",
"revoke_rules_on_delete": false,
"tags": null,
"timeouts": null,
"vpc_id": ""
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0="
}
]
},
{
"mode": "managed",
"type": "aws_security_group",
"name": "baz",
"provider": "provider.aws",
"instances": [
{
"schema_version": 1,
"attributes": {
"arn": "arn:aws:ec2:ap-northeast-1:000000000000:security-group/sg-d1ff4d60",
"description": "Managed by Terraform",
"egress": [
{
"cidr_blocks": [
"0.0.0.0/0"
],
"description": "",
"from_port": 0,
"ipv6_cidr_blocks": [],
"prefix_list_ids": [],
"protocol": "-1",
"security_groups": [],
"self": false,
"to_port": 0
}
],
"id": "sg-d1ff4d60",
"ingress": [],
"name": "foo",
"name_prefix": null,
"owner_id": "000000000000",
"revoke_rules_on_delete": false,
"tags": {},
"timeouts": null,
"vpc_id": ""
},
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0="
}
]
}
]
}
`
10 changes: 1 addition & 9 deletions tfexec/terraform_state_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ import (
)

func TestTerraformCLIStatePull(t *testing.T) {
stdout := `{
"version": 4,
"terraform_version": "0.12.28",
"serial": 0,
"lineage": "3d2cf549-8051-c117-aaa7-f93cda2674e8",
"outputs": {},
"resources": []
}
`
stdout := "dummy state"
cases := []struct {
desc string
mockCommands []*mockCommand
Expand Down
10 changes: 1 addition & 9 deletions tfexec/terraform_state_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ import (
)

func TestTerraformCLIStatePush(t *testing.T) {
state := NewState([]byte(`{
"version": 4,
"terraform_version": "0.12.28",
"serial": 0,
"lineage": "3d2cf549-8051-c117-aaa7-f93cda2674e8",
"outputs": {},
"resources": []
}
`))
state := NewState([]byte("dummy state"))
cases := []struct {
desc string
mockCommands []*mockCommand
Expand Down

0 comments on commit e5b3dc0

Please sign in to comment.