Skip to content

Commit af8745d

Browse files
committed
test: Update E2E test using PSS with workspace commands to assert state files are created by given commands
1 parent d371f7a commit af8745d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

internal/command/e2etest/pluggable_state_store_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package e2etest
66
import (
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\nstderr:\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\nstderr:\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\nstderr:\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\nstderr:\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)

internal/command/e2etest/testdata/full-workflow-with-state-store-fs/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ terraform {
77

88
state_store "simple6_fs" {
99
provider "simple6" {}
10+
11+
workspace_dir = "states"
1012
}
1113
}
1214

0 commit comments

Comments
 (0)