99 "fmt"
1010 "github.com/fluxcd/go-git-providers/gitprovider"
1111 "github.com/fluxcd/helm-controller/api/v2beta1"
12+ "github.com/fluxcd/pkg/runtime/logger"
13+ "github.com/go-logr/logr"
1214 "github.com/google/go-github/v47/github"
1315 "github.com/hashicorp/go-uuid"
1416 . "github.com/onsi/gomega"
@@ -37,6 +39,7 @@ const (
3739
3840func TestPullRequestPromotions (t * testing.T ) {
3941 g := testingutils .NewGomegaWithT (t )
42+ log := logger .NewLogger (logger.Options {})
4043
4144 tests := []struct {
4245 name string
@@ -56,16 +59,15 @@ func TestPullRequestPromotions(t *testing.T) {
5659 "6.0.0" ,
5760 "6.0.1" ,
5861 },
59- //TODO enable me when https://github.com/weaveworks/pipeline-controller/issues/132 is closed
60- //{
61- // "can promote gitlab",
62- // "podinfo-gitlab",
63- // "flux-system",
64- // "promotion-flux-system-podinfo-gitlab-prod",
65- // "prod",
66- // "6.0.0",
67- // "6.0.1",
68- //},
62+ {
63+ "can promote gitlab" ,
64+ "podinfo-gitlab" ,
65+ "flux-system" ,
66+ "promotion-flux-system-podinfo-gitlab-prod" ,
67+ "prod" ,
68+ "6.0.0" ,
69+ "6.0.1" ,
70+ },
6971 }
7072
7173 g .SetDefaultEventuallyTimeout (defaultTimeout )
@@ -82,15 +84,15 @@ func TestPullRequestPromotions(t *testing.T) {
8284
8385 //cleanup promotion
8486 t .Cleanup (func () {
85- log .Println ("cleaning test" )
87+ log .Info ("cleaning test" )
8688 //restore helm release version
8789 released := releaseNewVersion (g , k8sClient , helmRelease , promotion .currentVersion )
8890 g .Expect (released ).To (BeTrue ())
8991 helmRelease , err = ensureHelmRelease (g , pipeline , k8sClient , promotion .currentVersion )
9092 //delete git branch
91- err := deleteGitBranchByName (context .Background (), g , k8sClient , pipeline , promotion .branchName )
93+ err := deleteGitBranchByName (context .Background (), g , k8sClient , pipeline , promotion .branchName , log )
9294 if err != nil {
93- log .Fatalf ( "could not delete branch %s" , err )
95+ log .Error ( err , "could not delete branch" )
9496 }
9597 })
9698
@@ -110,7 +112,7 @@ func TestPullRequestPromotions(t *testing.T) {
110112 deletePodsByNamespaceAndLabel (g , "flux-system" , "app=notification-controller" )
111113}
112114
113- func deleteGitBranchByName (ctx context.Context , g * WithT , c client.Client , pipeline v1alpha1.Pipeline , branchName string ) error {
115+ func deleteGitBranchByName (ctx context.Context , g * WithT , c client.Client , pipeline v1alpha1.Pipeline , branchName string , log logr. Logger ) error {
114116 var secret corev1.Secret
115117
116118 promotion := pipeline .Spec .Promotion
@@ -131,26 +133,27 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel
131133 g .Eventually (func () bool {
132134 //get secret
133135 if err := c .Get (ctx , client.ObjectKey {Namespace : pipeline .Namespace , Name : secretName }, & secret ); err != nil {
134- log .Printf ( "failed to fetch Secret: %s" , err )
136+ log .Error ( err , "failed to fetch Secret" )
135137 return false
136138 }
137139 return true
138140 }).Should (BeTrue ())
139141
140- hostname := userRepoRef .Domain
141142 tokenString := string (secret .Data ["token" ])
142143 provider := pullrequest.GitProviderConfig {
143144 Token : tokenString ,
144145 TokenType : "oauth2" ,
145146 Type : pullRequestPromotion .Type ,
146- Hostname : hostname ,
147+ Domain : userRepoRef . Domain ,
147148 DestructiveCalls : false ,
148149 }
149150
150- gitProviderClient , err := pullrequest .NewGitProviderClientFactory ()(provider )
151+ gitProviderClient , err := pullrequest .NewGitProviderClientFactory (log )(provider )
151152 if err != nil {
152153 return fmt .Errorf ("could not create git provider client: %w" , err )
153154 }
155+ //TODO it should not be needed - gitlab ggp issue
156+ userRepoRef .Domain = gitProviderClient .SupportedDomain ()
154157 userRepo , err := gitProviderClient .UserRepositories ().Get (ctx , * userRepoRef )
155158 if err != nil {
156159 return fmt .Errorf ("could not get repository: %w" , err )
@@ -167,19 +170,17 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel
167170 }
168171 owner := userRepoRef .UserLogin
169172 repo := userRepoRef .RepositoryName
170- _ , r , err : = gClient .Repositories .RenameBranch (ctx , owner , repo , branchName , fmt .Sprintf ("%s-%s" , branchName , generatedUuid ))
173+ _ , _ , err = gClient .Repositories .RenameBranch (ctx , owner , repo , branchName , fmt .Sprintf ("%s-%s" , branchName , generatedUuid ))
171174 if err != nil {
172175 return fmt .Errorf ("could not rename branch: %w" , err )
173176 }
174- log .Println ("branch delete response" , r )
175177 case v1alpha1 .Gitlab :
176178 gitlabProject := userRepo .APIObject ().(* gitlab2.Project )
177179 gClient := clientRaw .(* gitlab2.Client )
178- deletedBranch , err := gClient .Branches .DeleteBranch (gitlabProject .ID , branchName , nil )
180+ _ , err := gClient .Branches .DeleteBranch (gitlabProject .ID , branchName , nil )
179181 if err != nil {
180182 return fmt .Errorf ("could not delete gitlab branch: %w" , err )
181183 }
182- log .Println ("branch delete response" , deletedBranch )
183184 }
184185 return nil
185186}
0 commit comments