@@ -116,9 +116,9 @@ func TestLocal_useOfPathAttribute(t *testing.T) {
116116
117117 // State file at the `path` location doesn't exist yet
118118 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 () )
122122 }
123123 defaultStatePath := fmt .Sprintf ("%s/%s" , td , path )
124124 if _ , err := os .Stat (defaultStatePath ); ! strings .Contains (err .Error (), "no such file or directory" ) {
@@ -137,7 +137,7 @@ func TestLocal_useOfPathAttribute(t *testing.T) {
137137 Value : cty .StringVal ("foobar" ),
138138 },
139139 }
140- err = stmgr .WriteState (s )
140+ err : = stmgr .WriteState (s )
141141 if err != nil {
142142 t .Fatalf ("unexpected error returned from WriteState" )
143143 }
@@ -150,9 +150,9 @@ func TestLocal_useOfPathAttribute(t *testing.T) {
150150 // Writing to a non-default workspace's state creates a file
151151 // that's unaffected by the `path` location
152152 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 () )
156156 }
157157 fizzbuzzStatePath := fmt .Sprintf ("%s/terraform.tfstate.d/%s/terraform.tfstate" , td , workspace )
158158 err = stmgr .WriteState (s )
@@ -186,17 +186,17 @@ func TestLocal_pathAttributeWrongExtension(t *testing.T) {
186186
187187 // Writing to the default workspace's state creates a file
188188 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 () )
192192 }
193193 s := states .NewState ()
194194 s .RootOutputValues = map [string ]* states.OutputValue {
195195 "foobar" : {
196196 Value : cty .StringVal ("foobar" ),
197197 },
198198 }
199- err = stmgr .WriteState (s )
199+ err : = stmgr .WriteState (s )
200200 if err != nil {
201201 t .Fatalf ("unexpected error returned from WriteState" )
202202 }
@@ -233,17 +233,17 @@ func TestLocal_useOfWorkspaceDirAttribute(t *testing.T) {
233233 // Unaffected by the `workspace_dir` location.
234234 workspace := backend .DefaultStateName
235235 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 () )
239239 }
240240 s := states .NewState ()
241241 s .RootOutputValues = map [string ]* states.OutputValue {
242242 "foobar" : {
243243 Value : cty .StringVal ("foobar" ),
244244 },
245245 }
246- err = stmgr .WriteState (s )
246+ err : = stmgr .WriteState (s )
247247 if err != nil {
248248 t .Fatalf ("unexpected error returned from WriteState" )
249249 }
@@ -254,9 +254,9 @@ func TestLocal_useOfWorkspaceDirAttribute(t *testing.T) {
254254 // that's affected by the `workspace_dir` location
255255 workspace = "fizzbuzz"
256256 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 () )
260260 }
261261 err = stmgr .WriteState (s )
262262 if err != nil {
@@ -324,8 +324,8 @@ func TestLocal_addAndRemoveStates(t *testing.T) {
324324
325325 // Calling StateMgr with a new workspace name creates that workspace's state file.
326326 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 )
329329 }
330330
331331 states , wDiags = b .Workspaces ()
@@ -340,8 +340,8 @@ func TestLocal_addAndRemoveStates(t *testing.T) {
340340
341341 // Creating another workspace appends it to the list of present workspaces.
342342 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 () )
345345 }
346346
347347 states , wDiags = b .Workspaces ()
@@ -626,8 +626,9 @@ func (b *testDelegateBackend) Configure(obj cty.Value) tfdiags.Diagnostics {
626626 return diags .Append (errTestDelegateConfigure )
627627}
628628
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 )
631632}
632633
633634func (b * testDelegateBackend ) Workspaces () ([]string , tfdiags.Diagnostics ) {
@@ -661,8 +662,8 @@ func TestLocal_callsMethodsOnStateBackend(t *testing.T) {
661662 t .Fatal ("expected errTestDelegateConfigure error, got:" , diags .Err ())
662663 }
663664
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 () )
666667 }
667668
668669 if _ , diags := b .Workspaces (); ! diags .HasErrors () || diags .Err ().Error () != errTestDelegateStates .Error () {
0 commit comments