fix: remove unused cobra args
Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
This commit is contained in:
parent
4409beb18a
commit
7221812dfa
26 changed files with 84 additions and 72 deletions
7
database/sql/common_test.go
Normal file
7
database/sql/common_test.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package sql
|
||||
|
||||
const (
|
||||
wrongPassphrase = "wrong-passphrase"
|
||||
webhookSecret = "webhook-secret"
|
||||
falseString = "false"
|
||||
)
|
||||
|
|
@ -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")).
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")).
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")).
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue