Skip to content

Commit

Permalink
fix: Reverting to asserts for non error checking assertions (#3341)
Browse files Browse the repository at this point in the history
* fix: Reverting to asserts for non error checking assertions

* fix: Fixing `TestParseTimestamp`

* fix: Fixing `TestParseTerragruntJsonConfigTerraformWithMultipleExtraArguments`

* fix: More `assertd` to `required` fixes

* fix: Formatting
  • Loading branch information
yhakbar authored Aug 13, 2024
1 parent e0c5cbe commit dd602a3
Show file tree
Hide file tree
Showing 42 changed files with 1,169 additions and 1,146 deletions.
6 changes: 3 additions & 3 deletions aws_helper/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ func TestUnmarshalActionResourceList(t *testing.T) {
bucketPolicy, err := UnmarshalPolicy(arraysPolicy)
require.NoError(t, err)
assert.NotNil(t, bucketPolicy)
require.Len(t, bucketPolicy.Statement, 1)
assert.Len(t, bucketPolicy.Statement, 1)
assert.NotNil(t, bucketPolicy.Statement[0].Action)
assert.NotNil(t, bucketPolicy.Statement[0].Resource)

switch actions := bucketPolicy.Statement[0].Action.(type) {
case []interface{}:
require.Len(t, actions, 11)
assert.Len(t, actions, 11)
assert.Contains(t, actions, "s3:ListJobs")
default:
assert.Fail(t, "Expected []string type for Action")
}

switch resource := bucketPolicy.Statement[0].Resource.(type) {
case []interface{}:
require.Len(t, resource, 2)
assert.Len(t, resource, 2)
assert.Contains(t, resource, "arn:aws:s3:*:666:job/*")
default:
assert.Fail(t, "Expected []string type for Resource")
Expand Down
3 changes: 2 additions & 1 deletion cli/commands/scaffold/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gruntwork-io/terragrunt/config"
"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -85,7 +86,7 @@ func TestDefaultTemplateVariables(t *testing.T) {
cfg, err := config.ReadTerragruntConfig(context.Background(), opts, config.DefaultParserOptions(opts))
require.NoError(t, err)
require.NotEmpty(t, cfg.Inputs)
require.Len(t, cfg.Inputs, 1)
assert.Len(t, cfg.Inputs, 1)
_, found := cfg.Inputs["required_var_1"]
require.True(t, found)
require.Equal(t, "git::https://github.com/gruntwork-io/terragrunt.git//test/fixture-inputs?ref=v0.53.8", *cfg.Terraform.Source)
Expand Down
18 changes: 9 additions & 9 deletions cli/commands/terraform/download_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestDownloadTerraformSourceIfNecessaryInvalidTerraformSource(t *testing.T)
require.Error(t, err)
var downloadingTerraformSourceErr DownloadingTerraformSourceErr
ok := errors.As(err, &downloadingTerraformSourceErr)
require.True(t, ok)
assert.True(t, ok)
}

func TestInvalidModulePath(t *testing.T) {
Expand All @@ -276,7 +276,7 @@ func TestInvalidModulePath(t *testing.T) {
require.Error(t, err)
var workingDirNotFound WorkingDirNotFound
ok := errors.As(err, &workingDirNotFound)
require.True(t, ok)
assert.True(t, ok)
}

func TestDownloadInvalidPathToFilePath(t *testing.T) {
Expand All @@ -296,7 +296,7 @@ func TestDownloadInvalidPathToFilePath(t *testing.T) {
require.Error(t, err)
var workingDirNotDir WorkingDirNotDir
ok := errors.As(err, &workingDirNotDir)
require.True(t, ok)
assert.True(t, ok)
}

func TestDownloadTerraformSourceFromLocalFolderWithManifest(t *testing.T) {
Expand Down Expand Up @@ -356,14 +356,14 @@ func TestDownloadTerraformSourceFromLocalFolderWithManifest(t *testing.T) {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
copyFolder(t, testCase.sourceURL, downloadDir)
require.Condition(t, testCase.comp)
assert.Condition(t, testCase.comp)
})

}

}

func testDownloadTerraformSourceIfNecessary(t *testing.T, canonicalUrl string, downloadDir string, sourceUpdate bool, expectedFileContents string, requireInitFile bool) {
func testDownloadTerraformSourceIfNecessary(t *testing.T, canonicalUrl string, downloadDir string, sourceUpdate bool, expectedFileContents string, assertInitFile bool) {
terraformSource, terragruntOptions, terragruntConfig, err := createConfig(t, canonicalUrl, downloadDir, sourceUpdate)

require.NoError(t, err)
Expand All @@ -374,12 +374,12 @@ func testDownloadTerraformSourceIfNecessary(t *testing.T, canonicalUrl string, d
expectedFilePath := util.JoinPath(downloadDir, "main.tf")
if assert.True(t, util.FileExists(expectedFilePath), "For terraform source %v", terraformSource) {
actualFileContents := readFile(t, expectedFilePath)
require.Equal(t, expectedFileContents, actualFileContents, "For terraform source %v", terraformSource)
assert.Equal(t, expectedFileContents, actualFileContents, "For terraform source %v", terraformSource)
}

if requireInitFile {
if assertInitFile {
existsInitFile := util.FileExists(util.JoinPath(terraformSource.WorkingDir, moduleInitRequiredFile))
require.True(t, existsInitFile)
assert.True(t, existsInitFile)
}
}

Expand Down Expand Up @@ -428,7 +428,7 @@ func testAlreadyHaveLatestCode(t *testing.T, canonicalUrl string, downloadDir st

actual, err := alreadyHaveLatestCode(terraformSource, opts)
require.NoError(t, err)
require.Equal(t, expected, actual, "For terraform source %v", terraformSource)
assert.Equal(t, expected, actual, "For terraform source %v", terraformSource)
}

func tmpDir(t *testing.T) string {
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/terraform/version_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func testCheckTerraformVersionMeetsConstraint(t *testing.T, currentVersion strin

err = checkTerraformVersionMeetsConstraint(current, versionConstraint)
if versionMeetsConstraint && err != nil {
require.NoError(t, err, "Expected Terraform version %s to meet constraint %s, but got error: %v", currentVersion, versionConstraint, err)
assert.NoError(t, err, "Expected Terraform version %s to meet constraint %s, but got error: %v", currentVersion, versionConstraint, err)
} else if !versionMeetsConstraint && err == nil {
require.Error(t, err, "Expected Terraform version %s to NOT meet constraint %s, but got back a nil error", currentVersion, versionConstraint)
assert.Error(t, err, "Expected Terraform version %s to NOT meet constraint %s, but got back a nil error", currentVersion, versionConstraint)
}
}

Expand Down
13 changes: 7 additions & 6 deletions codegen/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/gruntwork-io/terragrunt/options"
"github.com/gruntwork-io/terragrunt/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -53,15 +54,15 @@ func TestRemoteStateConfigToTerraformCode(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
output, err := RemoteStateConfigToTerraformCode(testCase.backend, testCase.config)
// validates the first output.
require.True(t, bytes.Contains(output, []byte(testCase.backend)))
require.Equal(t, testCase.expected, output)
assert.True(t, bytes.Contains(output, []byte(testCase.backend)))
assert.Equal(t, testCase.expected, output)
require.NoError(t, err)

// runs the function a few of times again. All the outputs must be
// equal to the first output.
for i := 0; i < 20; i++ {
actual, _ := RemoteStateConfigToTerraformCode(testCase.backend, testCase.config)
require.Equal(t, output, actual)
assert.Equal(t, output, actual)
}
})
}
Expand Down Expand Up @@ -106,15 +107,15 @@ func TestGenerateDisabling(t *testing.T) {

opts, err := options.NewTerragruntOptionsForTest("mock-path-for-test.hcl")
require.NoError(t, err)
require.NotNil(t, opts)
assert.NotNil(t, opts)

err = WriteToFile(opts, "", config)
require.NoError(t, err)

if testCase.disabled {
require.True(t, util.FileNotExists(testCase.path))
assert.True(t, util.FileNotExists(testCase.path))
} else {
require.True(t, util.FileExists(testCase.path))
assert.True(t, util.FileExists(testCase.path))
}
})
}
Expand Down
18 changes: 9 additions & 9 deletions config/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/gruntwork-io/terragrunt/internal/cache"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)

const testCacheName = "TerragruntConfig"
Expand All @@ -15,10 +15,10 @@ func TestTerragruntConfigCacheCreation(t *testing.T) {

cache := cache.NewCache[TerragruntConfig](testCacheName)

require.NotNil(t, cache.Mutex)
require.NotNil(t, cache.Cache)
assert.NotNil(t, cache.Mutex)
assert.NotNil(t, cache.Cache)

require.Empty(t, cache.Cache)
assert.Empty(t, cache.Cache)
}

func TestTerragruntConfigCacheOperation(t *testing.T) {
Expand All @@ -31,8 +31,8 @@ func TestTerragruntConfigCacheOperation(t *testing.T) {

actualResult, found := cache.Get(ctx, testCacheKey)

require.False(t, found)
require.Empty(t, actualResult)
assert.False(t, found)
assert.Empty(t, actualResult)

stubTerragruntConfig := TerragruntConfig{
IsPartial: true, // Any random property will be sufficient
Expand All @@ -41,7 +41,7 @@ func TestTerragruntConfigCacheOperation(t *testing.T) {
cache.Put(ctx, testCacheKey, stubTerragruntConfig)
actualResult, found = cache.Get(ctx, testCacheKey)

require.True(t, found)
require.NotEmpty(t, actualResult)
require.Equal(t, stubTerragruntConfig, actualResult)
assert.True(t, found)
assert.NotEmpty(t, actualResult)
assert.Equal(t, stubTerragruntConfig, actualResult)
}
Loading

0 comments on commit dd602a3

Please sign in to comment.