Skip to content

Commit b1c547a

Browse files
committed
Skip tests that require write access when secrets are unavailable
1 parent 72482c0 commit b1c547a

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
changelog:
2+
- type: NON_USER_FACING
3+
resolvesIssue: false
4+
description: Skip write steps for forks without cloudbuild secrets.

githubutils/repo_client_test.go

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package githubutils_test
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strings"
78

89
"github.com/solo-io/go-utils/randutils"
@@ -116,40 +117,48 @@ var _ = Describe("repo client utils", func() {
116117
expectStatus(loaded, status)
117118
}
118119

119-
It("can manage status", func() {
120-
client = githubutils.NewRepoClient(githubClient, owner, repo)
121-
// randomizing this would create a (slim) potential race
122-
// not randomizing makes it less easy to validate that the create worked, but we'll assume github api responses are accurate
123-
status := &github.RepoStatus{
124-
State: github.String(githubutils.STATUS_SUCCESS),
125-
Context: github.String("test"),
126-
Description: github.String("test"), // longer than 140 characters will be truncated
127-
}
128-
testManageStatus(client, status, sha)
129-
})
120+
Context("With write token", func() {
121+
BeforeEach(func() {
122+
if os.Getenv("HAS_CLOUDBUILD_GITHUB_TOKEN") == "" {
123+
Skip("Needs write token")
124+
}
125+
})
130126

131-
It("can manage status even when it exceeds 140 character", func() {
132-
client = githubutils.NewRepoClient(githubClient, owner, repo)
133-
// randomizing this would create a (slim) potential race
134-
// not randomizing makes it less easy to validate that the create worked, but we'll assume github api responses are accurate
135-
status := &github.RepoStatus{
136-
State: github.String(githubutils.STATUS_SUCCESS),
137-
Context: github.String("test"),
138-
Description: github.String(strings.Repeat("test", 40)), // longer than 140 characters will be truncated
139-
}
140-
testManageStatus(client, status, otherSha) // don't share sha with other test to avoid race
141-
})
127+
It("can manage status", func() {
128+
client = githubutils.NewRepoClient(githubClient, owner, repo)
129+
// randomizing this would create a (slim) potential race
130+
// not randomizing makes it less easy to validate that the create worked, but we'll assume github api responses are accurate
131+
status := &github.RepoStatus{
132+
State: github.String(githubutils.STATUS_SUCCESS),
133+
Context: github.String("test"),
134+
Description: github.String("test"), // longer than 140 characters will be truncated
135+
}
136+
testManageStatus(client, status, sha)
137+
})
142138

143-
It("can create and delete comments", func() {
144-
client = githubutils.NewRepoClient(githubClient, owner, repo)
145-
body := fmt.Sprintf("test-%s", randutils.RandString(4))
146-
comment := &github.IssueComment{
147-
Body: github.String(body),
148-
}
149-
stored, err := client.CreateComment(ctx, pr, comment)
150-
Expect(err).To(BeNil())
151-
err = client.DeleteComment(ctx, stored.GetID())
152-
Expect(err).To(BeNil())
139+
It("can manage status even when it exceeds 140 character", func() {
140+
client = githubutils.NewRepoClient(githubClient, owner, repo)
141+
// randomizing this would create a (slim) potential race
142+
// not randomizing makes it less easy to validate that the create worked, but we'll assume github api responses are accurate
143+
status := &github.RepoStatus{
144+
State: github.String(githubutils.STATUS_SUCCESS),
145+
Context: github.String("test"),
146+
Description: github.String(strings.Repeat("test", 40)), // longer than 140 characters will be truncated
147+
}
148+
testManageStatus(client, status, otherSha) // don't share sha with other test to avoid race
149+
})
150+
151+
It("can create and delete comments", func() {
152+
client = githubutils.NewRepoClient(githubClient, owner, repo)
153+
body := fmt.Sprintf("test-%s", randutils.RandString(4))
154+
comment := &github.IssueComment{
155+
Body: github.String(body),
156+
}
157+
stored, err := client.CreateComment(ctx, pr, comment)
158+
Expect(err).To(BeNil())
159+
err = client.DeleteComment(ctx, stored.GetID())
160+
Expect(err).To(BeNil())
161+
})
153162
})
154163

155164
Context("Can properly find the most recent tag before an SHA", func() {

0 commit comments

Comments
 (0)