@@ -31,6 +31,11 @@ import (
31
31
"github.com/terraform-google-modules/terraform-google-bootstrap/test/integration/utils"
32
32
)
33
33
34
+ const (
35
+ githubOwner = "im-goose"
36
+ githubRepo = "im-cloudbuild-workspace-github"
37
+ )
38
+
34
39
type GitHubClient struct {
35
40
t * testing.T
36
41
client * github.Client
@@ -104,49 +109,12 @@ func (gh *GitHubClient) GetRepository(ctx context.Context) *github.Repository {
104
109
return repo
105
110
}
106
111
107
- func (gh * GitHubClient ) CreateRepository (ctx context.Context , org , repoName string ) * github.Repository {
108
- newRepo := & github.Repository {
109
- Name : github .String (repoName ),
110
- AutoInit : github .Bool (true ),
111
- Visibility : github .String ("private" ),
112
- }
113
- repo , _ , err := gh .client .Repositories .Create (ctx , org , newRepo )
114
- if err != nil {
115
- gh .t .Fatal (err .Error ())
116
- }
117
- gh .repository = repo
118
- return repo
119
- }
120
-
121
- func (gh * GitHubClient ) AddFileToRepository (ctx context.Context , file []byte ) {
122
- opts := & github.RepositoryContentFileOptions {
123
- Content : file ,
124
- Message : github .String ("Setup commit" ),
125
- }
126
- _ , _ , err := gh .client .Repositories .CreateFile (ctx , gh .owner , gh .repoName , "main.tf" , opts )
127
- if err != nil {
128
- gh .t .Fatal (err .Error ())
129
- }
130
- }
131
-
132
- func (gh * GitHubClient ) DeleteRepository (ctx context.Context ) {
133
- _ , err := gh .client .Repositories .Delete (ctx , gh .owner , * gh .repository .Name )
134
- if err != nil {
135
- gh .t .Fatal (err .Error ())
136
- }
137
- }
138
-
139
112
func TestIMCloudBuildWorkspaceGitHub (t * testing.T ) {
140
113
ctx := context .Background ()
141
114
142
115
githubPAT := cftutils .ValFromEnv (t , "IM_GITHUB_PAT" )
143
- client := NewGitHubClient (t , githubPAT , "im-goose" , fmt .Sprintf ("im-blueprint-test-%s" , utils .GetRandomStringFromSetup (t )))
144
-
145
- repo := client .GetRepository (ctx )
146
- if repo == nil {
147
- client .CreateRepository (ctx , client .owner , client .repoName )
148
- client .AddFileToRepository (ctx , utils .GetFileContents (t , "files/main.tf" ))
149
- }
116
+ client := NewGitHubClient (t , githubPAT , githubOwner , githubRepo )
117
+ client .GetRepository (ctx )
150
118
151
119
// Testing the module's feature of appending the ".git" suffix if it's missing
152
120
repoURL := strings .TrimSuffix (client .repository .GetCloneURL (), ".git" )
@@ -165,10 +133,6 @@ func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
165
133
if pr != nil {
166
134
client .ClosePullRequest (ctx , pr )
167
135
}
168
- // Delete the repository if we hit a failed state
169
- if t .Failed () {
170
- client .DeleteRepository (ctx )
171
- }
172
136
})
173
137
174
138
projectID := bpt .GetStringOutput ("project_id" )
@@ -260,7 +224,7 @@ func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
260
224
return true , nil
261
225
}
262
226
}
263
- cftutils .Poll (t , pollCloudBuild (buildListCmd ), 20 , 10 * time .Second )
227
+ cftutils .Poll (t , pollCloudBuild (buildListCmd ), 40 , 10 * time .Second )
264
228
build := gcloud .Run (t , buildListCmd , gcloud .WithLogger (logger .Discard )).Array ()[0 ]
265
229
266
230
switch branch {
@@ -275,7 +239,6 @@ func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
275
239
bpt .DefineTeardown (func (assert * assert.Assertions ) {
276
240
// Guarantee clean up even if the normal gcloud/teardown run into errors
277
241
t .Cleanup (func () {
278
- client .DeleteRepository (ctx )
279
242
bpt .DefaultTeardown (assert )
280
243
})
281
244
projectID := bpt .GetStringOutput ("project_id" )
0 commit comments