mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore(scripts/rules.go): broaden scope of testingWithOwnerUser linter (#10548)
* Updated testingWithOwnerUser ruleguard rule to detect: a) Passing client from coderdenttest.New() to clitest.SetupConfig() similar to what already exists for AGPL code b) Usage of any method of the owner client from coderdenttest.New() - all usages of the owner client must be justified with a `//nolint:gocritic` comment. * Fixed resulting linter complaints. * Added new coderdtest helpers CreateGroup and UpdateTemplateMeta. * Modified check_enterprise_import.sh to ignore scripts/rules.go.
This commit is contained in:
@@ -11,11 +11,11 @@ import (
|
||||
"github.com/coder/coder/v2/cli/clitest"
|
||||
"github.com/coder/coder/v2/cli/cliui"
|
||||
"github.com/coder/coder/v2/coderd/coderdtest"
|
||||
"github.com/coder/coder/v2/coderd/rbac"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
|
||||
"github.com/coder/coder/v2/enterprise/coderd/license"
|
||||
"github.com/coder/coder/v2/pty/ptytest"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
)
|
||||
|
||||
func TestGroupEdit(t *testing.T) {
|
||||
@@ -29,23 +29,13 @@ func TestGroupEdit(t *testing.T) {
|
||||
codersdk.FeatureTemplateRBAC: 1,
|
||||
},
|
||||
}})
|
||||
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID, rbac.RoleUserAdmin())
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
_, user1 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
|
||||
_, user2 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
|
||||
_, user3 := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
|
||||
|
||||
group, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
|
||||
Name: "alpha",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// We use the sdk here as opposed to the CLI since adding this user
|
||||
// is considered setup. They will be removed in the proper CLI test.
|
||||
group, err = client.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
|
||||
AddUsers: []string{user3.ID.String()},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
group := coderdtest.CreateGroup(t, client, admin.OrganizationID, "alpha", user3)
|
||||
|
||||
expectedName := "beta"
|
||||
|
||||
@@ -62,9 +52,9 @@ func TestGroupEdit(t *testing.T) {
|
||||
pty := ptytest.New(t)
|
||||
|
||||
inv.Stdout = pty.Output()
|
||||
clitest.SetupConfig(t, client, conf)
|
||||
clitest.SetupConfig(t, anotherClient, conf)
|
||||
|
||||
err = inv.Run()
|
||||
err := inv.Run()
|
||||
require.NoError(t, err)
|
||||
|
||||
pty.ExpectMatch(fmt.Sprintf("Successfully patched group %s", pretty.Sprint(cliui.DefaultStyles.Keyword, expectedName)))
|
||||
@@ -79,12 +69,8 @@ func TestGroupEdit(t *testing.T) {
|
||||
},
|
||||
}})
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
group, err := client.CreateGroup(ctx, admin.OrganizationID, codersdk.CreateGroupRequest{
|
||||
Name: "alpha",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// Create a group with no members.
|
||||
group := coderdtest.CreateGroup(t, client, admin.OrganizationID, "alpha")
|
||||
|
||||
inv, conf := newCLI(
|
||||
t,
|
||||
@@ -92,26 +78,26 @@ func TestGroupEdit(t *testing.T) {
|
||||
"-a", "foo",
|
||||
)
|
||||
|
||||
clitest.SetupConfig(t, client, conf)
|
||||
clitest.SetupConfig(t, client, conf) //nolint:gocritic // intentional usage of owner
|
||||
|
||||
err = inv.Run()
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "must be a valid UUID or email address")
|
||||
err := inv.Run()
|
||||
require.ErrorContains(t, err, "must be a valid UUID or email address")
|
||||
})
|
||||
|
||||
t.Run("NoArg", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, _ := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
|
||||
client, user := coderdenttest.New(t, &coderdenttest.Options{LicenseOptions: &coderdenttest.LicenseOptions{
|
||||
Features: license.Features{
|
||||
codersdk.FeatureTemplateRBAC: 1,
|
||||
},
|
||||
}})
|
||||
anotherClient, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID, rbac.RoleUserAdmin())
|
||||
|
||||
inv, conf := newCLI(t, "groups", "edit")
|
||||
clitest.SetupConfig(t, client, conf)
|
||||
clitest.SetupConfig(t, anotherClient, conf)
|
||||
|
||||
err := inv.Run()
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "wanted 1 args but got 0")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user