mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00: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:
@ -28,13 +28,15 @@ func TestCustomLogoAndCompanyName(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
adminClient, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
|
||||
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
|
||||
coderdenttest.AddLicense(t, adminClient, coderdenttest.LicenseOptions{
|
||||
Features: license.Features{
|
||||
codersdk.FeatureAppearance: 1,
|
||||
},
|
||||
})
|
||||
|
||||
anotherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
|
||||
// Update logo and application name
|
||||
uac := codersdk.UpdateAppearanceConfig{
|
||||
ApplicationName: "ACME Ltd",
|
||||
@ -45,7 +47,7 @@ func TestCustomLogoAndCompanyName(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify update
|
||||
got, err := adminClient.Appearance(ctx)
|
||||
got, err := anotherClient.Appearance(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, uac.ApplicationName, got.ApplicationName)
|
||||
@ -62,9 +64,10 @@ func TestServiceBanners(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
|
||||
basicUserClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
|
||||
// Even without a license, the banner should return as disabled.
|
||||
sb, err := adminClient.Appearance(ctx)
|
||||
sb, err := basicUserClient.Appearance(ctx)
|
||||
require.NoError(t, err)
|
||||
require.False(t, sb.ServiceBanner.Enabled)
|
||||
|
||||
@ -75,12 +78,10 @@ func TestServiceBanners(t *testing.T) {
|
||||
})
|
||||
|
||||
// Default state
|
||||
sb, err = adminClient.Appearance(ctx)
|
||||
sb, err = basicUserClient.Appearance(ctx)
|
||||
require.NoError(t, err)
|
||||
require.False(t, sb.ServiceBanner.Enabled)
|
||||
|
||||
basicUserClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
|
||||
uac := codersdk.UpdateAppearanceConfig{
|
||||
ServiceBanner: sb.ServiceBanner,
|
||||
}
|
||||
@ -100,7 +101,7 @@ func TestServiceBanners(t *testing.T) {
|
||||
wantBanner.ServiceBanner.BackgroundColor = "#00FF00"
|
||||
err = adminClient.UpdateAppearance(ctx, wantBanner)
|
||||
require.NoError(t, err)
|
||||
gotBanner, err := adminClient.Appearance(ctx)
|
||||
gotBanner, err := adminClient.Appearance(ctx) //nolint:gocritic // we should assert at least once that the owner can get the banner
|
||||
require.NoError(t, err)
|
||||
gotBanner.SupportLinks = nil // clean "support links" before comparison
|
||||
require.Equal(t, wantBanner.ServiceBanner, gotBanner.ServiceBanner)
|
||||
@ -200,7 +201,7 @@ func TestCustomSupportLinks(t *testing.T) {
|
||||
Value: supportLinks,
|
||||
}
|
||||
|
||||
client, _ := coderdenttest.New(t, &coderdenttest.Options{
|
||||
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{
|
||||
Options: &coderdtest.Options{
|
||||
DeploymentValues: cfg,
|
||||
},
|
||||
@ -211,10 +212,11 @@ func TestCustomSupportLinks(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
anotherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
|
||||
defer cancel()
|
||||
|
||||
appearance, err := client.Appearance(ctx)
|
||||
appearance, err := anotherClient.Appearance(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, supportLinks, appearance.SupportLinks)
|
||||
}
|
||||
@ -223,12 +225,13 @@ func TestDefaultSupportLinks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Don't need to set the license, as default links are passed without it.
|
||||
client, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
|
||||
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
|
||||
anotherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
|
||||
defer cancel()
|
||||
|
||||
appearance, err := client.Appearance(ctx)
|
||||
appearance, err := anotherClient.Appearance(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, coderd.DefaultSupportLinks, appearance.SupportLinks)
|
||||
}
|
||||
|
Reference in New Issue
Block a user