From 9dec98fbbaa5bdd99f142c8cdd4fb81ec6daadd8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Feb 2022 10:21:41 +0800 Subject: [PATCH] Fix: add unit test for getting Terraform Configuration from remote git (#3194) Add another unit test when the configuration of Terraform locates in a subpath of a git remote repository Signed-off-by: Zheng Xi Zhou (cherry picked from commit bef07e9a0891c5183471f04f8850fda0d3548ff8) Co-authored-by: Zheng Xi Zhou --- pkg/controller/utils/capability_test.go | 35 ++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/controller/utils/capability_test.go b/pkg/controller/utils/capability_test.go index 4d8a2cc13..25276deb2 100644 --- a/pkg/controller/utils/capability_test.go +++ b/pkg/controller/utils/capability_test.go @@ -423,6 +423,34 @@ variable "aaa" { config = string })) default = [] +}`, + }, + }, + "configuration is remote with path": { + args: args{ + name: "aws-subnet", + url: "https://github.com/kubevela-contrib/terraform-modules.git", + path: "aws/subnet", + data: []byte(` +variable "aaa" { + type = list(object({ + type = string + sourceArn = string + config = string + })) + default = [] +}`), + variableFile: "variables.tf", + }, + want: want{ + config: ` +variable "aaa" { + type = list(object({ + type = string + sourceArn = string + config = string + })) + default = [] }`, }, }, @@ -454,7 +482,12 @@ variable "aaa" { } patch := ApplyFunc(git.PlainCloneContext, func(ctx context.Context, path string, isBare bool, o *git.CloneOptions) (*git.Repository, error) { - tmpPath := filepath.Join("./tmp/terraform", tc.args.name) + var tmpPath string + if tc.args.path != "" { + tmpPath = filepath.Join("./tmp/terraform", tc.args.name, tc.args.path) + } else { + tmpPath = filepath.Join("./tmp/terraform", tc.args.name) + } err := os.MkdirAll(tmpPath, os.ModePerm) assert.NilError(t, err) err = ioutil.WriteFile(filepath.Clean(filepath.Join(tmpPath, tc.args.variableFile)), tc.args.data, 0644)