Skip to content

Commit 9bf8b34

Browse files
committed
refactor: Replace use of newMeta with reuse of Meta that we re-set the UI value on
1 parent ae65335 commit 9bf8b34

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

internal/command/workspace_command_test.go

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,28 @@ func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
2929
t.Chdir(td)
3030

3131
mock := testStateStoreMockWithChunkNegotiation(t, 1000)
32-
newMeta := func(provider providers.Interface) (meta Meta, ui *cli.MockUi, close func()) {
33-
// Assumes the mocked provider is hashicorp/test
34-
providerSource, close := newMockProviderSource(t, map[string][]string{
35-
"hashicorp/test": {"1.2.3"},
36-
})
3732

38-
ui = new(cli.MockUi)
39-
view, _ := testView(t)
40-
meta = Meta{
41-
AllowExperimentalFeatures: true,
42-
Ui: ui,
43-
View: view,
44-
testingOverrides: &testingOverrides{
45-
Providers: map[addrs.Provider]providers.Factory{
46-
addrs.NewDefaultProvider("test"): providers.FactoryFixed(mock),
47-
},
33+
// Assumes the mocked provider is hashicorp/test
34+
providerSource, close := newMockProviderSource(t, map[string][]string{
35+
"hashicorp/test": {"1.2.3"},
36+
})
37+
defer close()
38+
39+
ui := new(cli.MockUi)
40+
view, _ := testView(t)
41+
meta := Meta{
42+
AllowExperimentalFeatures: true,
43+
Ui: ui,
44+
View: view,
45+
testingOverrides: &testingOverrides{
46+
Providers: map[addrs.Provider]providers.Factory{
47+
addrs.NewDefaultProvider("test"): providers.FactoryFixed(mock),
4848
},
49-
ProviderSource: providerSource,
50-
}
51-
return meta, ui, close
49+
},
50+
ProviderSource: providerSource,
5251
}
5352

5453
//// Init
55-
meta, ui, close := newMeta(mock)
56-
defer close()
5754
intCmd := &InitCommand{
5855
Meta: meta,
5956
}
@@ -69,9 +66,8 @@ func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
6966

7067
//// Create Workspace
7168
newWorkspace := "foobar"
72-
73-
meta, ui, close = newMeta(mock)
74-
defer close()
69+
ui = new(cli.MockUi)
70+
meta.Ui = ui
7571
newCmd := &WorkspaceNewCommand{
7672
Meta: meta,
7773
}
@@ -100,8 +96,8 @@ func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
10096
}
10197

10298
//// List Workspaces
103-
meta, ui, close = newMeta(mock)
104-
defer close()
99+
ui = new(cli.MockUi)
100+
meta.Ui = ui
105101
listCmd := &WorkspaceListCommand{
106102
Meta: meta,
107103
}
@@ -115,8 +111,8 @@ func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
115111
}
116112

117113
//// Select Workspace
118-
meta, ui, close = newMeta(mock)
119-
defer close()
114+
ui = new(cli.MockUi)
115+
meta.Ui = ui
120116
selCmd := &WorkspaceSelectCommand{
121117
Meta: meta,
122118
}
@@ -132,8 +128,8 @@ func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
132128
}
133129

134130
//// Show Workspace
135-
meta, ui, close = newMeta(mock)
136-
defer close()
131+
ui = new(cli.MockUi)
132+
meta.Ui = ui
137133
showCmd := &WorkspaceShowCommand{
138134
Meta: meta,
139135
}
@@ -153,8 +149,8 @@ func TestWorkspace_allCommands_pluggableStateStore(t *testing.T) {
153149
}
154150

155151
//// Delete Workspace
156-
meta, ui, close = newMeta(mock)
157-
defer close()
152+
ui = new(cli.MockUi)
153+
meta.Ui = ui
158154
deleteCmd := &WorkspaceDeleteCommand{
159155
Meta: meta,
160156
}

0 commit comments

Comments
 (0)