-
Notifications
You must be signed in to change notification settings - Fork 10.1k
PSS: Update the workspace new subcommand to work with PSS, add E2E and integration tests for using workspace commands with PSS.
#37855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
SarahFrench
wants to merge
12
commits into
pss/add-builtin-inmem-state-storage-implementation
Choose a base branch
from
pss/make-worspace-new-work-with-pss
base: pss/add-builtin-inmem-state-storage-implementation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+313
−6
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
859229f
Update the `workspace new` subcommand to work with PSS, add E2E test.
SarahFrench c11db26
Make some ioutil => os changes while I'm looking at the workspace com…
SarahFrench 3cd2d99
Add missing file header
SarahFrench a0cee10
Update code comments in command
SarahFrench 8694c76
test: Update E2E test using PSS with workspace commands to assert sta…
SarahFrench b89c446
test: Include `workspace show` in happy path E2E test using PSS
SarahFrench 2f374bb
fix: Allow DeleteState RPC to include the id of the state to delete
SarahFrench 1e07af1
test: Include `workspace delete` in happy path E2E test using PSS
SarahFrench 43ba713
fix: Avoid assignment to nil map in mock provider during WriteStateBytes
SarahFrench 612c4fc
test: Add integration test for workspace commands when using PSS
SarahFrench fe6866b
test: Update test to reflect changes in the test fixture configuration
SarahFrench 55a606d
docs: Fix code comment
SarahFrench File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| package e2etest | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform/internal/e2e" | ||
| "github.com/hashicorp/terraform/internal/getproviders" | ||
| ) | ||
|
|
||
| func TestPrimary_stateStore_workspaceCmd(t *testing.T) { | ||
| if v := os.Getenv("TF_TEST_EXPERIMENTS"); v == "" { | ||
| t.Skip("can't run without enabling experiments in the executable terraform binary, enable with TF_TEST_EXPERIMENTS=1") | ||
| } | ||
|
|
||
| if !canRunGoBuild { | ||
| // We're running in a separate-build-then-run context, so we can't | ||
| // currently execute this test which depends on being able to build | ||
| // new executable at runtime. | ||
| // | ||
| // (See the comment on canRunGoBuild's declaration for more information.) | ||
| t.Skip("can't run without building a new provider executable") | ||
| } | ||
| t.Parallel() | ||
|
|
||
| tf := e2e.NewBinary(t, terraformBin, "testdata/full-workflow-with-state-store-fs") | ||
| workspaceDirName := "states" // see test fixture value for workspace_dir | ||
|
|
||
| // In order to test integration with PSS we need a provider plugin implementing a state store. | ||
| // Here will build the simple6 (built with protocol v6) provider, which implements PSS. | ||
| simple6Provider := filepath.Join(tf.WorkDir(), "terraform-provider-simple6") | ||
| simple6ProviderExe := e2e.GoBuild("github.com/hashicorp/terraform/internal/provider-simple-v6/main", simple6Provider) | ||
|
|
||
| // Move the provider binaries into a directory that we will point terraform | ||
| // to using the -plugin-dir cli flag. | ||
| platform := getproviders.CurrentPlatform.String() | ||
| hashiDir := "cache/registry.terraform.io/hashicorp/" | ||
| if err := os.MkdirAll(tf.Path(hashiDir, "simple6/0.0.1/", platform), os.ModePerm); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := os.Rename(simple6ProviderExe, tf.Path(hashiDir, "simple6/0.0.1/", platform, "terraform-provider-simple6")); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| //// Init | ||
| _, stderr, err := tf.Run("init", "-enable-pluggable-state-storage-experiment=true", "-plugin-dir=cache", "-no-color") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) | ||
| } | ||
| fi, err := os.Stat(path.Join(tf.WorkDir(), workspaceDirName, "default", "terraform.tfstate")) | ||
| if err != nil { | ||
| t.Fatalf("failed to open default workspace's state file: %s", err) | ||
| } | ||
| if fi.Size() == 0 { | ||
| t.Fatal("default workspace's state file should not have size 0 bytes") | ||
| } | ||
|
|
||
| //// Create Workspace: terraform workspace new | ||
| newWorkspace := "foobar" | ||
| stdout, stderr, err := tf.Run("workspace", "new", newWorkspace, "-no-color") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) | ||
| } | ||
| expectedMsg := fmt.Sprintf("Created and switched to workspace %q!", newWorkspace) | ||
| if !strings.Contains(stdout, expectedMsg) { | ||
| t.Errorf("unexpected output, expected %q, but got:\n%s", expectedMsg, stdout) | ||
| } | ||
| fi, err = os.Stat(path.Join(tf.WorkDir(), workspaceDirName, newWorkspace, "terraform.tfstate")) | ||
| if err != nil { | ||
| t.Fatalf("failed to open %s workspace's state file: %s", newWorkspace, err) | ||
| } | ||
| if fi.Size() == 0 { | ||
| t.Fatalf("%s workspace's state file should not have size 0 bytes", newWorkspace) | ||
| } | ||
|
|
||
| //// List Workspaces: : terraform workspace list | ||
| stdout, stderr, err = tf.Run("workspace", "list", "-no-color") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) | ||
| } | ||
| if !strings.Contains(stdout, newWorkspace) { | ||
| t.Errorf("unexpected output, expected the new %q workspace to be listed present, but it's missing. Got:\n%s", newWorkspace, stdout) | ||
| } | ||
|
|
||
| //// Select Workspace: terraform workspace select | ||
| selectedWorkspace := "default" | ||
| stdout, stderr, err = tf.Run("workspace", "select", selectedWorkspace, "-no-color") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) | ||
| } | ||
| expectedMsg = fmt.Sprintf("Switched to workspace %q.", selectedWorkspace) | ||
| if !strings.Contains(stdout, expectedMsg) { | ||
| t.Errorf("unexpected output, expected %q, but got:\n%s", expectedMsg, stdout) | ||
| } | ||
|
|
||
| //// Show Workspace: terraform workspace show | ||
| stdout, stderr, err = tf.Run("workspace", "show", "-no-color") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) | ||
| } | ||
| expectedMsg = fmt.Sprintf("%s\n", selectedWorkspace) | ||
| if stdout != expectedMsg { | ||
| t.Errorf("unexpected output, expected %q, but got:\n%s", expectedMsg, stdout) | ||
| } | ||
|
|
||
| //// Delete Workspace: terraform workspace delete | ||
| stdout, stderr, err = tf.Run("workspace", "delete", newWorkspace, "-no-color") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s\nstderr:\n%s", err, stderr) | ||
| } | ||
| expectedMsg = fmt.Sprintf("Deleted workspace %q!\n", newWorkspace) | ||
| if stdout != expectedMsg { | ||
| t.Errorf("unexpected output, expected %q, but got:\n%s", expectedMsg, stdout) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ terraform { | |
|
|
||
| state_store "simple6_fs" { | ||
| provider "simple6" {} | ||
|
|
||
| workspace_dir = "states" | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagined that future E2E tests related to PSS would all go in this file.