@@ -6,6 +6,7 @@ package e2etest
66import (
77 "fmt"
88 "os"
9+ "path"
910 "path/filepath"
1011 "strings"
1112 "testing"
@@ -30,6 +31,7 @@ func TestPrimary_stateStore_workspaceCmd(t *testing.T) {
3031 t .Parallel ()
3132
3233 tf := e2e .NewBinary (t , terraformBin , "testdata/full-workflow-with-state-store-fs" )
34+ workspaceDirName := "states" // see test fixture value for workspace_dir
3335
3436 // In order to test integration with PSS we need a provider plugin implementing a state store.
3537 // Here will build the simple6 (built with protocol v6) provider, which implements PSS.
@@ -52,25 +54,37 @@ func TestPrimary_stateStore_workspaceCmd(t *testing.T) {
5254 if err != nil {
5355 t .Fatalf ("unexpected error: %s\n stderr:\n %s" , err , stderr )
5456 }
57+ fi , err := os .Stat (path .Join (tf .WorkDir (), workspaceDirName , "default" , "terraform.tfstate" ))
58+ if err != nil {
59+ t .Fatalf ("failed to open default workspace's state file: %s" , err )
60+ }
61+ if fi .Size () == 0 {
62+ t .Fatal ("default workspace's state file should not have size 0 bytes" )
63+ }
5564
5665 //// Create Workspace
5766 newWorkspace := "foobar"
5867 stdout , stderr , err := tf .Run ("workspace" , "new" , newWorkspace , "-no-color" )
5968 if err != nil {
6069 t .Fatalf ("unexpected error: %s\n stderr:\n %s" , err , stderr )
6170 }
62-
6371 expectedMsg := fmt .Sprintf ("Created and switched to workspace %q!" , newWorkspace )
6472 if ! strings .Contains (stdout , expectedMsg ) {
6573 t .Errorf ("unexpected output, expected %q, but got:\n %s" , expectedMsg , stdout )
6674 }
75+ fi , err = os .Stat (path .Join (tf .WorkDir (), workspaceDirName , newWorkspace , "terraform.tfstate" ))
76+ if err != nil {
77+ t .Fatalf ("failed to open %s workspace's state file: %s" , newWorkspace , err )
78+ }
79+ if fi .Size () == 0 {
80+ t .Fatalf ("%s workspace's state file should not have size 0 bytes" , newWorkspace )
81+ }
6782
6883 //// List Workspaces
6984 stdout , stderr , err = tf .Run ("workspace" , "list" , "-no-color" )
7085 if err != nil {
7186 t .Fatalf ("unexpected error: %s\n stderr:\n %s" , err , stderr )
7287 }
73-
7488 if ! strings .Contains (stdout , newWorkspace ) {
7589 t .Errorf ("unexpected output, expected the new %q workspace to be listed present, but it's missing. Got:\n %s" , newWorkspace , stdout )
7690 }
@@ -81,7 +95,6 @@ func TestPrimary_stateStore_workspaceCmd(t *testing.T) {
8195 if err != nil {
8296 t .Fatalf ("unexpected error: %s\n stderr:\n %s" , err , stderr )
8397 }
84-
8598 expectedMsg = fmt .Sprintf ("Switched to workspace %q." , selectedWorkspace )
8699 if ! strings .Contains (stdout , expectedMsg ) {
87100 t .Errorf ("unexpected output, expected %q, but got:\n %s" , expectedMsg , stdout )
0 commit comments