@@ -28,7 +28,12 @@ import (
2828 cftutils "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
2929 "github.com/google/go-github/v71/github"
3030 "github.com/stretchr/testify/assert"
31- "github.com/terraform-google-modules/terraform-google-bootstrap/test/integration/utils"
31+ )
32+
33+ const (
34+ githubOwner = "im-goose"
35+ githubRepo = "b-gh-test"
36+ githubAppID = "47590865" // Found in the URL of your Cloud Build GitHub app configuration settings
3237)
3338
3439type GitHubClient struct {
@@ -39,14 +44,14 @@ type GitHubClient struct {
3944 repository * github.Repository
4045}
4146
42- func NewGitHubClient (t * testing.T , token , owner , repo string ) * GitHubClient {
47+ func NewGitHubClient (t * testing.T , token string ) * GitHubClient {
4348 t .Helper ()
4449 client := github .NewClient (nil ).WithAuthToken (token )
4550 return & GitHubClient {
4651 t : t ,
4752 client : client ,
48- owner : owner ,
49- repoName : repo ,
53+ owner : githubOwner ,
54+ repoName : githubRepo ,
5055 }
5156}
5257
@@ -59,59 +64,25 @@ func (gh *GitHubClient) GetRepository(ctx context.Context) *github.Repository {
5964 return repo
6065}
6166
62- func (gh * GitHubClient ) CreateRepository (ctx context.Context , org , repoName string ) * github.Repository {
63- newRepo := & github.Repository {
64- Name : github .String (repoName ),
65- AutoInit : github .Bool (true ),
66- Private : github .Bool (true ),
67- Visibility : github .String ("private" ),
68- }
69- repo , _ , err := gh .client .Repositories .Create (ctx , org , newRepo )
70- if err != nil {
71- gh .t .Fatal (err .Error ())
72- }
73- gh .repository = repo
74- return repo
75- }
76-
77- func (gh * GitHubClient ) DeleteRepository (ctx context.Context ) {
78- resp , err := gh .client .Repositories .Delete (ctx , gh .owner , * gh .repository .Name )
79- if resp .StatusCode != 404 && err != nil {
80- gh .t .Fatal (err .Error ())
81- }
82- }
83-
8467func TestTFCloudBuildBuilderGitHub (t * testing.T ) {
8568 ctx := context .Background ()
8669 githubPAT := cftutils .ValFromEnv (t , "IM_GITHUB_PAT" )
87- owner := "im-goose"
88- repoName := fmt .Sprintf ("b-gh-test-%s" , utils .GetRandomStringFromSetup (t ))
89- client := NewGitHubClient (t , githubPAT , owner , repoName )
70+ client := NewGitHubClient (t , githubPAT )
9071
91- repo := client .GetRepository (ctx )
92- if repo == nil {
93- client .CreateRepository (ctx , client .owner , client .repoName )
94- }
72+ client .GetRepository (ctx )
9573
9674 // Testing the module's feature of appending the ".git" suffix if it's missing
9775 repoURL := strings .TrimSuffix (client .repository .GetCloneURL (), ".git" )
9876 vars := map [string ]interface {}{
9977 "github_pat" : githubPAT ,
10078 "repository_uri" : repoURL ,
101- "github_app_id" : "47590865" , // Found in the URL of your Cloud Build GitHub app configuration settings
79+ "github_app_id" : githubAppID ,
10280 }
10381 bpt := tft .NewTFBlueprintTest (t , tft .WithVars (vars ))
10482
10583 bpt .DefineVerify (func (assert * assert.Assertions ) {
10684 bpt .DefaultVerify (assert )
10785
108- t .Cleanup (func () {
109- // Delete the repository if we hit a failed state
110- if t .Failed () {
111- client .DeleteRepository (ctx )
112- }
113- })
114-
11586 location := bpt .GetStringOutput ("location" )
11687 projectID := bpt .GetStringOutput ("project_id" )
11788 artifactRepo := bpt .GetStringOutput ("artifact_repo" )
@@ -210,7 +181,6 @@ func TestTFCloudBuildBuilderGitHub(t *testing.T) {
210181 bpt .DefineTeardown (func (assert * assert.Assertions ) {
211182 // Guarantee clean up even if the normal gcloud/teardown run into errors
212183 t .Cleanup (func () {
213- client .DeleteRepository (ctx )
214184 bpt .DefaultTeardown (assert )
215185 })
216186 })
0 commit comments