@@ -116,9 +116,9 @@ func TestLocal_useOfPathAttribute(t *testing.T) {
116
116
117
117
// State file at the `path` location doesn't exist yet
118
118
workspace := backend .DefaultStateName
119
- stmgr , err := b .StateMgr (workspace )
120
- if err != nil {
121
- t .Fatalf ("unexpected error returned from StateMgr" )
119
+ stmgr , sDiags := b .StateMgr (workspace )
120
+ if sDiags . HasErrors () {
121
+ t .Fatalf ("unexpected error returned from StateMgr: %s" , sDiags . Err () )
122
122
}
123
123
defaultStatePath := fmt .Sprintf ("%s/%s" , td , path )
124
124
if _ , err := os .Stat (defaultStatePath ); ! strings .Contains (err .Error (), "no such file or directory" ) {
@@ -137,7 +137,7 @@ func TestLocal_useOfPathAttribute(t *testing.T) {
137
137
Value : cty .StringVal ("foobar" ),
138
138
},
139
139
}
140
- err = stmgr .WriteState (s )
140
+ err : = stmgr .WriteState (s )
141
141
if err != nil {
142
142
t .Fatalf ("unexpected error returned from WriteState" )
143
143
}
@@ -150,9 +150,9 @@ func TestLocal_useOfPathAttribute(t *testing.T) {
150
150
// Writing to a non-default workspace's state creates a file
151
151
// that's unaffected by the `path` location
152
152
workspace = "fizzbuzz"
153
- stmgr , err = b .StateMgr (workspace )
154
- if err != nil {
155
- t .Fatalf ("unexpected error returned from StateMgr" )
153
+ stmgr , sDiags = b .StateMgr (workspace )
154
+ if sDiags . HasErrors () {
155
+ t .Fatalf ("unexpected error returned from StateMgr: %s" , sDiags . Err () )
156
156
}
157
157
fizzbuzzStatePath := fmt .Sprintf ("%s/terraform.tfstate.d/%s/terraform.tfstate" , td , workspace )
158
158
err = stmgr .WriteState (s )
@@ -186,17 +186,17 @@ func TestLocal_pathAttributeWrongExtension(t *testing.T) {
186
186
187
187
// Writing to the default workspace's state creates a file
188
188
workspace := backend .DefaultStateName
189
- stmgr , err := b .StateMgr (workspace )
190
- if err != nil {
191
- t .Fatalf ("unexpected error returned from StateMgr" )
189
+ stmgr , sDiags := b .StateMgr (workspace )
190
+ if sDiags . HasErrors () {
191
+ t .Fatalf ("unexpected error returned from StateMgr: %s" , sDiags . Err () )
192
192
}
193
193
s := states .NewState ()
194
194
s .RootOutputValues = map [string ]* states.OutputValue {
195
195
"foobar" : {
196
196
Value : cty .StringVal ("foobar" ),
197
197
},
198
198
}
199
- err = stmgr .WriteState (s )
199
+ err : = stmgr .WriteState (s )
200
200
if err != nil {
201
201
t .Fatalf ("unexpected error returned from WriteState" )
202
202
}
@@ -233,17 +233,17 @@ func TestLocal_useOfWorkspaceDirAttribute(t *testing.T) {
233
233
// Unaffected by the `workspace_dir` location.
234
234
workspace := backend .DefaultStateName
235
235
defaultStatePath := fmt .Sprintf ("%s/terraform.tfstate" , td )
236
- stmgr , err := b .StateMgr (workspace )
237
- if err != nil {
238
- t .Fatalf ("unexpected error returned from StateMgr" )
236
+ stmgr , sDiags := b .StateMgr (workspace )
237
+ if sDiags . HasErrors () {
238
+ t .Fatalf ("unexpected error returned from StateMgr: %s" , sDiags . Err () )
239
239
}
240
240
s := states .NewState ()
241
241
s .RootOutputValues = map [string ]* states.OutputValue {
242
242
"foobar" : {
243
243
Value : cty .StringVal ("foobar" ),
244
244
},
245
245
}
246
- err = stmgr .WriteState (s )
246
+ err : = stmgr .WriteState (s )
247
247
if err != nil {
248
248
t .Fatalf ("unexpected error returned from WriteState" )
249
249
}
@@ -254,9 +254,9 @@ func TestLocal_useOfWorkspaceDirAttribute(t *testing.T) {
254
254
// that's affected by the `workspace_dir` location
255
255
workspace = "fizzbuzz"
256
256
fizzbuzzStatePath := fmt .Sprintf ("%s/%s/%s/terraform.tfstate" , td , workspaceDir , workspace )
257
- stmgr , err = b .StateMgr (workspace )
258
- if err != nil {
259
- t .Fatalf ("unexpected error returned from StateMgr" )
257
+ stmgr , sDiags = b .StateMgr (workspace )
258
+ if sDiags . HasErrors () {
259
+ t .Fatalf ("unexpected error returned from StateMgr: %s" , sDiags . Err () )
260
260
}
261
261
err = stmgr .WriteState (s )
262
262
if err != nil {
@@ -324,8 +324,8 @@ func TestLocal_addAndRemoveStates(t *testing.T) {
324
324
325
325
// Calling StateMgr with a new workspace name creates that workspace's state file.
326
326
expectedA := "test_A"
327
- if _ , err := b .StateMgr (expectedA ); err != nil {
328
- t .Fatal (err )
327
+ if _ , sDiags := b .StateMgr (expectedA ); sDiags . HasErrors () {
328
+ t .Fatal (sDiags )
329
329
}
330
330
331
331
states , wDiags = b .Workspaces ()
@@ -340,8 +340,8 @@ func TestLocal_addAndRemoveStates(t *testing.T) {
340
340
341
341
// Creating another workspace appends it to the list of present workspaces.
342
342
expectedB := "test_B"
343
- if _ , err := b .StateMgr (expectedB ); err != nil {
344
- t .Fatal (err )
343
+ if _ , sDiags := b .StateMgr (expectedB ); sDiags . HasErrors () {
344
+ t .Fatal (sDiags . Err () )
345
345
}
346
346
347
347
states , wDiags = b .Workspaces ()
@@ -626,8 +626,9 @@ func (b *testDelegateBackend) Configure(obj cty.Value) tfdiags.Diagnostics {
626
626
return diags .Append (errTestDelegateConfigure )
627
627
}
628
628
629
- func (b * testDelegateBackend ) StateMgr (name string ) (statemgr.Full , error ) {
630
- return nil , errTestDelegateState
629
+ func (b * testDelegateBackend ) StateMgr (name string ) (statemgr.Full , tfdiags.Diagnostics ) {
630
+ var diags tfdiags.Diagnostics
631
+ return nil , diags .Append (errTestDelegateState )
631
632
}
632
633
633
634
func (b * testDelegateBackend ) Workspaces () ([]string , tfdiags.Diagnostics ) {
@@ -661,8 +662,8 @@ func TestLocal_callsMethodsOnStateBackend(t *testing.T) {
661
662
t .Fatal ("expected errTestDelegateConfigure error, got:" , diags .Err ())
662
663
}
663
664
664
- if _ , err := b .StateMgr ("test" ); err != errTestDelegateState {
665
- t .Fatal ("expected errTestDelegateState, got:" , err )
665
+ if _ , sDiags := b .StateMgr ("test" ); sDiags . Err (). Error () != errTestDelegateState . Error () {
666
+ t .Fatal ("expected errTestDelegateState, got:" , sDiags . Err () )
666
667
}
667
668
668
669
if _ , diags := b .Workspaces (); ! diags .HasErrors () || diags .Err ().Error () != errTestDelegateStates .Error () {
0 commit comments