ignore output changes for upgrade test
This commit is contained in:
Родитель
525a61c203
Коммит
ba43cf4106
|
@ -0,0 +1,14 @@
|
|||
output "id" {
|
||||
value = 1
|
||||
}
|
||||
|
||||
output "name" {
|
||||
value = "John Doe"
|
||||
}
|
||||
|
||||
output "complete" {
|
||||
value = {
|
||||
id = 1
|
||||
name = "John Doe"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
output "id" {
|
||||
value = 1
|
||||
}
|
||||
|
||||
output "complete" {
|
||||
value = {
|
||||
id = 1
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
module "test" {
|
||||
source = "../before/"
|
||||
}
|
||||
|
||||
output "complete" {
|
||||
value = module.test.complete
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module "test" {
|
||||
source = "{{env "MODULE_SOURCE" | default "../before/"}}"
|
||||
}
|
|
@ -3,7 +3,6 @@ package terraform_module_test_helper
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gruntwork-io/terratest/modules/files"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -14,6 +13,7 @@ import (
|
|||
"github.com/Masterminds/sprig"
|
||||
"github.com/ahmetb/go-linq/v3"
|
||||
"github.com/google/go-github/v42/github"
|
||||
"github.com/gruntwork-io/terratest/modules/files"
|
||||
"github.com/gruntwork-io/terratest/modules/terraform"
|
||||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
|
||||
"github.com/hashicorp/go-getter"
|
||||
|
@ -59,7 +59,7 @@ func ModuleUpgradeTest(t *testing.T, owner, repo, moduleFolderRelativeToRoot, cu
|
|||
}
|
||||
}
|
||||
|
||||
func moduleUpgrade(t *testing.T, owner string, repo string, moduleFolderRelativeToRoot string, currentModulePath string, opts terraform.Options, currentMajorVer int) error {
|
||||
func moduleUpgrade(t *testing.T, owner string, repo string, moduleFolderRelativeToRoot string, newModulePath string, opts terraform.Options, currentMajorVer int) error {
|
||||
latestTag, err := getLatestTag(owner, repo, currentMajorVer)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -75,14 +75,22 @@ func moduleUpgrade(t *testing.T, owner string, repo string, moduleFolderRelative
|
|||
if !exists {
|
||||
return SkipError
|
||||
}
|
||||
tmpDir := test_structure.CopyTerraformFolderToTemp(t, tmpDirForTag, moduleFolderRelativeToRoot)
|
||||
opts.TerraformDir = tmpDir
|
||||
defer terraform.Destroy(t, &opts)
|
||||
tmpTestDir := test_structure.CopyTerraformFolderToTemp(t, tmpDirForTag, moduleFolderRelativeToRoot)
|
||||
return diffTwoVersions(t, opts, tmpTestDir, newModulePath)
|
||||
}
|
||||
|
||||
func diffTwoVersions(t *testing.T, opts terraform.Options, originTerraformDir string, newModulePath string) error {
|
||||
opts.TerraformDir = originTerraformDir
|
||||
defer terraform.Destroy(t, &opts)
|
||||
terraform.InitAndApplyAndIdempotent(t, &opts)
|
||||
overrideModuleSourceToCurrentPath(t, tmpDir, currentModulePath)
|
||||
code := terraform.InitAndPlanWithExitCode(t, &opts)
|
||||
if code != 0 {
|
||||
opts.PlanFilePath = filepath.Join(originTerraformDir, "tf.plan")
|
||||
terraform.Plan(t, &opts)
|
||||
overrideModuleSourceToCurrentPath(t, originTerraformDir, newModulePath)
|
||||
|
||||
plan := terraform.InitAndPlanAndShowWithStruct(t, &opts)
|
||||
changes := plan.ResourceChangesMap
|
||||
|
||||
if len(changes) > 0 {
|
||||
return fmt.Errorf("terraform configuration not idempotent:%s", terraform.Plan(t, &opts))
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package terraform_module_test_helper
|
||||
|
||||
import (
|
||||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -113,3 +114,19 @@ func TestNoValidVersion(t *testing.T) {
|
|||
first := latestTagWithinMajorVersion(tags, 0)
|
||||
assert.Nil(t, first)
|
||||
}
|
||||
|
||||
func TestDetectPlanDiff(t *testing.T) {
|
||||
err := moduleUpgrade(t, "lonegunmanb", "terraform-module-test-helper", "example/upgrade", "./", terraform.Options{
|
||||
Upgrade: true,
|
||||
}, 0)
|
||||
assert.NotEqual(t, SkipError, err)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestAddNewOutputShouldNotFailTheTest(t *testing.T) {
|
||||
tmpDir := test_structure.CopyTerraformFolderToTemp(t, "./example/output_upgrade", "test")
|
||||
err := diffTwoVersions(t, terraform.Options{
|
||||
Upgrade: true,
|
||||
}, tmpDir, "../after")
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче