@@ -28,7 +28,12 @@ import (
28
28
cftutils "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
29
29
"github.com/google/go-github/v71/github"
30
30
"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
32
37
)
33
38
34
39
type GitHubClient struct {
@@ -39,14 +44,14 @@ type GitHubClient struct {
39
44
repository * github.Repository
40
45
}
41
46
42
- func NewGitHubClient (t * testing.T , token , owner , repo string ) * GitHubClient {
47
+ func NewGitHubClient (t * testing.T , token string ) * GitHubClient {
43
48
t .Helper ()
44
49
client := github .NewClient (nil ).WithAuthToken (token )
45
50
return & GitHubClient {
46
51
t : t ,
47
52
client : client ,
48
- owner : owner ,
49
- repoName : repo ,
53
+ owner : githubOwner ,
54
+ repoName : githubRepo ,
50
55
}
51
56
}
52
57
@@ -59,59 +64,25 @@ func (gh *GitHubClient) GetRepository(ctx context.Context) *github.Repository {
59
64
return repo
60
65
}
61
66
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
-
84
67
func TestTFCloudBuildBuilderGitHub (t * testing.T ) {
85
68
ctx := context .Background ()
86
69
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 )
90
71
91
- repo := client .GetRepository (ctx )
92
- if repo == nil {
93
- client .CreateRepository (ctx , client .owner , client .repoName )
94
- }
72
+ client .GetRepository (ctx )
95
73
96
74
// Testing the module's feature of appending the ".git" suffix if it's missing
97
75
repoURL := strings .TrimSuffix (client .repository .GetCloneURL (), ".git" )
98
76
vars := map [string ]interface {}{
99
77
"github_pat" : githubPAT ,
100
78
"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 ,
102
80
}
103
81
bpt := tft .NewTFBlueprintTest (t , tft .WithVars (vars ))
104
82
105
83
bpt .DefineVerify (func (assert * assert.Assertions ) {
106
84
bpt .DefaultVerify (assert )
107
85
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
-
115
86
location := bpt .GetStringOutput ("location" )
116
87
projectID := bpt .GetStringOutput ("project_id" )
117
88
artifactRepo := bpt .GetStringOutput ("artifact_repo" )
@@ -210,7 +181,6 @@ func TestTFCloudBuildBuilderGitHub(t *testing.T) {
210
181
bpt .DefineTeardown (func (assert * assert.Assertions ) {
211
182
// Guarantee clean up even if the normal gcloud/teardown run into errors
212
183
t .Cleanup (func () {
213
- client .DeleteRepository (ctx )
214
184
bpt .DefaultTeardown (assert )
215
185
})
216
186
})
0 commit comments