-
Notifications
You must be signed in to change notification settings - Fork 887
fix(cli): add check for DisableOwnerWorkspaceExec in scaletest #14417
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
Merged
Merged
Changes from all commits
Commits
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
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,70 @@ | ||
package exptest_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"cdr.dev/slog/sloggers/slogtest" | ||
"github.com/coder/coder/v2/cli/clitest" | ||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
|
||
// This test validates that the scaletest CLI filters out workspaces not owned | ||
// when disable owner workspace access is set. | ||
// This test is in its own package because it mutates a global variable that | ||
// can influence other tests in the same package. | ||
// nolint:paralleltest | ||
func TestScaleTestWorkspaceTraffic_UseHostLogin(t *testing.T) { | ||
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium) | ||
defer cancelFunc() | ||
|
||
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) | ||
client := coderdtest.New(t, &coderdtest.Options{ | ||
Logger: &log, | ||
IncludeProvisionerDaemon: true, | ||
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) { | ||
dv.DisableOwnerWorkspaceExec = true | ||
}), | ||
}) | ||
owner := coderdtest.CreateFirstUser(t, client) | ||
tv := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) | ||
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, tv.ID) | ||
tpl := coderdtest.CreateTemplate(t, client, owner.OrganizationID, tv.ID) | ||
// Create a workspace owned by a different user | ||
memberClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) | ||
_ = coderdtest.CreateWorkspace(t, memberClient, tpl.ID, func(cwr *codersdk.CreateWorkspaceRequest) { | ||
cwr.Name = "scaletest-workspace" | ||
}) | ||
|
||
// Test without --use-host-login first.g | ||
inv, root := clitest.New(t, "exp", "scaletest", "workspace-traffic", | ||
"--template", tpl.Name, | ||
) | ||
// nolint:gocritic // We are intentionally testing this as the owner. | ||
clitest.SetupConfig(t, client, root) | ||
var stdoutBuf bytes.Buffer | ||
inv.Stdout = &stdoutBuf | ||
|
||
err := inv.WithContext(ctx).Run() | ||
require.ErrorContains(t, err, "no scaletest workspaces exist") | ||
require.Contains(t, stdoutBuf.String(), `1 workspace(s) were skipped`) | ||
|
||
// Test once again with --use-host-login. | ||
inv, root = clitest.New(t, "exp", "scaletest", "workspace-traffic", | ||
"--template", tpl.Name, | ||
"--use-host-login", | ||
) | ||
// nolint:gocritic // We are intentionally testing this as the owner. | ||
clitest.SetupConfig(t, client, root) | ||
stdoutBuf.Reset() | ||
inv.Stdout = &stdoutBuf | ||
|
||
err = inv.WithContext(ctx).Run() | ||
require.ErrorContains(t, err, "no scaletest workspaces exist") | ||
require.NotContains(t, stdoutBuf.String(), `1 workspace(s) were skipped`) | ||
} |
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.
Does this test not run in
go tests
?I ask because these roles are global, and it is an unfortunate consequence atm. (maybe custom roles can solve this without being global in the future).
You can see how I reset the global state here when using this option:
coder/coderd/rbac/roles_test.go
Lines 63 to 66 in e6ed3c3
and of course, no
t.Parallel()
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.
As far as I can tell, each package is its own test binary. So the global variable would only affect tests run in the same package.
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 added a
require.FailNow()
and validated that the test does indeed get run.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.
CI is passing, so the global-ness is not impacting the rest 🤔
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.
Yeah, Cian is right, you can think of each package as being built as its own test binary (basically that's what actually happens too), so global scope changes are constrained to that package. This is one of the test parallelism mechanisms in Go too (run different packages concurrently) and works irrespective of
t.Parallel()
.