Skip to content

Commit be896a0

Browse files
committed
Update tests and mock; this is unblocked now Get and Put are implemented
1 parent ac65f60 commit be896a0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

internal/command/meta_backend_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,11 +2205,13 @@ func TestMetaBackend_configureNewStateStore(t *testing.T) {
22052205
}
22062206
if len(w) > 0 {
22072207
if tc.expectDefaultWorkspaceExists {
2208-
if len(w) == 1 && w[0] != "default" {
2209-
t.Fatalf("expected the default workspace to exist, but instead got: %v", w)
2208+
if len(w) != 1 || w[0] != "default" {
2209+
t.Fatalf("expected only the default workspace to exist, but instead got: %v", w)
22102210
}
2211+
return // we've got the expected default workspace
22112212
}
2212-
t.Fatalf("expected the default workspace to be the only existing workspace, but instead got: %v", w)
2213+
2214+
t.Fatalf("got unexpected workspaces: %v", w)
22132215
}
22142216
})
22152217
}

internal/providers/testing/provider_mock.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ type MockProvider struct {
159159
WriteStateBytesFn func(providers.WriteStateBytesRequest) providers.WriteStateBytesResponse
160160
WriteStateBytesResponse providers.WriteStateBytesResponse
161161

162-
// states is an internal field that tracks which workspaces have been created in a test
163-
states map[string]interface{}
162+
// MockStates is an internal field that tracks which workspaces have been created in a test
163+
// The map keys are state ids (workspaces) and the value depends on the test.
164+
MockStates map[string]interface{}
164165

165166
GetStatesCalled bool
166167
GetStatesResponse *providers.GetStatesResponse
@@ -1039,7 +1040,7 @@ func (p *MockProvider) GetStates(r providers.GetStatesRequest) (resp providers.G
10391040
}
10401041

10411042
// If the mock has no further inputs, return the internal states list
1042-
resp.States = slices.Sorted(maps.Keys(p.states))
1043+
resp.States = slices.Sorted(maps.Keys(p.MockStates))
10431044

10441045
return resp
10451046
}
@@ -1066,8 +1067,8 @@ func (p *MockProvider) DeleteState(r providers.DeleteStateRequest) (resp provide
10661067
return p.DeleteStateFn(r)
10671068
}
10681069

1069-
if _, match := p.states[r.StateId]; match {
1070-
delete(p.states, r.StateId)
1070+
if _, match := p.MockStates[r.StateId]; match {
1071+
delete(p.MockStates, r.StateId)
10711072
} else {
10721073
resp.Diagnostics.Append(&hcl.Diagnostic{
10731074
Severity: hcl.DiagError,

0 commit comments

Comments
 (0)