Mohammed Nafees hace 4 años
padre
commit
5245812aa5
Se han modificado 2 ficheros con 109 adiciones y 0 borrados
  1. 97 0
      internal/repository/test/auth.go
  2. 12 0
      internal/repository/test/repository.go

+ 97 - 0
internal/repository/test/auth.go

@@ -606,3 +606,100 @@ func (repo *AzureIntegrationRepository) ListAzureIntegrationsByProjectID(
 ) ([]*ints.AzureIntegration, error) {
 	panic("unimplemented")
 }
+
+type GitlabIntegrationRepository struct {
+	canQuery           bool
+	gitlabIntegrations []*ints.GitlabIntegration
+}
+
+func NewGitlabIntegrationRepository(canQuery bool) repository.GitlabIntegrationRepository {
+	return &GitlabIntegrationRepository{
+		canQuery,
+		[]*ints.GitlabIntegration{},
+	}
+}
+
+func (repo *GitlabIntegrationRepository) CreateGitlabIntegration(gi *ints.GitlabIntegration) (*ints.GitlabIntegration, error) {
+	if !repo.canQuery {
+		return nil, errors.New("cannot write database")
+	}
+
+	repo.gitlabIntegrations = append(repo.gitlabIntegrations, gi)
+	gi.ID = uint(len(repo.gitlabIntegrations))
+
+	return gi, nil
+}
+
+func (repo *GitlabIntegrationRepository) ReadGitlabIntegration(projectID, id uint) (*ints.GitlabIntegration, error) {
+	if !repo.canQuery {
+		return nil, errors.New("Cannot read from database")
+	}
+
+	if int(id-1) >= len(repo.gitlabIntegrations) || repo.gitlabIntegrations[id-1] == nil {
+		return nil, gorm.ErrRecordNotFound
+	}
+
+	index := int(id - 1)
+	return repo.gitlabIntegrations[index], nil
+}
+func (repo *GitlabIntegrationRepository) ListGitlabIntegrationsByProjectID(projectID uint) ([]*ints.GitlabIntegration, error) {
+	if !repo.canQuery {
+		return nil, errors.New("Cannot read from database")
+	}
+
+	res := make([]*ints.GitlabIntegration, 0)
+
+	for _, gitlabAM := range repo.gitlabIntegrations {
+		if gitlabAM.ProjectID == projectID {
+			res = append(res, gitlabAM)
+		}
+	}
+
+	return res, nil
+}
+
+type GitlabAppOAuthIntegrationRepository struct {
+	canQuery                   bool
+	gitlabAppOAuthIntegrations []*ints.GitlabAppOAuthIntegration
+}
+
+func NewGitlabAppOAuthIntegrationRepository(canQuery bool) repository.GitlabAppOAuthIntegrationRepository {
+	return &GitlabAppOAuthIntegrationRepository{
+		canQuery,
+		[]*ints.GitlabAppOAuthIntegration{},
+	}
+}
+
+func (repo *GitlabAppOAuthIntegrationRepository) CreateGitlabAppOAuthIntegration(
+	gi *ints.GitlabAppOAuthIntegration,
+) (*ints.GitlabAppOAuthIntegration, error) {
+	if !repo.canQuery {
+		return nil, errors.New("cannot write database")
+	}
+
+	repo.gitlabAppOAuthIntegrations = append(repo.gitlabAppOAuthIntegrations, gi)
+	gi.ID = uint(len(repo.gitlabAppOAuthIntegrations))
+
+	return gi, nil
+}
+
+func (repo *GitlabAppOAuthIntegrationRepository) ReadGitlabAppOAuthIntegration(
+	userID, projectID, integrationID uint,
+) (*ints.GitlabAppOAuthIntegration, error) {
+	panic("not implemented")
+}
+
+func (repo *GitlabAppOAuthIntegrationRepository) UpdateGitlabAppOAuthIntegration(gi *ints.GitlabAppOAuthIntegration) (*ints.GitlabAppOAuthIntegration, error) {
+	if !repo.canQuery {
+		return nil, errors.New("Cannot write database")
+	}
+
+	if int(gi.ID-1) >= len(repo.gitlabAppOAuthIntegrations) || repo.gitlabAppOAuthIntegrations[gi.ID-1] == nil {
+		return nil, gorm.ErrRecordNotFound
+	}
+
+	index := int(gi.ID - 1)
+	repo.gitlabAppOAuthIntegrations[index] = gi
+
+	return gi, nil
+}

+ 12 - 0
internal/repository/test/repository.go

@@ -29,6 +29,8 @@ type TestRepository struct {
 	azIntegration             repository.AzureIntegrationRepository
 	githubAppInstallation     repository.GithubAppInstallationRepository
 	githubAppOAuthIntegration repository.GithubAppOAuthIntegrationRepository
+	gitlabIntegration         repository.GitlabIntegrationRepository
+	gitlabAppOAuthIntegration repository.GitlabAppOAuthIntegrationRepository
 	slackIntegration          repository.SlackIntegrationRepository
 	notificationConfig        repository.NotificationConfigRepository
 	jobNotificationConfig     repository.JobNotificationConfigRepository
@@ -139,6 +141,14 @@ func (t *TestRepository) GithubAppOAuthIntegration() repository.GithubAppOAuthIn
 	return t.githubAppOAuthIntegration
 }
 
+func (t *TestRepository) GitlabIntegration() repository.GitlabIntegrationRepository {
+	return t.gitlabIntegration
+}
+
+func (t *TestRepository) GitlabAppOAuthIntegration() repository.GitlabAppOAuthIntegrationRepository {
+	return t.gitlabAppOAuthIntegration
+}
+
 func (t *TestRepository) SlackIntegration() repository.SlackIntegrationRepository {
 	return t.slackIntegration
 }
@@ -215,6 +225,8 @@ func NewRepository(canQuery bool, failingMethods ...string) repository.Repositor
 		azIntegration:             NewAzureIntegrationRepository(),
 		githubAppInstallation:     NewGithubAppInstallationRepository(canQuery),
 		githubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(canQuery),
+		gitlabIntegration:         NewGitlabIntegrationRepository(canQuery),
+		gitlabAppOAuthIntegration: NewGitlabAppOAuthIntegrationRepository(canQuery),
 		slackIntegration:          NewSlackIntegrationRepository(canQuery),
 		notificationConfig:        NewNotificationConfigRepository(canQuery),
 		jobNotificationConfig:     NewJobNotificationConfigRepository(canQuery),