Skip to content

Commit a9f23ea

Browse files
committed
test: Add a new test that shows PSS cannot be used if the pluggable_state_stores experiment isn't declared in the config.
1 parent 966dfef commit a9f23ea

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

internal/command/experimental_test.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,43 @@ import (
1212

1313
func TestInit_stateStoreBlockIsExperimental(t *testing.T) {
1414

15-
t.Run("init command", func(t *testing.T) {
16-
// Create a temporary working directory with state_store in use
15+
// When experiments are enabled, users are prompted to add experiments = [pluggable_state_stores] to their config.
16+
t.Run("init command without `pluggable_state_stores` experiment in config", func(t *testing.T) {
17+
// Create a temporary working directory with state_store in use but experiment not declared
18+
td := t.TempDir()
19+
testCopyDir(t, testFixturePath("init-with-state-store-no-experiment"), td)
20+
t.Chdir(td)
21+
22+
ui := new(cli.MockUi)
23+
view, done := testView(t)
24+
c := &InitCommand{
25+
Meta: Meta{
26+
Ui: ui,
27+
View: view,
28+
AllowExperimentalFeatures: true,
29+
},
30+
}
31+
32+
args := []string{}
33+
code := c.Run(args)
34+
testOutput := done(t)
35+
if code != 1 {
36+
t.Fatalf("unexpected output: \n%s", testOutput.All())
37+
}
38+
39+
// Check output
40+
output := cleanString(testOutput.Stderr())
41+
if !strings.Contains(output, `Error: Pluggable state store experiment not supported`) {
42+
t.Fatalf("doesn't look like experiment is blocking access': %s", output)
43+
}
44+
if !strings.Contains(output, "opt into the \"pluggable_state_stores\" experiment using the `terraform` block's `experiments` attribute") {
45+
t.Fatalf("expected the error to explain the need for a config change': %s", output)
46+
}
47+
})
48+
49+
// When experiments aren't enabled, the state_store block is reported as being unexpected
50+
t.Run("init command without experiments enabled", func(t *testing.T) {
51+
// Create a temporary working directory with state_store in use but experiment not declared
1752
td := t.TempDir()
1853
testCopyDir(t, testFixturePath("init-with-state-store"), td)
1954
t.Chdir(td)
@@ -42,7 +77,7 @@ func TestInit_stateStoreBlockIsExperimental(t *testing.T) {
4277
}
4378
})
4479

45-
t.Run("non-init command: plan", func(t *testing.T) {
80+
t.Run("non-init command: `plan` without experiments enabled", func(t *testing.T) {
4681
// Create a temporary working directory with state_store in use
4782
td := t.TempDir()
4883
testCopyDir(t, testFixturePath("init-with-state-store"), td)
@@ -72,7 +107,7 @@ func TestInit_stateStoreBlockIsExperimental(t *testing.T) {
72107
}
73108
})
74109

75-
t.Run("non-init command: state list", func(t *testing.T) {
110+
t.Run("non-init command: `state list` without experiments enabled", func(t *testing.T) {
76111
// Create a temporary working directory with state_store in use
77112
td := t.TempDir()
78113
testCopyDir(t, testFixturePath("init-with-state-store"), td)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
# There should be `experiments = [pluggable_state_stores]` present here, but it is intentionally missing.
3+
required_providers {
4+
test = {
5+
source = "hashicorp/test"
6+
}
7+
}
8+
state_store "test_store" {
9+
provider "test" {
10+
}
11+
12+
value = "foobar"
13+
}
14+
}

0 commit comments

Comments
 (0)