Skip to content

Commit 5fcfa73

Browse files
committed
fix e2e
Signed-off-by: Balazs Nadasdi <balazs@weave.works>
1 parent 1613700 commit 5fcfa73

File tree

12 files changed

+51
-29
lines changed

12 files changed

+51
-29
lines changed

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ resources:
66
images:
77
- name: controller
88
newName: ghcr.io/weaveworks/pipeline-controller
9-
newTag: latest
9+
newTag: v0.0.30-5-g75c5b9f-dirty

e2e/promotion_pull_request_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
//go:build e2e
22

3-
package e2e
3+
package e2e_test
44

55
import (
66
"bytes"
77
"context"
88
"encoding/json"
99
"fmt"
10+
"io"
11+
"log"
12+
"strings"
13+
"testing"
14+
"time"
15+
1016
"github.com/fluxcd/go-git-providers/gitprovider"
1117
"github.com/fluxcd/helm-controller/api/v2beta1"
1218
"github.com/fluxcd/pkg/runtime/logger"
1319
"github.com/go-logr/logr"
14-
"github.com/google/go-github/v47/github"
20+
"github.com/google/go-github/v49/github"
1521
"github.com/hashicorp/go-uuid"
1622
. "github.com/onsi/gomega"
1723
"github.com/weaveworks/pipeline-controller/api/v1alpha1"
1824
"github.com/weaveworks/pipeline-controller/internal/testingutils"
1925
"github.com/weaveworks/pipeline-controller/pkg/conditions"
2026
"github.com/weaveworks/pipeline-controller/server/strategy/pullrequest"
2127
gitlab2 "github.com/xanzy/go-gitlab"
22-
"io"
2328
corev1 "k8s.io/api/core/v1"
2429
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2530
"k8s.io/apimachinery/pkg/types"
2631
"k8s.io/client-go/kubernetes"
27-
"log"
2832
"sigs.k8s.io/controller-runtime/pkg/client"
29-
"strings"
30-
"testing"
31-
"time"
3233
)
3334

3435
const (
@@ -120,7 +121,7 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel
120121
return fmt.Errorf("cannot delete branch for pipeline without promotion")
121122
}
122123

123-
pullRequestPromotion := promotion.PullRequest
124+
pullRequestPromotion := promotion.Strategy.PullRequest
124125
if pullRequestPromotion == nil {
125126
return fmt.Errorf("cannot delete branch for pipelines without pullRequest")
126127
}
@@ -154,30 +155,29 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel
154155
}
155156
//TODO it should not be needed - gitlab ggp issue
156157
userRepoRef.Domain = gitProviderClient.SupportedDomain()
157-
userRepo, err := gitProviderClient.UserRepositories().Get(ctx, *userRepoRef)
158-
if err != nil {
159-
return fmt.Errorf("could not get repository: %w", err)
160-
}
161-
clientRaw := gitProviderClient.Raw()
162158
//TODO contribute me to ggp
163159
switch pullRequestPromotion.Type {
164160
case v1alpha1.Github:
165161
//cannot delete github branch so renaming
166-
gClient := clientRaw.(*github.Client)
162+
clientRaw := gitProviderClient.RawClient().(gitprovider.Client).Raw().(*github.Client)
167163
generatedUuid, err := uuid.GenerateUUID()
168164
if err != nil {
169165
return fmt.Errorf("could not generate uuid: %w", err)
170166
}
171167
owner := userRepoRef.UserLogin
172168
repo := userRepoRef.RepositoryName
173-
_, _, err = gClient.Repositories.RenameBranch(ctx, owner, repo, branchName, fmt.Sprintf("%s-%s", branchName, generatedUuid))
169+
_, _, err = clientRaw.Repositories.RenameBranch(ctx, owner, repo, branchName, fmt.Sprintf("%s-%s", branchName, generatedUuid))
174170
if err != nil {
175171
return fmt.Errorf("could not rename branch: %w", err)
176172
}
177173
case v1alpha1.Gitlab:
178-
gitlabProject := userRepo.APIObject().(*gitlab2.Project)
179-
gClient := clientRaw.(*gitlab2.Client)
180-
_, err := gClient.Branches.DeleteBranch(gitlabProject.ID, branchName, nil)
174+
clientRaw := gitProviderClient.RawClient().(gitprovider.Client).Raw().(*gitlab2.Client)
175+
glRepo, err := gitProviderClient.RawClient().(gitprovider.Client).UserRepositories().Get(ctx, *userRepoRef)
176+
if err != nil {
177+
return fmt.Errorf("could not delete branch: %w", err)
178+
}
179+
gitlabProject := glRepo.APIObject().(*gitlab2.Project)
180+
_, err = clientRaw.Branches.DeleteBranch(gitlabProject.ID, branchName, nil)
181181
if err != nil {
182182
return fmt.Errorf("could not delete gitlab branch: %w", err)
183183
}

e2e/suite_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
//go:build e2e
22

3-
package e2e
3+
package e2e_test
44

55
import (
66
"context"
7+
"log"
8+
"os"
9+
"path/filepath"
10+
"testing"
11+
712
"github.com/fluxcd/helm-controller/api/v2beta1"
813
"github.com/onsi/gomega"
914
clusterctrlv1alpha1 "github.com/weaveworks/cluster-controller/api/v1alpha1"
1015
"k8s.io/client-go/kubernetes"
1116
"k8s.io/client-go/kubernetes/scheme"
12-
"log"
13-
"os"
14-
"path/filepath"
1517
"sigs.k8s.io/controller-runtime/pkg/client"
1618
"sigs.k8s.io/controller-runtime/pkg/envtest"
17-
"testing"
1819

1920
"github.com/weaveworks/pipeline-controller/api/v1alpha1"
2021
)

e2e/testdata/pipelines/github/pipeline.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ spec:
1919
strategy:
2020
pull-request:
2121
type: "github"
22+
baseBranch: "main"
2223
url: "https://github.com/weaveworks/pipeline-controller-e2e"
2324
secretRef:
2425
name: "github-promotion-credentials"

e2e/testdata/pipelines/gitlab/pipeline.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ spec:
1919
strategy:
2020
pull-request:
2121
type: "gitlab"
22+
baseBranch: "main"
2223
url: "https://gitlab.git.dev.weave.works/pipeline-controller/pipeline-controller-e2e"
2324
secretRef:
24-
name: "gitlab-ee-promotion-credentials"
25+
name: "gitlab-promotion-credentials"

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/go-logr/stdr v1.2.2
2626
github.com/golang/mock v1.6.0
2727
github.com/google/go-github/v32 v32.1.0
28-
github.com/google/go-github/v47 v47.1.0
28+
github.com/google/go-github/v49 v49.1.0
2929
github.com/hashicorp/go-uuid v1.0.3
3030
github.com/jenkins-x/go-scm v1.13.12
3131
github.com/onsi/gomega v1.27.4
@@ -91,7 +91,6 @@ require (
9191
github.com/google/gnostic v0.6.9 // indirect
9292
github.com/google/go-cmp v0.5.9 // indirect
9393
github.com/google/go-containerregistry v0.11.0 // indirect
94-
github.com/google/go-github/v49 v49.1.0 // indirect
9594
github.com/google/go-querystring v1.1.0 // indirect
9695
github.com/google/gofuzz v1.2.0 // indirect
9796
github.com/google/uuid v1.3.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ github.com/google/go-containerregistry v0.11.0 h1:Xt8x1adcREjFcmDoDK8OdOsjxu90PH
268268
github.com/google/go-containerregistry v0.11.0/go.mod h1:BBaYtsHPHA42uEgAvd/NejvAfPSlz281sJWqupjSxfk=
269269
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
270270
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
271-
github.com/google/go-github/v47 v47.1.0 h1:Cacm/WxQBOa9lF0FT0EMjZ2BWMetQ1TQfyurn4yF1z8=
272-
github.com/google/go-github/v47 v47.1.0/go.mod h1:VPZBXNbFSJGjyjFRUKo9vZGawTajnWzC/YjGw/oFKi0=
273271
github.com/google/go-github/v49 v49.1.0 h1:LFkMgawGQ8dfzWLH/rNE0b3u1D3n6/dw7ZmrN3b+YFY=
274272
github.com/google/go-github/v49 v49.1.0/go.mod h1:MUUzHPrhGniB6vUKa27y37likpipzG+BXXJbG04J334=
275273
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=

internal/git/azure.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,7 @@ func (p *AzureDevOpsProvider) Name() string {
234234
func (p *AzureDevOpsProvider) SupportedDomain() string {
235235
return ""
236236
}
237+
238+
func (p *AzureDevOpsProvider) RawClient() interface{} {
239+
return p.client
240+
}

internal/git/bitbucket_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,7 @@ func (p *BitBucketServerProvider) Name() string {
174174
func (p *BitBucketServerProvider) SupportedDomain() string {
175175
return p.client.SupportedDomain()
176176
}
177+
178+
func (p *BitBucketServerProvider) RawClient() interface{} {
179+
return p.client
180+
}

internal/git/github.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,18 @@ func (p *GitHubProvider) UpdatePullRequest(ctx context.Context, repoURL string,
164164
})
165165
}
166166

167+
func (p *GitHubProvider) DeleteBranch(ctx context.Context, repoURL, branchName string) error {
168+
return nil
169+
}
170+
167171
func (p *GitHubProvider) Name() string {
168172
return GitHubProviderName
169173
}
170174

171175
func (p *GitHubProvider) SupportedDomain() string {
172176
return p.client.SupportedDomain()
173177
}
178+
179+
func (p *GitHubProvider) RawClient() interface{} {
180+
return p.client
181+
}

0 commit comments

Comments
 (0)