diff --git a/Makefile b/Makefile index 8f4d2009..3914e9be 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,7 @@ $(LOCALBIN): GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint ## Tool Versions -GOLANGCI_LINT_VERSION ?= v1.55.2 +GOLANGCI_LINT_VERSION ?= v1.56.2 .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten. diff --git a/apiserver/controllers/controllers.go b/apiserver/controllers/controllers.go index e7e5049f..256d8efc 100644 --- a/apiserver/controllers/controllers.go +++ b/apiserver/controllers/controllers.go @@ -32,7 +32,7 @@ import ( "github.com/cloudbase/garm/auth" "github.com/cloudbase/garm/metrics" runnerParams "github.com/cloudbase/garm/params" - "github.com/cloudbase/garm/runner" + "github.com/cloudbase/garm/runner" //nolint:typecheck wsWriter "github.com/cloudbase/garm/websocket" ) diff --git a/cmd/garm-cli/cmd/controller_info.go b/cmd/garm-cli/cmd/controller_info.go index 2cf818b3..67ef2b86 100644 --- a/cmd/garm-cli/cmd/controller_info.go +++ b/cmd/garm-cli/cmd/controller_info.go @@ -37,7 +37,7 @@ var infoShowCmd = &cobra.Command{ Short: "Show information", Long: `Show information about the current controller.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/credentials.go b/cmd/garm-cli/cmd/credentials.go index 603c6120..72bf4ec3 100644 --- a/cmd/garm-cli/cmd/credentials.go +++ b/cmd/garm-cli/cmd/credentials.go @@ -46,7 +46,7 @@ func init() { Short: "List configured github credentials", Long: `List the names of the github personal access tokens available to the garm.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/enterprise.go b/cmd/garm-cli/cmd/enterprise.go index d65aab9e..b01b0413 100644 --- a/cmd/garm-cli/cmd/enterprise.go +++ b/cmd/garm-cli/cmd/enterprise.go @@ -50,7 +50,7 @@ var enterpriseAddCmd = &cobra.Command{ Short: "Add enterprise", Long: `Add a new enterprise to the manager.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -76,7 +76,7 @@ var enterpriseListCmd = &cobra.Command{ Short: "List enterprises", Long: `List all configured enterprises that are currently managed.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -96,7 +96,7 @@ var enterpriseShowCmd = &cobra.Command{ Short: "Show details for one enterprise", Long: `Displays detailed information about a single enterprise.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -123,7 +123,7 @@ var enterpriseDeleteCmd = &cobra.Command{ Short: "Removes one enterprise", Long: `Delete one enterprise from the manager.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -147,7 +147,7 @@ var enterpriseUpdateCmd = &cobra.Command{ Short: "Update enterprise", Long: `Update enterprise credentials or webhook secret.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/init.go b/cmd/garm-cli/cmd/init.go index c3c00997..acdbda5a 100644 --- a/cmd/garm-cli/cmd/init.go +++ b/cmd/garm-cli/cmd/init.go @@ -45,7 +45,7 @@ Example usage: garm-cli init --name=dev --url=https://runner.example.com --username=admin --password=superSecretPassword `, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if cfg != nil { if cfg.HasManager(loginProfileName) { return fmt.Errorf("a manager with name %s already exists in your local config", loginProfileName) diff --git a/cmd/garm-cli/cmd/jobs.go b/cmd/garm-cli/cmd/jobs.go index 0dae4b2a..c8505222 100644 --- a/cmd/garm-cli/cmd/jobs.go +++ b/cmd/garm-cli/cmd/jobs.go @@ -41,7 +41,7 @@ var jobsListCmd = &cobra.Command{ Short: "List jobs", Long: `List all jobs currently recorded in the system.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/log.go b/cmd/garm-cli/cmd/log.go index 155127e7..1dab7c1d 100644 --- a/cmd/garm-cli/cmd/log.go +++ b/cmd/garm-cli/cmd/log.go @@ -23,7 +23,7 @@ var logCmd = &cobra.Command{ SilenceUsage: true, Short: "Stream garm log", Long: `Stream all garm logging to the terminal.`, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) diff --git a/cmd/garm-cli/cmd/metrics.go b/cmd/garm-cli/cmd/metrics.go index cfd48001..ea1fd7ca 100644 --- a/cmd/garm-cli/cmd/metrics.go +++ b/cmd/garm-cli/cmd/metrics.go @@ -36,7 +36,7 @@ var metricsTokenCreateCmd = &cobra.Command{ Short: "Create a metrics token", Long: `Create a metrics token.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/organization.go b/cmd/garm-cli/cmd/organization.go index 2873b0e5..2b5def34 100644 --- a/cmd/garm-cli/cmd/organization.go +++ b/cmd/garm-cli/cmd/organization.go @@ -62,7 +62,7 @@ var orgWebhookInstallCmd = &cobra.Command{ Short: "Install webhook", Long: `Install webhook for an organization.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -92,7 +92,7 @@ var orgHookInfoShowCmd = &cobra.Command{ Short: "Show webhook info", Long: `Show webhook info for an organization.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -120,7 +120,7 @@ var orgWebhookUninstallCmd = &cobra.Command{ Short: "Uninstall webhook", Long: `Uninstall webhook for an organization.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -148,7 +148,7 @@ var orgAddCmd = &cobra.Command{ Short: "Add organization", Long: `Add a new organization to the manager.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -199,7 +199,7 @@ var orgUpdateCmd = &cobra.Command{ Short: "Update organization", Long: `Update organization credentials or webhook secret.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -232,7 +232,7 @@ var orgListCmd = &cobra.Command{ Short: "List organizations", Long: `List all configured organizations that are currently managed.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -252,7 +252,7 @@ var orgShowCmd = &cobra.Command{ Short: "Show details for one organization", Long: `Displays detailed information about a single organization.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -279,7 +279,7 @@ var orgDeleteCmd = &cobra.Command{ Short: "Removes one organization", Long: `Delete one organization from the manager.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/pool.go b/cmd/garm-cli/cmd/pool.go index e6cdaaae..31fe326d 100644 --- a/cmd/garm-cli/cmd/pool.go +++ b/cmd/garm-cli/cmd/pool.go @@ -139,7 +139,7 @@ var poolShowCmd = &cobra.Command{ Short: "Show details for a runner", Long: `Displays a detailed view of a single runner.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -169,7 +169,7 @@ var poolDeleteCmd = &cobra.Command{ Short: "Delete pool by ID", Long: `Delete one pool by referencing it's ID, regardless of repo or org.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -197,7 +197,7 @@ var poolAddCmd = &cobra.Command{ Short: "Add pool", Long: `Add a new pool to a repository or organization.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/profile.go b/cmd/garm-cli/cmd/profile.go index fe7e36e6..0ec28ec0 100644 --- a/cmd/garm-cli/cmd/profile.go +++ b/cmd/garm-cli/cmd/profile.go @@ -55,7 +55,7 @@ This command will list all currently defined profiles in the local configuration file of the garm client. `, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -76,7 +76,7 @@ var profileDeleteCmd = &cobra.Command{ Short: "Delete profile", Long: `Delete a profile from the local CLI configuration.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -101,7 +101,7 @@ var poolSwitchCmd = &cobra.Command{ Short: "Switch to a different profile", Long: `Switch the CLI to a different profile.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -132,7 +132,7 @@ var profileAddCmd = &cobra.Command{ Short: "Add profile", Long: `Create a profile for a new garm installation.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if cfg != nil { if cfg.HasManager(loginProfileName) { return fmt.Errorf("a manager with name %s already exists in your local config", loginProfileName) @@ -180,7 +180,7 @@ This command will refresh the bearer token associated with an already defined ga installation, by performing a login. `, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/provider.go b/cmd/garm-cli/cmd/provider.go index bd466254..eef6a421 100644 --- a/cmd/garm-cli/cmd/provider.go +++ b/cmd/garm-cli/cmd/provider.go @@ -45,7 +45,7 @@ func init() { Short: "List all configured providers", Long: `List all cloud providers configured with the service.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/repository.go b/cmd/garm-cli/cmd/repository.go index 9cc4d2c6..a603988b 100644 --- a/cmd/garm-cli/cmd/repository.go +++ b/cmd/garm-cli/cmd/repository.go @@ -63,7 +63,7 @@ var repoWebhookInstallCmd = &cobra.Command{ Short: "Install webhook", Long: `Install webhook for a repository.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -93,7 +93,7 @@ var repoHookInfoShowCmd = &cobra.Command{ Short: "Show webhook info", Long: `Show webhook info for a repository.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -121,7 +121,7 @@ var repoWebhookUninstallCmd = &cobra.Command{ Short: "Uninstall webhook", Long: `Uninstall webhook for a repository.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -149,7 +149,7 @@ var repoAddCmd = &cobra.Command{ Short: "Add repository", Long: `Add a new repository to the manager.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -202,7 +202,7 @@ var repoListCmd = &cobra.Command{ Short: "List repositories", Long: `List all configured repositories that are currently managed.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { if needsInit { return errNeedsInitError } @@ -222,7 +222,7 @@ var repoUpdateCmd = &cobra.Command{ Short: "Update repository", Long: `Update repository credentials or webhook secret.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -255,7 +255,7 @@ var repoShowCmd = &cobra.Command{ Short: "Show details for one repository", Long: `Displays detailed information about a single repository.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -282,7 +282,7 @@ var repoDeleteCmd = &cobra.Command{ Short: "Removes one repository", Long: `Delete one repository from the manager.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/runner.go b/cmd/garm-cli/cmd/runner.go index 730e0625..b3c00ae8 100644 --- a/cmd/garm-cli/cmd/runner.go +++ b/cmd/garm-cli/cmd/runner.go @@ -139,7 +139,7 @@ var runnerShowCmd = &cobra.Command{ Short: "Show details for a runner", Long: `Displays a detailed view of a single runner.`, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } @@ -178,7 +178,7 @@ NOTE: An active runner cannot be removed from Github. You will have to either cancel the workflow or wait for it to finish. `, SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { if needsInit { return errNeedsInitError } diff --git a/cmd/garm-cli/cmd/version.go b/cmd/garm-cli/cmd/version.go index 99253aed..4d209b3d 100644 --- a/cmd/garm-cli/cmd/version.go +++ b/cmd/garm-cli/cmd/version.go @@ -25,7 +25,7 @@ var versionCmd = &cobra.Command{ Use: "version", SilenceUsage: true, Short: "Print version and exit", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println(Version) }, } diff --git a/cmd/garm/main.go b/cmd/garm/main.go index 75d574e2..ad80c521 100644 --- a/cmd/garm/main.go +++ b/cmd/garm/main.go @@ -41,7 +41,7 @@ import ( "github.com/cloudbase/garm/database" "github.com/cloudbase/garm/database/common" "github.com/cloudbase/garm/metrics" - "github.com/cloudbase/garm/runner" + "github.com/cloudbase/garm/runner" //nolint:typecheck runnerMetrics "github.com/cloudbase/garm/runner/metrics" garmUtil "github.com/cloudbase/garm/util" "github.com/cloudbase/garm/util/appdefaults" diff --git a/database/sql/common_test.go b/database/sql/common_test.go new file mode 100644 index 00000000..af0adcf9 --- /dev/null +++ b/database/sql/common_test.go @@ -0,0 +1,7 @@ +package sql + +const ( + wrongPassphrase = "wrong-passphrase" + webhookSecret = "webhook-secret" + falseString = "false" +) diff --git a/database/sql/enterprise_test.go b/database/sql/enterprise_test.go index c156077f..e00af874 100644 --- a/database/sql/enterprise_test.go +++ b/database/sql/enterprise_test.go @@ -104,7 +104,7 @@ func (s *EnterpriseTestSuite) SetupTest() { SkipInitializeWithVersion: true, } gormConfig := &gorm.Config{} - if flag.Lookup("test.v").Value.String() == "false" { + if flag.Lookup("test.v").Value.String() == falseString { gormConfig.Logger = logger.Default.LogMode(logger.Silent) } gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig) @@ -182,7 +182,7 @@ func (s *EnterpriseTestSuite) TestCreateEnterpriseInvalidDBPassphrase() { s.FailNow(fmt.Sprintf("failed to create db connection: %s", err)) } // make sure we use a 'sqlDatabase' struct with a wrong 'cfg.Passphrase' - cfg.Passphrase = "wrong-passphrase" // it must have a size different than 32 + cfg.Passphrase = wrongPassphrase // it must have a size different than 32 sqlDB := &sqlDatabase{ conn: conn, cfg: cfg, @@ -321,7 +321,7 @@ func (s *EnterpriseTestSuite) TestUpdateEnterpriseInvalidEnterpriseID() { } func (s *EnterpriseTestSuite) TestUpdateEnterpriseDBEncryptErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `enterprises` WHERE id = ? AND `enterprises`.`deleted_at` IS NULL ORDER BY `enterprises`.`id` LIMIT 1")). @@ -354,8 +354,8 @@ func (s *EnterpriseTestSuite) TestUpdateEnterpriseDBSaveErr() { } func (s *EnterpriseTestSuite) TestUpdateEnterpriseDBDecryptingErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" - s.Fixtures.UpdateRepoParams.WebhookSecret = "webhook-secret" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase + s.Fixtures.UpdateRepoParams.WebhookSecret = webhookSecret s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `enterprises` WHERE id = ? AND `enterprises`.`deleted_at` IS NULL ORDER BY `enterprises`.`id` LIMIT 1")). diff --git a/database/sql/instances_test.go b/database/sql/instances_test.go index fca439a3..44fd95c3 100644 --- a/database/sql/instances_test.go +++ b/database/sql/instances_test.go @@ -129,7 +129,7 @@ func (s *InstancesTestSuite) SetupTest() { SkipInitializeWithVersion: true, } gormConfig := &gorm.Config{} - if flag.Lookup("test.v").Value.String() == "false" { + if flag.Lookup("test.v").Value.String() == falseString { gormConfig.Logger = logger.Default.LogMode(logger.Silent) } gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig) diff --git a/database/sql/organizations_test.go b/database/sql/organizations_test.go index 2d6f83fc..50e46191 100644 --- a/database/sql/organizations_test.go +++ b/database/sql/organizations_test.go @@ -104,7 +104,7 @@ func (s *OrgTestSuite) SetupTest() { SkipInitializeWithVersion: true, } gormConfig := &gorm.Config{} - if flag.Lookup("test.v").Value.String() == "false" { + if flag.Lookup("test.v").Value.String() == falseString { gormConfig.Logger = logger.Default.LogMode(logger.Silent) } gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig) @@ -182,7 +182,7 @@ func (s *OrgTestSuite) TestCreateOrganizationInvalidDBPassphrase() { s.FailNow(fmt.Sprintf("failed to create db connection: %s", err)) } // make sure we use a 'sqlDatabase' struct with a wrong 'cfg.Passphrase' - cfg.Passphrase = "wrong-passphrase" // it must have a size different than 32 + cfg.Passphrase = wrongPassphrase // it must have a size different than 32 sqlDB := &sqlDatabase{ conn: conn, cfg: cfg, @@ -321,7 +321,7 @@ func (s *OrgTestSuite) TestUpdateOrganizationInvalidOrgID() { } func (s *OrgTestSuite) TestUpdateOrganizationDBEncryptErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `organizations` WHERE id = ? AND `organizations`.`deleted_at` IS NULL ORDER BY `organizations`.`id` LIMIT 1")). @@ -354,8 +354,8 @@ func (s *OrgTestSuite) TestUpdateOrganizationDBSaveErr() { } func (s *OrgTestSuite) TestUpdateOrganizationDBDecryptingErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" - s.Fixtures.UpdateRepoParams.WebhookSecret = "webhook-secret" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase + s.Fixtures.UpdateRepoParams.WebhookSecret = webhookSecret s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `organizations` WHERE id = ? AND `organizations`.`deleted_at` IS NULL ORDER BY `organizations`.`id` LIMIT 1")). diff --git a/database/sql/pools.go b/database/sql/pools.go index 3ebb69d8..9d6737e6 100644 --- a/database/sql/pools.go +++ b/database/sql/pools.go @@ -26,6 +26,12 @@ import ( "github.com/cloudbase/garm/params" ) +const ( + entityTypeEnterpriseName = "enterprise_id" + entityTypeOrgName = "org_id" + entityTypeRepoName = "repo_id" +) + func (s *sqlDatabase) ListAllPools(_ context.Context) ([]params.Pool, error) { var pools []Pool @@ -92,11 +98,11 @@ func (s *sqlDatabase) getEntityPool(_ context.Context, entityType params.PoolTyp var fieldName string switch entityType { case params.RepositoryPool: - fieldName = "repo_id" + fieldName = entityTypeRepoName case params.OrganizationPool: - fieldName = "org_id" + fieldName = entityTypeOrgName case params.EnterprisePool: - fieldName = "enterprise_id" + fieldName = entityTypeEnterpriseName default: return Pool{}, fmt.Errorf("invalid entityType: %v", entityType) } @@ -106,7 +112,6 @@ func (s *sqlDatabase) getEntityPool(_ context.Context, entityType params.PoolTyp err = q.Model(&Pool{}). Where(condition, u, entityID). First(&pool).Error - if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return Pool{}, errors.Wrap(runnerErrors.ErrNotFound, "finding pool") @@ -132,11 +137,11 @@ func (s *sqlDatabase) listEntityPools(_ context.Context, entityType params.PoolT var fieldName string switch entityType { case params.RepositoryPool: - fieldName = "repo_id" + fieldName = entityTypeRepoName case params.OrganizationPool: - fieldName = "org_id" + fieldName = entityTypeOrgName case params.EnterprisePool: - fieldName = "enterprise_id" + fieldName = entityTypeEnterpriseName default: return nil, fmt.Errorf("invalid entityType: %v", entityType) } @@ -169,11 +174,11 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.PoolType, tags [ var fieldName string switch poolType { case params.RepositoryPool: - fieldName = "repo_id" + fieldName = entityTypeRepoName case params.OrganizationPool: - fieldName = "org_id" + fieldName = entityTypeOrgName case params.EnterprisePool: - fieldName = "enterprise_id" + fieldName = entityTypeEnterpriseName default: return nil, fmt.Errorf("invalid poolType: %v", poolType) } diff --git a/database/sql/pools_test.go b/database/sql/pools_test.go index 43939282..c9a26fe0 100644 --- a/database/sql/pools_test.go +++ b/database/sql/pools_test.go @@ -99,7 +99,7 @@ func (s *PoolsTestSuite) SetupTest() { SkipInitializeWithVersion: true, } gormConfig := &gorm.Config{} - if flag.Lookup("test.v").Value.String() == "false" { + if flag.Lookup("test.v").Value.String() == falseString { gormConfig.Logger = logger.Default.LogMode(logger.Silent) } gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig) diff --git a/database/sql/repositories_test.go b/database/sql/repositories_test.go index 5d2d8f1f..7f3903b0 100644 --- a/database/sql/repositories_test.go +++ b/database/sql/repositories_test.go @@ -115,7 +115,7 @@ func (s *RepoTestSuite) SetupTest() { SkipInitializeWithVersion: true, } gormConfig := &gorm.Config{} - if flag.Lookup("test.v").Value.String() == "false" { + if flag.Lookup("test.v").Value.String() == falseString { gormConfig.Logger = logger.Default.LogMode(logger.Silent) } gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig) @@ -197,7 +197,7 @@ func (s *RepoTestSuite) TestCreateRepositoryInvalidDBPassphrase() { s.FailNow(fmt.Sprintf("failed to create db connection: %s", err)) } // make sure we use a 'sqlDatabase' struct with a wrong 'cfg.Passphrase' - cfg.Passphrase = "wrong-passphrase" // it must have a size different than 32 + cfg.Passphrase = wrongPassphrase // it must have a size different than 32 sqlDB := &sqlDatabase{ conn: conn, cfg: cfg, @@ -296,7 +296,7 @@ func (s *RepoTestSuite) TestListRepositoriesDBFetchErr() { } func (s *RepoTestSuite) TestListRepositoriesDBDecryptingErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `repositories` WHERE `repositories`.`deleted_at` IS NULL")). @@ -360,7 +360,7 @@ func (s *RepoTestSuite) TestUpdateRepositoryInvalidRepoID() { } func (s *RepoTestSuite) TestUpdateRepositoryDBEncryptErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `repositories` WHERE id = ? AND `repositories`.`deleted_at` IS NULL ORDER BY `repositories`.`id` LIMIT 1")). @@ -392,8 +392,8 @@ func (s *RepoTestSuite) TestUpdateRepositoryDBSaveErr() { } func (s *RepoTestSuite) TestUpdateRepositoryDBDecryptingErr() { - s.StoreSQLMocked.cfg.Passphrase = "wrong-passphrase" - s.Fixtures.UpdateRepoParams.WebhookSecret = "webhook-secret" + s.StoreSQLMocked.cfg.Passphrase = wrongPassphrase + s.Fixtures.UpdateRepoParams.WebhookSecret = webhookSecret s.Fixtures.SQLMock. ExpectQuery(regexp.QuoteMeta("SELECT * FROM `repositories` WHERE id = ? AND `repositories`.`deleted_at` IS NULL ORDER BY `repositories`.`id` LIMIT 1")). diff --git a/database/sql/users_test.go b/database/sql/users_test.go index ae5d63c6..1317130a 100644 --- a/database/sql/users_test.go +++ b/database/sql/users_test.go @@ -91,7 +91,7 @@ func (s *UserTestSuite) SetupTest() { SkipInitializeWithVersion: true, } gormConfig := &gorm.Config{} - if flag.Lookup("test.v").Value.String() == "false" { + if flag.Lookup("test.v").Value.String() == falseString { gormConfig.Logger = logger.Default.LogMode(logger.Silent) } gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig) diff --git a/runner/metrics/enterprise.go b/runner/metrics/enterprise.go index 17c2fa0d..407c0fc4 100644 --- a/runner/metrics/enterprise.go +++ b/runner/metrics/enterprise.go @@ -5,7 +5,7 @@ import ( "strconv" "github.com/cloudbase/garm/metrics" - "github.com/cloudbase/garm/runner" + "github.com/cloudbase/garm/runner" //nolint:typecheck ) // CollectOrganizationMetric collects the metrics for the enterprise objects