@@ -3238,7 +3238,7 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
32383238 testCopyDir (t , testFixturePath ("init-with-state-store" ), td )
32393239 t .Chdir (td )
32403240
3241- mockProvider := mockPluggableStateStorageProvider ()
3241+ mockProvider := mockPluggableStateStorageProvider (t )
32423242 mockProviderAddress := addrs .NewDefaultProvider ("test" )
32433243 providerSource , close := newMockProviderSource (t , map [string ][]string {
32443244 // The test fixture config has no version constraints, so the latest version will
@@ -3325,7 +3325,7 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
33253325 testCopyDir (t , testFixturePath ("init-with-state-store" ), td )
33263326 t .Chdir (td )
33273327
3328- mockProvider := mockPluggableStateStorageProvider ()
3328+ mockProvider := mockPluggableStateStorageProvider (t )
33293329 mockProviderAddress := addrs .NewDefaultProvider ("test" )
33303330 providerSource , close := newMockProviderSource (t , map [string ][]string {
33313331 "hashicorp/test" : {"1.0.0" },
@@ -3374,7 +3374,7 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
33743374 testCopyDir (t , testFixturePath ("init-with-state-store" ), td )
33753375 t .Chdir (td )
33763376
3377- mockProvider := mockPluggableStateStorageProvider ()
3377+ mockProvider := mockPluggableStateStorageProvider (t )
33783378 mockProviderAddress := addrs .NewDefaultProvider ("test" )
33793379 providerSource , close := newMockProviderSource (t , map [string ][]string {
33803380 "hashicorp/test" : {"1.0.0" },
@@ -3429,7 +3429,7 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
34293429 customWorkspace := "my-custom-workspace"
34303430 t .Setenv (WorkspaceNameEnvVar , customWorkspace )
34313431
3432- mockProvider := mockPluggableStateStorageProvider ()
3432+ mockProvider := mockPluggableStateStorageProvider (t )
34333433 mockProviderAddress := addrs .NewDefaultProvider ("test" )
34343434 providerSource , close := newMockProviderSource (t , map [string ][]string {
34353435 "hashicorp/test" : {"1.0.0" },
@@ -3492,7 +3492,7 @@ func TestInit_stateStore_newWorkingDir(t *testing.T) {
34923492 testCopyDir (t , testFixturePath ("init-with-state-store" ), td )
34933493 t .Chdir (td )
34943494
3495- mockProvider := mockPluggableStateStorageProvider ()
3495+ mockProvider := mockPluggableStateStorageProvider (t )
34963496 mockProvider .GetStatesResponse = & providers.GetStatesResponse {
34973497 States : []string {
34983498 "foobar1" ,
@@ -3583,7 +3583,7 @@ func TestInit_stateStore_configUnchanged(t *testing.T) {
35833583 testCopyDir (t , testFixturePath ("state-store-unchanged" ), td )
35843584 t .Chdir (td )
35853585
3586- mockProvider := mockPluggableStateStorageProvider ()
3586+ mockProvider := mockPluggableStateStorageProvider (t )
35873587 // If the working directory was previously initialized successfully then at least
35883588 // one workspace is guaranteed to exist when a user is re-running init with no config
35893589 // changes since last init. So this test says `default` exists.
@@ -3670,7 +3670,7 @@ func TestInit_stateStore_configChanges(t *testing.T) {
36703670 testCopyDir (t , testFixturePath ("state-store-changed/store-config" ), td )
36713671 t .Chdir (td )
36723672
3673- mockProvider := mockPluggableStateStorageProvider ()
3673+ mockProvider := mockPluggableStateStorageProvider (t )
36743674
36753675 // The previous init implied by this test scenario would have created this.
36763676 mockProvider .GetStatesResponse = & providers.GetStatesResponse {States : []string {"default" }}
@@ -3758,7 +3758,7 @@ func TestInit_stateStore_configChanges(t *testing.T) {
37583758 testCopyDir (t , testFixturePath ("state-store-changed/store-config" ), td )
37593759 t .Chdir (td )
37603760
3761- mockProvider := mockPluggableStateStorageProvider ()
3761+ mockProvider := mockPluggableStateStorageProvider (t )
37623762 mockProvider .GetStatesResponse = & providers.GetStatesResponse {States : []string {"default" }} // The previous init implied by this test scenario would have created the default workspace.
37633763 mockProviderAddress := addrs .NewDefaultProvider ("test" )
37643764 providerSource , close := newMockProviderSource (t , map [string ][]string {
@@ -3808,7 +3808,7 @@ func TestInit_stateStore_configChanges(t *testing.T) {
38083808 testCopyDir (t , testFixturePath ("state-store-changed/provider-config" ), td )
38093809 t .Chdir (td )
38103810
3811- mockProvider := mockPluggableStateStorageProvider ()
3811+ mockProvider := mockPluggableStateStorageProvider (t )
38123812 mockProvider .GetStatesResponse = & providers.GetStatesResponse {States : []string {"default" }} // The previous init implied by this test scenario would have created the default workspace.
38133813 mockProviderAddress := addrs .NewDefaultProvider ("test" )
38143814 providerSource , close := newMockProviderSource (t , map [string ][]string {
@@ -3857,7 +3857,7 @@ func TestInit_stateStore_configChanges(t *testing.T) {
38573857 testCopyDir (t , testFixturePath ("state-store-changed/state-store-type" ), td )
38583858 t .Chdir (td )
38593859
3860- mockProvider := mockPluggableStateStorageProvider ()
3860+ mockProvider := mockPluggableStateStorageProvider (t )
38613861 storeName := "test_store"
38623862 otherStoreName := "test_otherstore"
38633863 // Make the provider report that it contains a 2nd storage implementation with the above name
@@ -3909,11 +3909,11 @@ func TestInit_stateStore_configChanges(t *testing.T) {
39093909 testCopyDir (t , testFixturePath ("state-store-changed/provider-used" ), td )
39103910 t .Chdir (td )
39113911
3912- mockProvider := mockPluggableStateStorageProvider ()
3912+ mockProvider := mockPluggableStateStorageProvider (t )
39133913 mockProvider .GetStatesResponse = & providers.GetStatesResponse {States : []string {"default" }} // The previous init implied by this test scenario would have created the default workspace.
39143914
39153915 // Make a mock that implies its name is test2 based on returned schemas
3916- mockProvider2 := mockPluggableStateStorageProvider ()
3916+ mockProvider2 := mockPluggableStateStorageProvider (t )
39173917 mockProvider2 .GetProviderSchemaResponse .StateStores ["test2_store" ] = mockProvider .GetProviderSchemaResponse .StateStores ["test_store" ]
39183918 delete (mockProvider2 .GetProviderSchemaResponse .StateStores , "test_store" )
39193919
@@ -3974,7 +3974,7 @@ func TestInit_stateStore_providerUpgrade(t *testing.T) {
39743974 testCopyDir (t , testFixturePath ("state-store-changed/provider-upgraded" ), td )
39753975 t .Chdir (td )
39763976
3977- mockProvider := mockPluggableStateStorageProvider ()
3977+ mockProvider := mockPluggableStateStorageProvider (t )
39783978 mockProviderAddress := addrs .NewDefaultProvider ("test" )
39793979 providerSource , close := newMockProviderSource (t , map [string ][]string {
39803980 "hashicorp/test" : {"1.2.3" , "9.9.9" }, // 1.2.3 is the version used in the backend state file, 9.9.9 is the version being upgraded to
@@ -4023,7 +4023,7 @@ func TestInit_stateStore_unset(t *testing.T) {
40234023 testCopyDir (t , testFixturePath ("init-state-store" ), td )
40244024 t .Chdir (td )
40254025
4026- mockProvider := mockPluggableStateStorageProvider ()
4026+ mockProvider := mockPluggableStateStorageProvider (t )
40274027 storeName := "test_store"
40284028 otherStoreName := "test_otherstore"
40294029 // Make the provider report that it contains a 2nd storage implementation with the above name
@@ -4121,7 +4121,7 @@ func TestInit_stateStore_unset_withoutProviderRequirements(t *testing.T) {
41214121 testCopyDir (t , testFixturePath ("init-state-store" ), td )
41224122 t .Chdir (td )
41234123
4124- mockProvider := mockPluggableStateStorageProvider ()
4124+ mockProvider := mockPluggableStateStorageProvider (t )
41254125 storeName := "test_store"
41264126 otherStoreName := "test_otherstore"
41274127 // Make the provider report that it contains a 2nd storage implementation with the above name
@@ -4355,7 +4355,7 @@ func expectedPackageInstallPath(name, version string, exe bool) string {
43554355 ))
43564356}
43574357
4358- func mockPluggableStateStorageProvider () * testing_provider.MockProvider {
4358+ func mockPluggableStateStorageProvider (t * testing. T ) * testing_provider.MockProvider {
43594359 // Create a mock provider to use for PSS
43604360 // Get mock provider factory to be used during init
43614361 //
@@ -4412,9 +4412,16 @@ func mockPluggableStateStorageProvider() *testing_provider.MockProvider {
44124412 mock .ReadStateBytesFn = func (req providers.ReadStateBytesRequest ) providers.ReadStateBytesResponse {
44134413 state := []byte {}
44144414 if v , exist := mock .MockStates [req .StateId ]; exist {
4415- if s , ok := v .([]byte ); ok {
4415+ s , ok := v .([]byte )
4416+ if ok {
44164417 state = s
4418+ } else {
4419+ // Test setup is incorrect if this happens
4420+ t .Fatalf ("mock provider is set up to return state bytes from the MockStates map, but the mock encountered a value that wasn't a slice of bytes: %#v" ,
4421+ mock .MockStates ,
4422+ )
44174423 }
4424+
44184425 }
44194426 return providers.ReadStateBytesResponse {
44204427 Bytes : state ,
0 commit comments