Fix tests
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
0152b21529
commit
9384e37bb1
22 changed files with 652 additions and 396 deletions
|
|
@ -201,16 +201,16 @@ func (s *sqlDatabase) CreateEnterprisePool(ctx context.Context, enterpriseID str
|
|||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetEnterprisePool(ctx context.Context, enterpriseID, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeEnterprise, enterpriseID, poolID, "Tags", "Instances")
|
||||
func (s *sqlDatabase) GetEnterprisePool(_ context.Context, enterpriseID, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeEnterprise, enterpriseID, poolID, "Tags", "Instances")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) DeleteEnterprisePool(ctx context.Context, enterpriseID, poolID string) error {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeEnterprise, enterpriseID, poolID)
|
||||
func (s *sqlDatabase) DeleteEnterprisePool(_ context.Context, enterpriseID, poolID string) error {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeEnterprise, enterpriseID, poolID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "looking up enterprise pool")
|
||||
}
|
||||
|
|
@ -221,13 +221,13 @@ func (s *sqlDatabase) DeleteEnterprisePool(ctx context.Context, enterpriseID, po
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) UpdateEnterprisePool(ctx context.Context, enterpriseID, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeEnterprise, enterpriseID, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
func (s *sqlDatabase) UpdateEnterprisePool(_ context.Context, enterpriseID, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeEnterprise, enterpriseID, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
|
||||
return s.updatePool(pool, param)
|
||||
return s.updatePool(s.conn, pool, param)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) ListEnterprisePools(ctx context.Context, enterpriseID string) ([]params.Pool, error) {
|
||||
|
|
|
|||
|
|
@ -405,7 +405,11 @@ func (s *EnterpriseTestSuite) TestGetEnterpriseByIDDBDecryptingErr() {
|
|||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestCreateEnterprisePool() {
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().Nil(err)
|
||||
|
||||
|
|
@ -422,18 +426,25 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePool() {
|
|||
|
||||
func (s *EnterpriseTestSuite) TestCreateEnterprisePoolMissingTags() {
|
||||
s.Fixtures.CreatePoolParams.Tags = []string{}
|
||||
|
||||
_, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
_, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("no tags specified", err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestCreateEnterprisePoolInvalidEnterpriseID() {
|
||||
_, err := s.Store.CreateEnterprisePool(context.Background(), "dummy-enterprise-id", s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-enterprise-id",
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
_, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("fetching enterprise: parsing id: invalid request", err.Error())
|
||||
s.Require().Equal("parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestCreateEnterprisePoolDBCreateErr() {
|
||||
|
|
@ -655,9 +666,13 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePoolDBFetchPoolErr() {
|
|||
|
||||
func (s *EnterpriseTestSuite) TestListEnterprisePools() {
|
||||
enterprisePools := []params.Pool{}
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
for i := 1; i <= 2; i++ {
|
||||
s.Fixtures.CreatePoolParams.Flavor = fmt.Sprintf("test-flavor-%v", i)
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create enterprise pool: %v", err))
|
||||
}
|
||||
|
|
@ -678,46 +693,66 @@ func (s *EnterpriseTestSuite) TestListEnterprisePoolsInvalidEnterpriseID() {
|
|||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestGetEnterprisePool() {
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create enterprise pool: %v", err))
|
||||
}
|
||||
|
||||
enterprisePool, err := s.Store.GetEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, pool.ID)
|
||||
enterprisePool, err := s.Store.GetEntityPool(context.Background(), entity, pool.ID)
|
||||
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(enterprisePool.ID, pool.ID)
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestGetEnterprisePoolInvalidEnterpriseID() {
|
||||
_, err := s.Store.GetEnterprisePool(context.Background(), "dummy-enterprise-id", "dummy-pool-id")
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-enterprise-id",
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
_, err := s.Store.GetEntityPool(context.Background(), entity, "dummy-pool-id")
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("fetching pool: parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() {
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create enterprise pool: %v", err))
|
||||
}
|
||||
|
||||
err = s.Store.DeleteEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, pool.ID)
|
||||
err = s.Store.DeleteEntityPool(context.Background(), entity, pool.ID)
|
||||
|
||||
s.Require().Nil(err)
|
||||
_, err = s.Store.GetEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, pool.ID)
|
||||
_, err = s.Store.GetEntityPool(context.Background(), entity, pool.ID)
|
||||
s.Require().Equal("fetching pool: finding pool: not found", err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolInvalidEnterpriseID() {
|
||||
err := s.Store.DeleteEnterprisePool(context.Background(), "dummy-enterprise-id", "dummy-pool-id")
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-enterprise-id",
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
err := s.Store.DeleteEntityPool(context.Background(), entity, "dummy-pool-id")
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("looking up enterprise pool: parsing id: invalid request", err.Error())
|
||||
s.Require().Equal("parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolDBDeleteErr() {
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create enterprise pool: %v", err))
|
||||
}
|
||||
|
|
@ -741,7 +776,11 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolDBDeleteErr() {
|
|||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestListEnterpriseInstances() {
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create enterprise pool: %v", err))
|
||||
}
|
||||
|
|
@ -769,7 +808,11 @@ func (s *EnterpriseTestSuite) TestListEnterpriseInstancesInvalidEnterpriseID() {
|
|||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() {
|
||||
pool, err := s.Store.CreateEnterprisePool(context.Background(), s.Fixtures.Enterprises[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Enterprises[0].ID,
|
||||
EntityType: params.GithubEntityTypeEnterprise,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create enterprise pool: %v", err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func (s *sqlDatabase) unsealAndUnmarshal(data []byte, target interface{}) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) CreateInstance(ctx context.Context, poolID string, param params.CreateInstanceParams) (params.Instance, error) {
|
||||
func (s *sqlDatabase) CreateInstance(_ context.Context, poolID string, param params.CreateInstanceParams) (params.Instance, error) {
|
||||
pool, err := s.getPoolByID(s.conn, poolID)
|
||||
if err != nil {
|
||||
return params.Instance{}, errors.Wrap(err, "fetching pool")
|
||||
|
|
@ -152,7 +152,7 @@ func (s *sqlDatabase) getInstanceByName(_ context.Context, instanceName string,
|
|||
return instance, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetPoolInstanceByName(ctx context.Context, poolID string, instanceName string) (params.Instance, error) {
|
||||
func (s *sqlDatabase) GetPoolInstanceByName(_ context.Context, poolID string, instanceName string) (params.Instance, error) {
|
||||
instance, err := s.getPoolInstanceByName(poolID, instanceName)
|
||||
if err != nil {
|
||||
return params.Instance{}, errors.Wrap(err, "fetching instance")
|
||||
|
|
@ -170,7 +170,7 @@ func (s *sqlDatabase) GetInstanceByName(ctx context.Context, instanceName string
|
|||
return s.sqlToParamsInstance(instance)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) DeleteInstance(ctx context.Context, poolID string, instanceName string) error {
|
||||
func (s *sqlDatabase) DeleteInstance(_ context.Context, poolID string, instanceName string) error {
|
||||
instance, err := s.getPoolInstanceByName(poolID, instanceName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "deleting instance")
|
||||
|
|
@ -337,7 +337,7 @@ func (s *sqlDatabase) ListAllInstances(_ context.Context) ([]params.Instance, er
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) PoolInstanceCount(ctx context.Context, poolID string) (int64, error) {
|
||||
func (s *sqlDatabase) PoolInstanceCount(_ context.Context, poolID string) (int64, error) {
|
||||
pool, err := s.getPoolByID(s.conn, poolID)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "fetching pool")
|
||||
|
|
|
|||
|
|
@ -92,7 +92,11 @@ func (s *InstancesTestSuite) SetupTest() {
|
|||
OSType: "linux",
|
||||
Tags: []string{"self-hosted", "amd64", "linux"},
|
||||
}
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), org.ID, createPoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: org.ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, createPoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("failed to create org pool: %s", err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,16 +235,16 @@ func (s *sqlDatabase) ListOrgPools(ctx context.Context, orgID string) ([]params.
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetOrganizationPool(ctx context.Context, orgID, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeOrganization, orgID, poolID, "Tags", "Instances")
|
||||
func (s *sqlDatabase) GetOrganizationPool(_ context.Context, orgID, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeOrganization, orgID, poolID, "Tags", "Instances")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) DeleteOrganizationPool(ctx context.Context, orgID, poolID string) error {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeOrganization, orgID, poolID)
|
||||
func (s *sqlDatabase) DeleteOrganizationPool(_ context.Context, orgID, poolID string) error {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeOrganization, orgID, poolID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "looking up org pool")
|
||||
}
|
||||
|
|
@ -273,13 +273,13 @@ func (s *sqlDatabase) ListOrgInstances(ctx context.Context, orgID string) ([]par
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) UpdateOrganizationPool(ctx context.Context, orgID, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeOrganization, orgID, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
func (s *sqlDatabase) UpdateOrganizationPool(_ context.Context, orgID, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeOrganization, orgID, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
|
||||
return s.updatePool(pool, param)
|
||||
return s.updatePool(s.conn, pool, param)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) getOrgByID(_ context.Context, id string, preload ...string) (Organization, error) {
|
||||
|
|
|
|||
|
|
@ -405,7 +405,11 @@ func (s *OrgTestSuite) TestGetOrganizationByIDDBDecryptingErr() {
|
|||
}
|
||||
|
||||
func (s *OrgTestSuite) TestCreateOrganizationPool() {
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().Nil(err)
|
||||
|
||||
|
|
@ -422,18 +426,25 @@ func (s *OrgTestSuite) TestCreateOrganizationPool() {
|
|||
|
||||
func (s *OrgTestSuite) TestCreateOrganizationPoolMissingTags() {
|
||||
s.Fixtures.CreatePoolParams.Tags = []string{}
|
||||
|
||||
_, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
_, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("no tags specified", err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestCreateOrganizationPoolInvalidOrgID() {
|
||||
_, err := s.Store.CreateOrganizationPool(context.Background(), "dummy-org-id", s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-org-id",
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
_, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("fetching org: parsing id: invalid request", err.Error())
|
||||
s.Require().Equal("parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestCreateOrganizationPoolDBCreateErr() {
|
||||
|
|
@ -655,9 +666,13 @@ func (s *OrgTestSuite) TestCreateOrganizationPoolDBFetchPoolErr() {
|
|||
|
||||
func (s *OrgTestSuite) TestListOrgPools() {
|
||||
orgPools := []params.Pool{}
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
for i := 1; i <= 2; i++ {
|
||||
s.Fixtures.CreatePoolParams.Flavor = fmt.Sprintf("test-flavor-%v", i)
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
|
||||
}
|
||||
|
|
@ -678,46 +693,66 @@ func (s *OrgTestSuite) TestListOrgPoolsInvalidOrgID() {
|
|||
}
|
||||
|
||||
func (s *OrgTestSuite) TestGetOrganizationPool() {
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
|
||||
}
|
||||
|
||||
orgPool, err := s.Store.GetOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, pool.ID)
|
||||
orgPool, err := s.Store.GetEntityPool(context.Background(), entity, pool.ID)
|
||||
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(orgPool.ID, pool.ID)
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestGetOrganizationPoolInvalidOrgID() {
|
||||
_, err := s.Store.GetOrganizationPool(context.Background(), "dummy-org-id", "dummy-pool-id")
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-org-id",
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
_, err := s.Store.GetEntityPool(context.Background(), entity, "dummy-pool-id")
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("fetching pool: parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestDeleteOrganizationPool() {
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
|
||||
}
|
||||
|
||||
err = s.Store.DeleteOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, pool.ID)
|
||||
err = s.Store.DeleteEntityPool(context.Background(), entity, pool.ID)
|
||||
|
||||
s.Require().Nil(err)
|
||||
_, err = s.Store.GetOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, pool.ID)
|
||||
_, err = s.Store.GetEntityPool(context.Background(), entity, pool.ID)
|
||||
s.Require().Equal("fetching pool: finding pool: not found", err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestDeleteOrganizationPoolInvalidOrgID() {
|
||||
err := s.Store.DeleteOrganizationPool(context.Background(), "dummy-org-id", "dummy-pool-id")
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-org-id",
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
err := s.Store.DeleteEntityPool(context.Background(), entity, "dummy-pool-id")
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("looking up org pool: parsing id: invalid request", err.Error())
|
||||
s.Require().Equal("parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestDeleteOrganizationPoolDBDeleteErr() {
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
|
||||
}
|
||||
|
|
@ -741,7 +776,11 @@ func (s *OrgTestSuite) TestDeleteOrganizationPoolDBDeleteErr() {
|
|||
}
|
||||
|
||||
func (s *OrgTestSuite) TestListOrgInstances() {
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
|
||||
}
|
||||
|
|
@ -769,7 +808,11 @@ func (s *OrgTestSuite) TestListOrgInstancesInvalidOrgID() {
|
|||
}
|
||||
|
||||
func (s *OrgTestSuite) TestUpdateOrganizationPool() {
|
||||
pool, err := s.Store.CreateOrganizationPool(context.Background(), s.Fixtures.Orgs[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Orgs[0].ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func (s *sqlDatabase) ListAllPools(_ context.Context) ([]params.Pool, error) {
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetPoolByID(ctx context.Context, poolID string) (params.Pool, error) {
|
||||
func (s *sqlDatabase) GetPoolByID(_ context.Context, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getPoolByID(s.conn, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool by ID")
|
||||
|
|
@ -66,7 +66,7 @@ func (s *sqlDatabase) GetPoolByID(ctx context.Context, poolID string) (params.Po
|
|||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) DeletePoolByID(ctx context.Context, poolID string) error {
|
||||
func (s *sqlDatabase) DeletePoolByID(_ context.Context, poolID string) error {
|
||||
pool, err := s.getPoolByID(s.conn, poolID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetching pool by ID")
|
||||
|
|
@ -79,7 +79,7 @@ func (s *sqlDatabase) DeletePoolByID(ctx context.Context, poolID string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) getEntityPool(_ context.Context, entityType params.GithubEntityType, entityID, poolID string, preload ...string) (Pool, error) {
|
||||
func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityType, entityID, poolID string, preload ...string) (Pool, error) {
|
||||
if entityID == "" {
|
||||
return Pool{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id")
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ func (s *sqlDatabase) getEntityPool(_ context.Context, entityType params.GithubE
|
|||
return Pool{}, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
|
||||
}
|
||||
|
||||
q := s.conn
|
||||
q := tx
|
||||
if len(preload) > 0 {
|
||||
for _, item := range preload {
|
||||
q = q.Preload(item)
|
||||
|
|
@ -233,7 +233,7 @@ func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType par
|
|||
return pools, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) CreateEntityPool(ctx context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error) {
|
||||
func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error) {
|
||||
if len(param.Tags) == 0 {
|
||||
return params.Pool{}, runnerErrors.NewBadRequestError("no tags specified")
|
||||
}
|
||||
|
|
@ -258,7 +258,7 @@ func (s *sqlDatabase) CreateEntityPool(ctx context.Context, entity params.Github
|
|||
|
||||
entityID, err := uuid.Parse(entity.ID)
|
||||
if err != nil {
|
||||
return params.Pool{}, fmt.Errorf("parsing entity ID: %w", err)
|
||||
return params.Pool{}, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
|
||||
}
|
||||
|
||||
switch entity.EntityType {
|
||||
|
|
@ -270,9 +270,14 @@ func (s *sqlDatabase) CreateEntityPool(ctx context.Context, entity params.Github
|
|||
newPool.EnterpriseID = &entityID
|
||||
}
|
||||
err = s.conn.Transaction(func(tx *gorm.DB) error {
|
||||
ok, err := s.hasGithubEntity(tx, entity.EntityType, entity.ID)
|
||||
if err != nil || !ok {
|
||||
return errors.Wrap(err, "checking entity existence")
|
||||
}
|
||||
|
||||
if _, err := s.getEntityPoolByUniqueFields(tx, entity, newPool.ProviderName, newPool.Image, newPool.Flavor); err != nil {
|
||||
if !errors.Is(err, runnerErrors.ErrNotFound) {
|
||||
return fmt.Errorf("checking for existing pool: %w", err)
|
||||
return errors.Wrap(err, "checking pool existence")
|
||||
}
|
||||
} else {
|
||||
return runnerErrors.NewConflictError("pool with the same image and flavor already exists on this provider")
|
||||
|
|
@ -282,25 +287,25 @@ func (s *sqlDatabase) CreateEntityPool(ctx context.Context, entity params.Github
|
|||
for _, val := range param.Tags {
|
||||
t, err := s.getOrCreateTag(tx, val)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating tag: %w", err)
|
||||
return errors.Wrap(err, "creating tag")
|
||||
}
|
||||
tags = append(tags, t)
|
||||
}
|
||||
|
||||
q := tx.Create(&newPool)
|
||||
if q.Error != nil {
|
||||
return fmt.Errorf("creating pool: %w", q.Error)
|
||||
return errors.Wrap(q.Error, "creating pool")
|
||||
}
|
||||
|
||||
for i := range tags {
|
||||
if err := tx.Model(&newPool).Association("Tags").Append(&tags[i]); err != nil {
|
||||
return fmt.Errorf("associating tags: %w", err)
|
||||
return errors.Wrap(err, "associating tags")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return params.Pool{}, fmt.Errorf("creating pool: %w", err)
|
||||
return params.Pool{}, errors.Wrap(err, "creating pool")
|
||||
}
|
||||
|
||||
pool, err := s.getPoolByID(s.conn, newPool.ID.String(), "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
|
|
@ -311,22 +316,53 @@ func (s *sqlDatabase) CreateEntityPool(ctx context.Context, entity params.Github
|
|||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) {
|
||||
return params.Pool{}, nil
|
||||
func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, entity.EntityType, entity.ID, poolID, "Tags", "Instances")
|
||||
if err != nil {
|
||||
return params.Pool{}, fmt.Errorf("fetching pool: %w", err)
|
||||
}
|
||||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) DeleteEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) error {
|
||||
func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEntity, poolID string) error {
|
||||
entityID, err := uuid.Parse(entity.ID)
|
||||
if err != nil {
|
||||
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
|
||||
}
|
||||
|
||||
poolUUID, err := uuid.Parse(poolID)
|
||||
if err != nil {
|
||||
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing pool id")
|
||||
}
|
||||
var fieldName string
|
||||
switch entity.EntityType {
|
||||
case params.GithubEntityTypeRepository:
|
||||
fieldName = entityTypeRepoName
|
||||
case params.GithubEntityTypeOrganization:
|
||||
fieldName = entityTypeOrgName
|
||||
case params.GithubEntityTypeEnterprise:
|
||||
fieldName = entityTypeEnterpriseName
|
||||
default:
|
||||
return fmt.Errorf("invalid entityType: %v", entity.EntityType)
|
||||
}
|
||||
condition := fmt.Sprintf("id = ? and %s = ?", fieldName)
|
||||
if err := s.conn.Unscoped().Where(condition, poolUUID, entityID).Delete(&Pool{}).Error; err != nil {
|
||||
return errors.Wrap(err, "removing pool")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) UpdateEntityPool(ctx context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
fmt.Printf("UpdateEntityPool: %v %v %v\n", entity, poolID, param)
|
||||
return params.Pool{}, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) ListEntityPools(ctx context.Context, entity params.GithubEntity) ([]params.Pool, error) {
|
||||
func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.GithubEntity) ([]params.Pool, error) {
|
||||
fmt.Println(entity)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) ListEntityInstances(ctx context.Context, entity params.GithubEntity) ([]params.Instance, error) {
|
||||
func (s *sqlDatabase) ListEntityInstances(_ context.Context, entity params.GithubEntity) ([]params.Instance, error) {
|
||||
fmt.Println(entity)
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,12 +66,16 @@ func (s *PoolsTestSuite) SetupTest() {
|
|||
s.FailNow(fmt.Sprintf("failed to create org: %s", err))
|
||||
}
|
||||
|
||||
entity := params.GithubEntity{
|
||||
ID: org.ID,
|
||||
EntityType: params.GithubEntityTypeOrganization,
|
||||
}
|
||||
// create some pool objects in the database, for testing purposes
|
||||
orgPools := []params.Pool{}
|
||||
for i := 1; i <= 3; i++ {
|
||||
pool, err := db.CreateOrganizationPool(
|
||||
pool, err := db.CreateEntityPool(
|
||||
context.Background(),
|
||||
org.ID,
|
||||
entity,
|
||||
params.CreatePoolParams{
|
||||
ProviderName: "test-provider",
|
||||
MaxRunners: 4,
|
||||
|
|
|
|||
|
|
@ -235,16 +235,16 @@ func (s *sqlDatabase) ListRepoPools(ctx context.Context, repoID string) ([]param
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) GetRepositoryPool(ctx context.Context, repoID, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeRepository, repoID, poolID, "Tags", "Instances")
|
||||
func (s *sqlDatabase) GetRepositoryPool(_ context.Context, repoID, poolID string) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeRepository, repoID, poolID, "Tags", "Instances")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
return s.sqlToCommonPool(pool)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) DeleteRepositoryPool(ctx context.Context, repoID, poolID string) error {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeRepository, repoID, poolID)
|
||||
func (s *sqlDatabase) DeleteRepositoryPool(_ context.Context, repoID, poolID string) error {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeRepository, repoID, poolID)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "looking up repo pool")
|
||||
}
|
||||
|
|
@ -274,13 +274,13 @@ func (s *sqlDatabase) ListRepoInstances(ctx context.Context, repoID string) ([]p
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) UpdateRepositoryPool(ctx context.Context, repoID, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(ctx, params.GithubEntityTypeRepository, repoID, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
func (s *sqlDatabase) UpdateRepositoryPool(_ context.Context, repoID, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
pool, err := s.getEntityPool(s.conn, params.GithubEntityTypeRepository, repoID, poolID, "Tags", "Instances", "Enterprise", "Organization", "Repository")
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching pool")
|
||||
}
|
||||
|
||||
return s.updatePool(pool, param)
|
||||
return s.updatePool(s.conn, pool, param)
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) getRepo(_ context.Context, owner, name string) (Repository, error) {
|
||||
|
|
|
|||
|
|
@ -443,7 +443,11 @@ func (s *RepoTestSuite) TestGetRepositoryByIDDBDecryptingErr() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestCreateRepositoryPool() {
|
||||
pool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().Nil(err)
|
||||
repo, err := s.Store.GetRepositoryByID(context.Background(), s.Fixtures.Repos[0].ID)
|
||||
|
|
@ -459,18 +463,25 @@ func (s *RepoTestSuite) TestCreateRepositoryPool() {
|
|||
|
||||
func (s *RepoTestSuite) TestCreateRepositoryPoolMissingTags() {
|
||||
s.Fixtures.CreatePoolParams.Tags = []string{}
|
||||
|
||||
_, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
_, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("no tags specified", err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestCreateRepositoryPoolInvalidRepoID() {
|
||||
_, err := s.Store.CreateRepositoryPool(context.Background(), "dummy-repo-id", s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-repo-id",
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
_, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("fetching repo: parsing id: invalid request", err.Error())
|
||||
s.Require().Equal("parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestCreateRepositoryPoolDBCreateErr() {
|
||||
|
|
@ -691,10 +702,14 @@ func (s *RepoTestSuite) TestCreateRepositoryPoolDBFetchPoolErr() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestListRepoPools() {
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
repoPools := []params.Pool{}
|
||||
for i := 1; i <= 2; i++ {
|
||||
s.Fixtures.CreatePoolParams.Flavor = fmt.Sprintf("test-flavor-%d", i)
|
||||
pool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create repo pool: %v", err))
|
||||
}
|
||||
|
|
@ -715,46 +730,66 @@ func (s *RepoTestSuite) TestListRepoPoolsInvalidRepoID() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestGetRepositoryPool() {
|
||||
pool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create repo pool: %v", err))
|
||||
}
|
||||
|
||||
repoPool, err := s.Store.GetRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, pool.ID)
|
||||
repoPool, err := s.Store.GetEntityPool(context.Background(), entity, pool.ID)
|
||||
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(repoPool.ID, pool.ID)
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestGetRepositoryPoolInvalidRepoID() {
|
||||
_, err := s.Store.GetRepositoryPool(context.Background(), "dummy-repo-id", "dummy-pool-id")
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-repo-id",
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
_, err := s.Store.GetEntityPool(context.Background(), entity, "dummy-pool-id")
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("fetching pool: parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestDeleteRepositoryPool() {
|
||||
pool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create repo pool: %v", err))
|
||||
}
|
||||
|
||||
err = s.Store.DeleteRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, pool.ID)
|
||||
err = s.Store.DeleteEntityPool(context.Background(), entity, pool.ID)
|
||||
|
||||
s.Require().Nil(err)
|
||||
_, err = s.Store.GetOrganizationPool(context.Background(), s.Fixtures.Repos[0].ID, pool.ID)
|
||||
_, err = s.Store.GetEntityPool(context.Background(), entity, pool.ID)
|
||||
s.Require().Equal("fetching pool: finding pool: not found", err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestDeleteRepositoryPoolInvalidRepoID() {
|
||||
err := s.Store.DeleteRepositoryPool(context.Background(), "dummy-repo-id", "dummy-pool-id")
|
||||
entity := params.GithubEntity{
|
||||
ID: "dummy-repo-id",
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
err := s.Store.DeleteEntityPool(context.Background(), entity, "dummy-pool-id")
|
||||
|
||||
s.Require().NotNil(err)
|
||||
s.Require().Equal("looking up repo pool: parsing id: invalid request", err.Error())
|
||||
s.Require().Equal("parsing id: invalid request", err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestDeleteRepositoryPoolDBDeleteErr() {
|
||||
pool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create repo pool: %v", err))
|
||||
}
|
||||
|
|
@ -778,7 +813,11 @@ func (s *RepoTestSuite) TestDeleteRepositoryPoolDBDeleteErr() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestListRepoInstances() {
|
||||
pool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
pool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create repo pool: %v", err))
|
||||
}
|
||||
|
|
@ -806,7 +845,11 @@ func (s *RepoTestSuite) TestListRepoInstancesInvalidRepoID() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestUpdateRepositoryPool() {
|
||||
repoPool, err := s.Store.CreateRepositoryPool(context.Background(), s.Fixtures.Repos[0].ID, s.Fixtures.CreatePoolParams)
|
||||
entity := params.GithubEntity{
|
||||
ID: s.Fixtures.Repos[0].ID,
|
||||
EntityType: params.GithubEntityTypeRepository,
|
||||
}
|
||||
repoPool, err := s.Store.CreateEntityPool(context.Background(), entity, s.Fixtures.CreatePoolParams)
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("cannot create repo pool: %v", err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ func (s *sqlDatabase) getOrCreateTag(tx *gorm.DB, tagName string) (Tag, error) {
|
|||
return newTag, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) updatePool(pool Pool, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
func (s *sqlDatabase) updatePool(tx *gorm.DB, pool Pool, param params.UpdatePoolParams) (params.Pool, error) {
|
||||
if param.Enabled != nil && pool.Enabled != *param.Enabled {
|
||||
pool.Enabled = *param.Enabled
|
||||
}
|
||||
|
|
@ -346,21 +346,21 @@ func (s *sqlDatabase) updatePool(pool Pool, param params.UpdatePoolParams) (para
|
|||
pool.Priority = *param.Priority
|
||||
}
|
||||
|
||||
if q := s.conn.Save(&pool); q.Error != nil {
|
||||
if q := tx.Save(&pool); q.Error != nil {
|
||||
return params.Pool{}, errors.Wrap(q.Error, "saving database entry")
|
||||
}
|
||||
|
||||
tags := []Tag{}
|
||||
if param.Tags != nil && len(param.Tags) > 0 {
|
||||
for _, val := range param.Tags {
|
||||
t, err := s.getOrCreateTag(s.conn, val)
|
||||
t, err := s.getOrCreateTag(tx, val)
|
||||
if err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "fetching tag")
|
||||
}
|
||||
tags = append(tags, t)
|
||||
}
|
||||
|
||||
if err := s.conn.Model(&pool).Association("Tags").Replace(&tags); err != nil {
|
||||
if err := tx.Model(&pool).Association("Tags").Replace(&tags); err != nil {
|
||||
return params.Pool{}, errors.Wrap(err, "replacing tags")
|
||||
}
|
||||
}
|
||||
|
|
@ -391,3 +391,30 @@ func (s *sqlDatabase) getPoolByID(tx *gorm.DB, poolID string, preload ...string)
|
|||
}
|
||||
return pool, nil
|
||||
}
|
||||
|
||||
func (s *sqlDatabase) hasGithubEntity(tx *gorm.DB, entityType params.GithubEntityType, entityID string) (bool, error) {
|
||||
u, err := uuid.Parse(entityID)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
|
||||
}
|
||||
var q *gorm.DB
|
||||
switch entityType {
|
||||
case params.GithubEntityTypeRepository:
|
||||
q = tx.Model(&Repository{}).Where("id = ?", u)
|
||||
case params.GithubEntityTypeOrganization:
|
||||
q = tx.Model(&Organization{}).Where("id = ?", u)
|
||||
case params.GithubEntityTypeEnterprise:
|
||||
q = tx.Model(&Enterprise{}).Where("id = ?", u)
|
||||
default:
|
||||
return false, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
|
||||
}
|
||||
|
||||
var entity interface{}
|
||||
if err := q.First(entity).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, errors.Wrap(runnerErrors.ErrNotFound, "entity not found")
|
||||
}
|
||||
return false, errors.Wrap(err, "fetching entity from database")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue