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 <zzxwill@gmail.com>
(cherry picked from commit bef07e9a08)

Co-authored-by: Zheng Xi Zhou <zzxwill@gmail.com>
This commit is contained in:
github-actions[bot]
2022-02-08 10:21:41 +08:00
committed by GitHub
parent 42e7f04267
commit 9dec98fbba

View File

@@ -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)