9
9
"fmt"
10
10
"github.com/fluxcd/go-git-providers/gitprovider"
11
11
"github.com/fluxcd/helm-controller/api/v2beta1"
12
+ "github.com/fluxcd/pkg/runtime/logger"
13
+ "github.com/go-logr/logr"
12
14
"github.com/google/go-github/v47/github"
13
15
"github.com/hashicorp/go-uuid"
14
16
. "github.com/onsi/gomega"
@@ -37,6 +39,7 @@ const (
37
39
38
40
func TestPullRequestPromotions (t * testing.T ) {
39
41
g := testingutils .NewGomegaWithT (t )
42
+ log := logger .NewLogger (logger.Options {})
40
43
41
44
tests := []struct {
42
45
name string
@@ -56,16 +59,15 @@ func TestPullRequestPromotions(t *testing.T) {
56
59
"6.0.0" ,
57
60
"6.0.1" ,
58
61
},
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
+ },
69
71
}
70
72
71
73
g .SetDefaultEventuallyTimeout (defaultTimeout )
@@ -82,15 +84,15 @@ func TestPullRequestPromotions(t *testing.T) {
82
84
83
85
//cleanup promotion
84
86
t .Cleanup (func () {
85
- log .Println ("cleaning test" )
87
+ log .Info ("cleaning test" )
86
88
//restore helm release version
87
89
released := releaseNewVersion (g , k8sClient , helmRelease , promotion .currentVersion )
88
90
g .Expect (released ).To (BeTrue ())
89
91
helmRelease , err = ensureHelmRelease (g , pipeline , k8sClient , promotion .currentVersion )
90
92
//delete git branch
91
- err := deleteGitBranchByName (context .Background (), g , k8sClient , pipeline , promotion .branchName )
93
+ err := deleteGitBranchByName (context .Background (), g , k8sClient , pipeline , promotion .branchName , log )
92
94
if err != nil {
93
- log .Fatalf ( "could not delete branch %s" , err )
95
+ log .Error ( err , "could not delete branch" )
94
96
}
95
97
})
96
98
@@ -110,7 +112,7 @@ func TestPullRequestPromotions(t *testing.T) {
110
112
deletePodsByNamespaceAndLabel (g , "flux-system" , "app=notification-controller" )
111
113
}
112
114
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 {
114
116
var secret corev1.Secret
115
117
116
118
promotion := pipeline .Spec .Promotion
@@ -131,26 +133,27 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel
131
133
g .Eventually (func () bool {
132
134
//get secret
133
135
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" )
135
137
return false
136
138
}
137
139
return true
138
140
}).Should (BeTrue ())
139
141
140
- hostname := userRepoRef .Domain
141
142
tokenString := string (secret .Data ["token" ])
142
143
provider := pullrequest.GitProviderConfig {
143
144
Token : tokenString ,
144
145
TokenType : "oauth2" ,
145
146
Type : pullRequestPromotion .Type ,
146
- Hostname : hostname ,
147
+ Domain : userRepoRef . Domain ,
147
148
DestructiveCalls : false ,
148
149
}
149
150
150
- gitProviderClient , err := pullrequest .NewGitProviderClientFactory ()(provider )
151
+ gitProviderClient , err := pullrequest .NewGitProviderClientFactory (log )(provider )
151
152
if err != nil {
152
153
return fmt .Errorf ("could not create git provider client: %w" , err )
153
154
}
155
+ //TODO it should not be needed - gitlab ggp issue
156
+ userRepoRef .Domain = gitProviderClient .SupportedDomain ()
154
157
userRepo , err := gitProviderClient .UserRepositories ().Get (ctx , * userRepoRef )
155
158
if err != nil {
156
159
return fmt .Errorf ("could not get repository: %w" , err )
@@ -167,19 +170,17 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel
167
170
}
168
171
owner := userRepoRef .UserLogin
169
172
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 ))
171
174
if err != nil {
172
175
return fmt .Errorf ("could not rename branch: %w" , err )
173
176
}
174
- log .Println ("branch delete response" , r )
175
177
case v1alpha1 .Gitlab :
176
178
gitlabProject := userRepo .APIObject ().(* gitlab2.Project )
177
179
gClient := clientRaw .(* gitlab2.Client )
178
- deletedBranch , err := gClient .Branches .DeleteBranch (gitlabProject .ID , branchName , nil )
180
+ _ , err := gClient .Branches .DeleteBranch (gitlabProject .ID , branchName , nil )
179
181
if err != nil {
180
182
return fmt .Errorf ("could not delete gitlab branch: %w" , err )
181
183
}
182
- log .Println ("branch delete response" , deletedBranch )
183
184
}
184
185
return nil
185
186
}
0 commit comments