Skip to content

Commit 8ddc6e7

Browse files
committed
refactor: Update tests using newMockProviderSource to not handle 'close' callback
1 parent c792fe0 commit 8ddc6e7

13 files changed

Lines changed: 119 additions & 235 deletions

internal/command/apply_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,11 @@ output "foobar" {
822822
// Mock provider still needs to be supplied via testingOverrides despite the mock HTTP source
823823
mockProvider := mockPluggableStateStorageProvider()
824824
mockProviderAddress := addrs.NewDefaultProvider("test")
825-
source, close := newMockProviderSource(t, map[string][]string{
825+
source := newMockProviderSource(t, map[string][]string{
826826
// The test fixture config has no version constraints, so the latest version will
827827
// be used; below is the 'latest' version in the test world.
828828
"hashicorp/test": {"1.2.3"},
829829
})
830-
t.Cleanup(close)
831830

832831
ui := new(cli.MockUi)
833832
view, done := testView(t)
@@ -943,10 +942,9 @@ output "foobar" {
943942
mockProvider.GetProviderSchemaResponse = &schema
944943
mockProviderAddress := addrs.NewBuiltInProvider("terraform")
945944

946-
source, close := newMockProviderSource(t, map[string][]string{
945+
source := newMockProviderSource(t, map[string][]string{
947946
"hashicorp/terraform": {"1.2.3"},
948947
})
949-
t.Cleanup(close)
950948

951949
ui := new(cli.MockUi)
952950
view, done := testView(t)

internal/command/autocomplete_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ func TestMetaCompletePredictWorkspaceName(t *testing.T) {
4949
"foobar": true,
5050
}
5151
mockProviderAddress := addrs.NewDefaultProvider("test")
52-
providerSource, close := newMockProviderSource(t, map[string][]string{
52+
providerSource := newMockProviderSource(t, map[string][]string{
5353
"hashicorp/test": {"1.0.0"},
5454
})
55-
defer close()
5655

5756
ui := new(cli.MockUi)
5857
view, _ := testView(t)
@@ -93,10 +92,9 @@ func TestMetaCompletePredictWorkspaceName(t *testing.T) {
9392
// No workspaces exist in the mock
9493
mockProvider.MockStates = map[string]interface{}{}
9594
mockProviderAddress := addrs.NewDefaultProvider("test")
96-
providerSource, close := newMockProviderSource(t, map[string][]string{
95+
providerSource := newMockProviderSource(t, map[string][]string{
9796
"hashicorp/test": {"1.0.0"},
9897
})
99-
defer close()
10098

10199
ui := new(cli.MockUi)
102100
view, _ := testView(t)

internal/command/import_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ func TestImport_remoteState(t *testing.T) {
173173

174174
statePath := "imported.tfstate"
175175

176-
providerSource, close := newMockProviderSource(t, map[string][]string{
177-
"test": []string{"1.2.3"},
176+
providerSource := newMockProviderSource(t, map[string][]string{
177+
"test": {"1.2.3"},
178178
})
179-
defer close()
180179

181180
// init our backend
182181
ui := cli.NewMockUi()
@@ -285,10 +284,9 @@ func TestImport_initializationErrorShouldUnlock(t *testing.T) {
285284

286285
statePath := "imported.tfstate"
287286

288-
providerSource, close := newMockProviderSource(t, map[string][]string{
289-
"test": []string{"1.2.3"},
287+
providerSource := newMockProviderSource(t, map[string][]string{
288+
"test": {"1.2.3"},
290289
})
291-
defer close()
292290

293291
// init our backend
294292
ui := cli.NewMockUi()
@@ -781,10 +779,9 @@ func TestImportModuleVarFile(t *testing.T) {
781779
},
782780
}
783781

784-
providerSource, close := newMockProviderSource(t, map[string][]string{
785-
"test": []string{"1.2.3"},
782+
providerSource := newMockProviderSource(t, map[string][]string{
783+
"test": {"1.2.3"},
786784
})
787-
defer close()
788785

789786
// init to install the module
790787
ui := new(cli.MockUi)
@@ -855,10 +852,9 @@ func TestImportModuleInputVariableEvaluation(t *testing.T) {
855852
},
856853
}
857854

858-
providerSource, close := newMockProviderSource(t, map[string][]string{
855+
providerSource := newMockProviderSource(t, map[string][]string{
859856
"test": {"1.2.3"},
860857
})
861-
defer close()
862858

863859
// init to install the module
864860
ui := new(cli.MockUi)

internal/command/init2_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,9 @@ func TestPlan_dynamicModuleSource(t *testing.T) {
310310
t.Chdir(td)
311311

312312
p := planFixtureProvider()
313-
providerSource, close := newMockProviderSource(t, map[string][]string{
313+
providerSource := newMockProviderSource(t, map[string][]string{
314314
"hashicorp/test": {"1.0.0"},
315315
})
316-
defer close()
317316

318317
args := []string{"-var", "module_name=example"}
319318

@@ -363,10 +362,9 @@ func TestPlan_dynamicModuleSourceMismatch(t *testing.T) {
363362
t.Chdir(td)
364363

365364
p := planFixtureProvider()
366-
providerSource, close := newMockProviderSource(t, map[string][]string{
365+
providerSource := newMockProviderSource(t, map[string][]string{
367366
"hashicorp/test": {"1.0.0"},
368367
})
369-
defer close()
370368
args := []string{"-var", "module_name=example"}
371369

372370
initUi := new(cli.MockUi)
@@ -411,10 +409,9 @@ func TestApply_dynamicModuleSource(t *testing.T) {
411409
t.Chdir(td)
412410

413411
p := planFixtureProvider()
414-
providerSource, close := newMockProviderSource(t, map[string][]string{
412+
providerSource := newMockProviderSource(t, map[string][]string{
415413
"hashicorp/test": {"1.0.0"},
416414
})
417-
defer close()
418415
args := []string{"-var", "module_name=example"}
419416

420417
initUi := new(cli.MockUi)
@@ -463,10 +460,9 @@ func TestApply_dynamicModuleSourceWithDefaultPlanFile(t *testing.T) {
463460
t.Chdir(td)
464461

465462
p := planFixtureProvider()
466-
providerSource, close := newMockProviderSource(t, map[string][]string{
463+
providerSource := newMockProviderSource(t, map[string][]string{
467464
"hashicorp/test": {"1.0.0"},
468465
})
469-
defer close()
470466

471467
initUi := new(cli.MockUi)
472468
initView, initDone := testView(t)
@@ -539,10 +535,9 @@ func TestPlan_dynamicModuleSourceWithCount(t *testing.T) {
539535
t.Chdir(td)
540536

541537
p := planFixtureProvider()
542-
providerSource, close := newMockProviderSource(t, map[string][]string{
538+
providerSource := newMockProviderSource(t, map[string][]string{
543539
"hashicorp/test": {"1.0.0"},
544540
})
545-
defer close()
546541

547542
args := []string{"-var", "module_name=example"}
548543

@@ -592,10 +587,9 @@ func TestPlan_dynamicModuleSourceWithForEach(t *testing.T) {
592587
t.Chdir(td)
593588

594589
p := planFixtureProvider()
595-
providerSource, close := newMockProviderSource(t, map[string][]string{
590+
providerSource := newMockProviderSource(t, map[string][]string{
596591
"hashicorp/test": {"1.0.0"},
597592
})
598-
defer close()
599593

600594
args := []string{"-var", "module_name=example"}
601595

0 commit comments

Comments
 (0)