-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawlrequests_test.go
91 lines (85 loc) · 2.49 KB
/
crawlrequests_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"testing"
)
func Test_WebhookURL(t *testing.T) {
setupTestlogging()
WantedURL := "http://localhost/webhook"
testConfig := ConfigGithub{Endpoint: "/webhook", PublicAddress: "http://localhost/"}
testurl := testConfig.getWebHookURL()
if testurl != WantedURL {
t.Errorf("%v should be %v", testurl, WantedURL)
}
testConfig = ConfigGithub{Endpoint: "webhook", PublicAddress: "http://localhost/"}
testurl = testConfig.getWebHookURL()
if testurl != WantedURL {
t.Errorf("%v should be %v", testurl, WantedURL)
}
testConfig = ConfigGithub{Endpoint: "/webhook", PublicAddress: "http://localhost"}
testurl = testConfig.getWebHookURL()
if testurl != WantedURL {
t.Errorf("%v should be %v", testurl, WantedURL)
}
testConfig = ConfigGithub{Endpoint: "webhook", PublicAddress: "http://localhost"}
testurl = testConfig.getWebHookURL()
if testurl != WantedURL {
t.Errorf("%v should be %v", testurl, WantedURL)
}
}
func Test_ListRepostories(t *testing.T) {
setupTestlogging()
c := &Crawler{Config: ConfigGithub{Endpoint: "/webhook"}}
c.Config.populateEnv()
if c.Config.Token == "" {
t.Log("Token not configured, Skipping Test")
return
}
repos, err := c.ListRepositories()
if err != nil {
t.Error(err)
}
t.Logf("Found %v repositories", len(repos))
for idx, repo := range repos {
t.Logf("[%v] %v/%v %v", idx, repo.Owner.Login, repo.Name, repo.Private)
}
}
func Test_ListPullRequests(t *testing.T) {
setupTestlogging()
c := &Crawler{Config: ConfigGithub{Endpoint: "/webhook"}}
c.Config.populateEnv()
if c.Config.Token == "" {
t.Log("Token not configured, Skipping Test")
return
}
pulls, next, err := c.getPullRequestsPage("https://api.github.com/repos/SimonStiil/turingpi-flux/pulls?state=all&per_page=50")
if err != nil {
t.Error(err)
}
if next != "" {
t.Log("has more pages")
}
t.Logf("Found %v Pullrequests", len(pulls))
for idx, pull := range pulls {
t.Logf("[%v] (%v) %v %v", idx, pull.Number, pull.State, pull.Title)
}
}
func Test_ListWebhooks(t *testing.T) {
setupTestlogging()
c := &Crawler{Config: ConfigGithub{Endpoint: "/webhook"}}
c.Config.populateEnv()
if c.Config.Token == "" {
t.Log("Token not configured, Skipping Test")
return
}
webhooks, next, err := c.getWebHooksPage("https://api.github.com/repos/SimonStiil/kube-auth-proxy/hooks")
if err != nil {
t.Error(err)
}
if next != "" {
t.Log("has more pages")
}
t.Logf("Found %v repositories", len(webhooks))
for idx, webhook := range webhooks {
t.Logf("[%v] %v", idx, webhook.String())
}
}