Skip to content

chore(cli): add linter to detect potential spurious usage of owner user in cli tests #10133

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 24 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d3114cd
chore: add linter to detect potential spurious usage of owner user in…
johnstcn Oct 7, 2023
e037fae
fix new linter complaints in userstatus_test.go
johnstcn Oct 9, 2023
b2da229
fix new linter complaints in userlist_test.go
johnstcn Oct 9, 2023
b0cedf6
fix new linter complaints in templatepush_test.go and update_test.go
johnstcn Oct 9, 2023
d4d53b5
fix new linter complaints in templatepush_test.go
johnstcn Oct 9, 2023
23a2658
address new linter complaints in templatepull_test.go
johnstcn Oct 9, 2023
4ef3b4e
fixup! chore: add linter to detect potential spurious usage of owner …
johnstcn Oct 9, 2023
709a7b7
fix new linter complaints in templatelist_test.go
johnstcn Oct 9, 2023
d6ca45d
fix new linter complaints in templateedit_test.go
johnstcn Oct 9, 2023
178d08b
fix new linter complaints in templatedelete_test.go
johnstcn Oct 9, 2023
c6f14f5
fix new linter complaints in state_test.go
johnstcn Oct 9, 2023
e281d9b
fix new linter complaints in start-test.go
johnstcn Oct 9, 2023
044edc7
fix new linter complaints in show_test.go
johnstcn Oct 9, 2023
21e1c5b
fix new linter complaints in restart_test.go
johnstcn Oct 9, 2023
a1f8fc4
fix new linter complaints in rename_test.go
johnstcn Oct 9, 2023
bfbbe66
fix new linter complaints in list_test.go
johnstcn Oct 9, 2023
92e6886
fix new linter complaints in delete_test.go, update docs
johnstcn Oct 9, 2023
7ce5bf4
fix new linter complaints in create_test.go
johnstcn Oct 9, 2023
c0fa0a4
fix new linter complaints in configssh__test.go
johnstcn Oct 9, 2023
0792d99
fix new linter complaints in agent_test.go
johnstcn Oct 9, 2023
9ef0f3c
fix issues in portforward_test that the linter missed :(
johnstcn Oct 10, 2023
277ffe8
consistently name result of CreateFirstUser owner instead of admin
johnstcn Oct 10, 2023
e43d307
Merge remote-tracking branch 'origin/main' into cj/owner-user-linter
johnstcn Oct 10, 2023
23a555a
address new linter complaints in user_delete_test.go
johnstcn Oct 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix issues in portforward_test that the linter missed :(
  • Loading branch information
johnstcn committed Oct 10, 2023
commit 9ef0f3c1d6d6fa7ca3886e30b91775c1c313f766
34 changes: 18 additions & 16 deletions cli/portforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ func TestPortForward_None(t *testing.T) {
t.Parallel()

client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)
admin := coderdtest.CreateFirstUser(t, client)
member, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)

inv, root := clitest.New(t, "port-forward", "blah")
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, member, root)
pty := ptytest.New(t).Attach(inv)
inv.Stderr = pty.Output()

Expand Down Expand Up @@ -132,8 +133,9 @@ func TestPortForward(t *testing.T) {
// non-parallel setup).
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user = coderdtest.CreateFirstUser(t, client)
workspace = runAgent(t, client, user.UserID)
admin = coderdtest.CreateFirstUser(t, client)
member, _ = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
workspace = runAgent(t, client, member)
)

for _, c := range cases {
Expand All @@ -151,7 +153,7 @@ func TestPortForward(t *testing.T) {
// Launch port-forward in a goroutine so we can start dialing
// the "local" listener.
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag)
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, member, root)
pty := ptytest.New(t)
inv.Stdin = pty.Input()
inv.Stdout = pty.Output()
Expand Down Expand Up @@ -198,7 +200,7 @@ func TestPortForward(t *testing.T) {
// Launch port-forward in a goroutine so we can start dialing
// the "local" listeners.
inv, root := clitest.New(t, "-v", "port-forward", workspace.Name, flag1, flag2)
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, member, root)
pty := ptytest.New(t)
inv.Stdin = pty.Input()
inv.Stdout = pty.Output()
Expand Down Expand Up @@ -253,7 +255,7 @@ func TestPortForward(t *testing.T) {
// Launch port-forward in a goroutine so we can start dialing
// the "local" listeners.
inv, root := clitest.New(t, append([]string{"-v", "port-forward", workspace.Name}, flags...)...)
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, member, root)
pty := ptytest.New(t).Attach(inv)
inv.Stderr = pty.Output()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
Expand Down Expand Up @@ -294,33 +296,33 @@ func TestPortForward(t *testing.T) {
// runAgent creates a fake workspace and starts an agent locally for that
// workspace. The agent will be cleaned up on test completion.
// nolint:unused
func runAgent(t *testing.T, client *codersdk.Client, userID uuid.UUID) codersdk.Workspace {
func runAgent(t *testing.T, adminClient, userClient *codersdk.Client) codersdk.Workspace {
ctx := context.Background()
user, err := client.User(ctx, userID.String())
user, err := userClient.User(ctx, codersdk.Me)
require.NoError(t, err, "specified user does not exist")
require.Greater(t, len(user.OrganizationIDs), 0, "user has no organizations")
orgID := user.OrganizationIDs[0]

// Setup template
agentToken := uuid.NewString()
version := coderdtest.CreateTemplateVersion(t, client, orgID, &echo.Responses{
version := coderdtest.CreateTemplateVersion(t, adminClient, orgID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionPlan: echo.PlanComplete,
ProvisionApply: echo.ProvisionApplyWithAgent(agentToken),
})

// Create template and workspace
template := coderdtest.CreateTemplate(t, client, orgID, version.ID)
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, orgID, template.ID)
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
template := coderdtest.CreateTemplate(t, adminClient, orgID, version.ID)
coderdtest.AwaitTemplateVersionJobCompleted(t, adminClient, version.ID)
workspace := coderdtest.CreateWorkspace(t, userClient, orgID, template.ID)
coderdtest.AwaitWorkspaceBuildJobCompleted(t, adminClient, workspace.LatestBuild.ID)

_ = agenttest.New(t, client.URL, agentToken,
_ = agenttest.New(t, adminClient.URL, agentToken,
func(o *agent.Options) {
o.SSHMaxTimeout = 60 * time.Second
},
)
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
coderdtest.AwaitWorkspaceAgents(t, adminClient, workspace.ID)

return workspace
}
Expand Down
7 changes: 4 additions & 3 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ func TestDERPHeaders(t *testing.T) {
})

var (
user = coderdtest.CreateFirstUser(t, client)
workspace = runAgent(t, client, user.UserID)
admin = coderdtest.CreateFirstUser(t, client)
member, _ = coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
workspace = runAgent(t, client, member)
)

// Inject custom /derp handler so we can inspect the headers.
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestDERPHeaders(t *testing.T) {
}
}
inv, root := clitest.New(t, args...)
clitest.SetupConfig(t, client, root)
clitest.SetupConfig(t, member, root)
pty := ptytest.New(t)
inv.Stdin = pty.Input()
inv.Stderr = pty.Output()
Expand Down