Fix existing tests
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
0270117e8d
commit
b4e92a69c9
5 changed files with 28 additions and 21 deletions
26
cache/cache_test.go
vendored
26
cache/cache_test.go
vendored
|
|
@ -22,6 +22,11 @@ func (c *CacheTestSuite) SetupTest() {
|
|||
EntityType: params.ForgeEntityTypeOrganization,
|
||||
Name: "test",
|
||||
Owner: "test",
|
||||
Credentials: params.ForgeCredentials{
|
||||
ID: 1,
|
||||
Name: "test",
|
||||
ForgeType: params.GithubEndpointType,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +55,6 @@ func (c *CacheTestSuite) TestSetCacheWorks() {
|
|||
DownloadURL: garmTesting.Ptr("https://example.com"),
|
||||
},
|
||||
}
|
||||
|
||||
c.Require().NotNil(githubToolsCache)
|
||||
c.Require().Len(githubToolsCache.entities, 0)
|
||||
SetGithubToolsCache(c.entity, tools)
|
||||
|
|
@ -71,13 +75,17 @@ func (c *CacheTestSuite) TestTimedOutToolsCache() {
|
|||
c.Require().NotNil(githubToolsCache)
|
||||
c.Require().Len(githubToolsCache.entities, 0)
|
||||
SetGithubToolsCache(c.entity, tools)
|
||||
c.Require().Len(githubToolsCache.entities, 1)
|
||||
entity := githubToolsCache.entities[c.entity.ID]
|
||||
entity.updatedAt = entity.updatedAt.Add(-2 * time.Hour)
|
||||
|
||||
c.Require().Equal(int64(entity.expiresAt.Sub(entity.updatedAt).Minutes()), int64(60))
|
||||
c.Require().Len(githubToolsCache.entities, 1)
|
||||
entity = githubToolsCache.entities[c.entity.ID]
|
||||
entity.updatedAt = entity.updatedAt.Add(-3 * time.Hour)
|
||||
entity.expiresAt = entity.updatedAt.Add(-2 * time.Hour)
|
||||
githubToolsCache.entities[c.entity.ID] = entity
|
||||
|
||||
cachedTools, err := GetGithubToolsCache(c.entity.ID)
|
||||
c.Require().NoError(err)
|
||||
c.Require().Error(err)
|
||||
c.Require().Nil(cachedTools)
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +93,7 @@ func (c *CacheTestSuite) TestGetInexistentCache() {
|
|||
c.Require().NotNil(githubToolsCache)
|
||||
c.Require().Len(githubToolsCache.entities, 0)
|
||||
cachedTools, err := GetGithubToolsCache(c.entity.ID)
|
||||
c.Require().NoError(err)
|
||||
c.Require().Error(err)
|
||||
c.Require().Nil(cachedTools)
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +288,8 @@ func (c *CacheTestSuite) TestReplaceEntityPools() {
|
|||
Name: "test",
|
||||
Owner: "test",
|
||||
Credentials: params.ForgeCredentials{
|
||||
ID: 1,
|
||||
ID: 1,
|
||||
ForgeType: params.GithubEndpointType,
|
||||
},
|
||||
}
|
||||
pool1 := params.Pool{
|
||||
|
|
@ -291,8 +300,9 @@ func (c *CacheTestSuite) TestReplaceEntityPools() {
|
|||
}
|
||||
|
||||
credentials := params.ForgeCredentials{
|
||||
ID: 1,
|
||||
Name: "test",
|
||||
ID: 1,
|
||||
Name: "test",
|
||||
ForgeType: params.GithubEndpointType,
|
||||
}
|
||||
SetGithubCredentials(credentials)
|
||||
|
||||
|
|
|
|||
2
cache/tools_cache.go
vendored
2
cache/tools_cache.go
vendored
|
|
@ -68,7 +68,7 @@ func (g *GithubToolsCache) Set(entity params.ForgeEntity, tools []commonParams.R
|
|||
}
|
||||
|
||||
if entity.Credentials.ForgeType == params.GithubEndpointType {
|
||||
forgeTools.expiresAt = time.Now().Add(24 * time.Hour)
|
||||
forgeTools.expiresAt = time.Now().Add(1 * time.Hour)
|
||||
}
|
||||
|
||||
g.entities[entity.ID] = forgeTools
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ func (s *RepoTestSuite) SetupTest() {
|
|||
Name: "test-repo-create",
|
||||
CredentialsName: s.testCreds.Name,
|
||||
WebhookSecret: "test-create-repo-webhook-secret",
|
||||
ForgeType: params.GithubEndpointType,
|
||||
},
|
||||
CreatePoolParams: params.CreatePoolParams{
|
||||
ProviderName: "test-provider",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue