From db71ef910ef673ac6f96f7e13163a4c427b91ff7 Mon Sep 17 00:00:00 2001 From: Kenta Kozuka Date: Tue, 24 Oct 2023 11:45:54 +0900 Subject: [PATCH] Add tests to terraform platform provider Signed-off-by: Kenta Kozuka --- .../terraform/terraform_test.go | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pkg/app/piped/platformprovider/terraform/terraform_test.go b/pkg/app/piped/platformprovider/terraform/terraform_test.go index c09e7e6e7e..873dbb02bc 100644 --- a/pkg/app/piped/platformprovider/terraform/terraform_test.go +++ b/pkg/app/piped/platformprovider/terraform/terraform_test.go @@ -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) + }) + } +}