Skip to content

Commit 1864e6d

Browse files
authored
fix: Use existing repo for IM Cloud Build GitHub module (#364)
1 parent 4dc5bdd commit 1864e6d

File tree

1 file changed

+8
-45
lines changed

1 file changed

+8
-45
lines changed

test/integration/im_cloudbuild_workspace_github/im_cloudbuild_workspace_github_test.go

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ import (
3131
"github.com/terraform-google-modules/terraform-google-bootstrap/test/integration/utils"
3232
)
3333

34+
const (
35+
githubOwner = "im-goose"
36+
githubRepo = "im-cloudbuild-workspace-github"
37+
)
38+
3439
type GitHubClient struct {
3540
t *testing.T
3641
client *github.Client
@@ -104,49 +109,12 @@ func (gh *GitHubClient) GetRepository(ctx context.Context) *github.Repository {
104109
return repo
105110
}
106111

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-
139112
func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
140113
ctx := context.Background()
141114

142115
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)
150118

151119
// Testing the module's feature of appending the ".git" suffix if it's missing
152120
repoURL := strings.TrimSuffix(client.repository.GetCloneURL(), ".git")
@@ -165,10 +133,6 @@ func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
165133
if pr != nil {
166134
client.ClosePullRequest(ctx, pr)
167135
}
168-
// Delete the repository if we hit a failed state
169-
if t.Failed() {
170-
client.DeleteRepository(ctx)
171-
}
172136
})
173137

174138
projectID := bpt.GetStringOutput("project_id")
@@ -260,7 +224,7 @@ func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
260224
return true, nil
261225
}
262226
}
263-
cftutils.Poll(t, pollCloudBuild(buildListCmd), 20, 10*time.Second)
227+
cftutils.Poll(t, pollCloudBuild(buildListCmd), 40, 10*time.Second)
264228
build := gcloud.Run(t, buildListCmd, gcloud.WithLogger(logger.Discard)).Array()[0]
265229

266230
switch branch {
@@ -275,7 +239,6 @@ func TestIMCloudBuildWorkspaceGitHub(t *testing.T) {
275239
bpt.DefineTeardown(func(assert *assert.Assertions) {
276240
// Guarantee clean up even if the normal gcloud/teardown run into errors
277241
t.Cleanup(func() {
278-
client.DeleteRepository(ctx)
279242
bpt.DefaultTeardown(assert)
280243
})
281244
projectID := bpt.GetStringOutput("project_id")

0 commit comments

Comments
 (0)