From 9d054302a1e72c158fbdad3bb427d49c7d5d47a7 Mon Sep 17 00:00:00 2001 From: Venelin Date: Wed, 3 Jul 2024 12:46:59 +0100 Subject: [PATCH] separate setup for each test --- pkg/tfbridge/diff_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/tfbridge/diff_test.go b/pkg/tfbridge/diff_test.go index 896d2dc02..d5251ab0d 100644 --- a/pkg/tfbridge/diff_test.go +++ b/pkg/tfbridge/diff_test.go @@ -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), }) @@ -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) }