fix packer error by monkey patch the version output

This commit is contained in:
hezijie 2024-07-02 12:46:11 +08:00 committed by lonegunmanb
parent 0fd2a5d129
commit b56dda974f
2 changed files with 19 additions and 0 deletions

View File

@ -9,10 +9,13 @@ import (
"testing"
helper "github.com/Azure/terraform-module-test-helper"
"github.com/agiledragon/gomonkey/v2"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/packer"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
terratest "github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
)
@ -128,6 +131,21 @@ func test201VmssPackerJumpbox(t *testing.T) {
if tenantId := os.Getenv("ARM_TENANT_ID"); !useMsi && tenantId != "" {
packerVars["tenant_id"] = tenantId
}
patches := gomonkey.ApplyFunc(shell.RunCommandAndGetOutputE, func(t terratest.TestingT, command shell.Command) (string, error) {
output, err := shell.RunCommandAndGetStdOutE(t, command)
if err != nil {
return output, err
}
if len(command.Args) == 1 && command.Args[0] == "-version" {
output = strings.TrimPrefix(output, "Packer ")
output = strings.TrimPrefix(output, "v")
output = strings.Split(output, "\n")[0]
}
return output, nil
})
defer patches.Reset()
_, err := packer.BuildArtifactE(t, &packer.Options{
Template: pkrCfg,
Vars: packerVars,

View File

@ -4,6 +4,7 @@ go 1.19
require (
github.com/Azure/terraform-module-test-helper v0.16.0
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/gruntwork-io/terratest v0.43.9
github.com/stretchr/testify v1.8.4
)