Fix existing tests

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-05-14 23:20:18 +00:00
parent 0270117e8d
commit b4e92a69c9
5 changed files with 28 additions and 21 deletions

View file

@ -290,8 +290,11 @@ func (s *sqlDatabase) getGithubCredentialsByName(ctx context.Context, tx *gorm.D
if detailed {
q = q.
Preload("Repositories").
Preload("Repositories.Credentials").
Preload("Organizations").
Preload("Enterprises")
Preload("Organizations.Credentials").
Preload("Enterprises").
Preload("Enterprises.Credentials")
}
userID, err := getUIDFromContext(ctx)
@ -316,7 +319,6 @@ func (s *sqlDatabase) GetGithubCredentialsByName(ctx context.Context, name strin
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "fetching github credentials")
}
return s.sqlToCommonForgeCredentials(creds)
}
@ -327,8 +329,11 @@ func (s *sqlDatabase) GetGithubCredentials(ctx context.Context, id uint, detaile
if detailed {
q = q.
Preload("Repositories").
Preload("Repositories.Credentials").
Preload("Organizations").
Preload("Enterprises")
Preload("Organizations.Credentials").
Preload("Enterprises").
Preload("Enterprises.Credentials")
}
if !auth.IsAdmin(ctx) {

View file

@ -249,15 +249,6 @@ func (s *RepoTestSuite) TestCreateRepositoryInvalidDBPassphrase() {
func (s *RepoTestSuite) TestCreateRepositoryInvalidDBCreateErr() {
s.Fixtures.SQLMock.ExpectBegin()
s.Fixtures.SQLMock.
ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_credentials` WHERE user_id = ? AND name = ? AND `github_credentials`.`deleted_at` IS NULL ORDER BY `github_credentials`.`id` LIMIT ?")).
WithArgs(s.adminUserID, s.Fixtures.Repos[0].CredentialsName, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "endpoint_name"}).
AddRow(s.testCreds.ID, s.githubEndpoint.Name))
s.Fixtures.SQLMock.ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_endpoints` WHERE `github_endpoints`.`name` = ? AND `github_endpoints`.`deleted_at` IS NULL")).
WithArgs(s.testCreds.Endpoint.Name).
WillReturnRows(sqlmock.NewRows([]string{"name"}).
AddRow(s.githubEndpoint.Name))
s.Fixtures.SQLMock.
ExpectExec(regexp.QuoteMeta("INSERT INTO `repositories`")).
WillReturnError(fmt.Errorf("creating repo mock error"))