Skip to content

Commit

Permalink
separate setup for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Jul 3, 2024
1 parent d8395ff commit 9d05430
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions pkg/tfbridge/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,15 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs,

for _, s := range setup {
t.Run(s.name, func(t *testing.T) {
sch, r, provider, info := s.setup(tfs)

tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
makeTerraformStateOptions{defaultZeroSchemaVersion: true})
assert.NoError(t, err)
t.Run("standard", func(t *testing.T) {
sch, r, provider, info := s.setup(tfs)

config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info)
assert.NoError(t, err)
tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
makeTerraformStateOptions{defaultZeroSchemaVersion: true})
assert.NoError(t, err)

t.Run("standard", func(t *testing.T) {
config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info)
assert.NoError(t, err)
tfDiff, err := provider.Diff(ctx, "resource", tfState, config, shim.DiffOptions{
IgnoreChanges: newIgnoreChanges(ctx, sch, info, stateMap, inputsMap, ignoreChanges),
})
Expand All @@ -314,17 +313,17 @@ func diffTest(t *testing.T, tfs map[string]*v2Schema.Schema, inputs,

for _, s := range setup {
t.Run(s.name, func(t *testing.T) {
sch, r, provider, info := s.setup(tfs)

tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
makeTerraformStateOptions{defaultZeroSchemaVersion: true})
assert.NoError(t, err)

config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info)
assert.NoError(t, err)
// Add an ignoreChanges entry for each path in the expected diff, then re-convert the diff
// and check the result.
t.Run("withIgnoreAllExpected", func(t *testing.T) {
sch, r, provider, info := s.setup(tfs)
tfState, err := makeTerraformStateWithOpts(ctx, r, "id", stateMap,
makeTerraformStateOptions{defaultZeroSchemaVersion: true})
assert.NoError(t, err)

config, _, err := MakeTerraformConfig(ctx, &Provider{tf: provider}, inputsMap, sch, info)
assert.NoError(t, err)

for k := range expected {
ignoreChanges = append(ignoreChanges, k)
}
Expand Down

0 comments on commit 9d05430

Please sign in to comment.