Skip to content

Commit 5de23c5

Browse files
committed
feat: add ghv3 test
1 parent cbeb9ed commit 5de23c5

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

server/internal/ghv3/ghv3.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@ import (
99
"golang.org/x/oauth2"
1010
)
1111

12+
const (
13+
owner = "codingpot"
14+
repoName = "pr12er"
15+
)
16+
1217
// GitHubV3 is the v3 implementation of gh.GitHubService.
1318
type GitHubV3 struct {
1419
client *github.Client
1520
}
1621

1722
// CreateIssue create an issue.
1823
func (g GitHubV3) CreateIssue(title, body string, labels []string) (*gh.GitHubIssue, error) {
19-
create, _, err := g.client.Issues.Create(context.Background(), "codingpot", "pr12er", &github.IssueRequest{
20-
Title: &title,
21-
Body: &body,
22-
Labels: &labels,
23-
})
24+
create, _, err := g.client.Issues.Create(
25+
context.Background(),
26+
owner,
27+
repoName,
28+
&github.IssueRequest{
29+
Title: &title,
30+
Body: &body,
31+
Labels: &labels,
32+
})
2433

25-
if create == nil {
34+
if create == nil || err != nil {
2635
return nil, err
2736
}
2837
return &gh.GitHubIssue{URL: create.GetURL()}, err

server/internal/ghv3/ghv3_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package ghv3
2+
3+
import (
4+
"context"
5+
"os"
6+
"testing"
7+
8+
"github.com/codingpot/pr12er/server/pkg/handlers/gh"
9+
"github.com/google/go-github/v36/github"
10+
"github.com/stretchr/testify/assert"
11+
"golang.org/x/oauth2"
12+
)
13+
14+
func TestGitHubV3_CreateIssue(t *testing.T) {
15+
t.Skip("this will create an issue; so skip for now")
16+
17+
githubAPIKey := os.Getenv("GITHUB_API_KEY")
18+
t.Logf("GITHUB_API_KEY=%s", githubAPIKey)
19+
20+
type fields struct {
21+
client *github.Client
22+
}
23+
type args struct {
24+
title string
25+
body string
26+
labels []string
27+
}
28+
tests := []struct {
29+
name string
30+
fields fields
31+
args args
32+
want *gh.GitHubIssue
33+
wantErr bool
34+
}{
35+
{
36+
name: "It should create a ticket",
37+
fields: fields{
38+
client: github.NewClient(
39+
oauth2.NewClient(
40+
context.Background(),
41+
oauth2.StaticTokenSource(
42+
&oauth2.Token{AccessToken: githubAPIKey}))),
43+
},
44+
args: args{
45+
title: "TEST TICKET 1",
46+
body: "TEST TICKET BODY",
47+
labels: []string{"data", "test"},
48+
},
49+
wantErr: false,
50+
},
51+
}
52+
for _, tt := range tests {
53+
t.Run(tt.name, func(t *testing.T) {
54+
g := GitHubV3{
55+
client: tt.fields.client,
56+
}
57+
got, err := g.CreateIssue(tt.args.title, tt.args.body, tt.args.labels)
58+
if tt.wantErr {
59+
assert.Error(t, err)
60+
} else {
61+
assert.NoError(t, err)
62+
assert.NotEmpty(t, got.URL)
63+
}
64+
})
65+
}
66+
}

0 commit comments

Comments
 (0)