Skip to content

Commit

Permalink
Add tests to terraform platform provider (#4625)
Browse files Browse the repository at this point in the history
Signed-off-by: Kenta Kozuka <[email protected]>
  • Loading branch information
kentakozuka authored and ffjlabo committed Nov 13, 2023
1 parent d080552 commit 22a396c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/app/piped/platformprovider/terraform/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,57 @@ func TestParsePlanResult(t *testing.T) {
})
}
}

func TestRender(t *testing.T) {
t.Parallel()

testcases := []struct {
name string
expected string
planResult *PlanResult
expectedErr bool
}{
{
name: "success",
planResult: &PlanResult{
Imports: 1,
Adds: 2,
Changes: 3,
Destroys: 4,
PlanOutput: `
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ resource "test-add" "test" {
+ id = (known after apply)
}
- resource "test-del" "test" {
+ id = "foo"
}
Plan: 1 to import, 2 to add, 3 to change, 4 to destroy.
`,
},
expected: ` resource "test-add" "test" {
+ id = (known after apply)
}
resource "test-del" "test" {
+ id = "foo"
}
Plan: 1 to import, 2 to add, 3 to change, 4 to destroy.
`,
expectedErr: false,
},
}

for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actual, err := tc.planResult.Render()
assert.Equal(t, tc.expected, actual)
assert.Equal(t, tc.expectedErr, err != nil)
})
}
}

0 comments on commit 22a396c

Please sign in to comment.