Skip to content

Commit b65e549

Browse files
joeybloggsjoeybloggs
authored andcommitted
Add timeout for server start for tests
* updated a few ports in the examples, just so can copy, paste and run locally without modification.
1 parent 8fc9c2c commit b65e549

File tree

5 files changed

+49
-43
lines changed

5 files changed

+49
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import (
5353

5454
const (
5555
path = "/webhooks"
56-
port = 80
56+
port = 3016
5757
)
5858

5959
func main() {
@@ -109,7 +109,7 @@ import (
109109

110110
const (
111111
path = "/webhooks"
112-
port = 80
112+
port = 3016
113113
)
114114

115115
func main() {

examples/multiple-handlers/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
path = "/webhooks"
13-
port = 80
13+
port = 3016
1414
)
1515

1616
func main() {

examples/single-handler/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
path = "/webhooks"
13-
port = 80
13+
port = 3016
1414
)
1515

1616
func main() {

github/github_test.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"strconv"
88
"testing"
9+
"time"
910

1011
. "gopkg.in/go-playground/assert.v1"
1112
"gopkg.in/go-playground/webhooks.v1"
@@ -40,7 +41,8 @@ func TestMain(m *testing.M) {
4041
hook = New(&Config{Secret: "IsWishesWereHorsesWedAllBeEatingSteak!"})
4142
hook.RegisterEvents(HandlePayload, CommitCommentEvent, CreateEvent, CreateEvent, DeleteEvent, DeploymentEvent, DeploymentStatusEvent, ForkEvent, GollumEvent, IssueCommentEvent, IssuesEvent, MemberEvent, MembershipEvent, PageBuildEvent, PublicEvent, PullRequestReviewCommentEvent, PullRequestEvent, PushEvent, RepositoryEvent, ReleaseEvent, StatusEvent, TeamAddEvent, WatchEvent)
4243

43-
go webhooks.Run(hook, ":"+strconv.Itoa(port), path)
44+
go webhooks.Run(hook, "127.0.0.1:"+strconv.Itoa(port), path)
45+
time.Sleep(5000)
4446

4547
os.Exit(m.Run())
4648

@@ -54,7 +56,7 @@ func TestProvider(t *testing.T) {
5456
func TestBadNoEventHeader(t *testing.T) {
5557
payload := "{}"
5658

57-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
59+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
5860
req.Header.Set("Content-Type", "application/json")
5961

6062
Equal(t, err, nil)
@@ -71,7 +73,7 @@ func TestBadNoEventHeader(t *testing.T) {
7173
func TestUnsubscribedEvent(t *testing.T) {
7274
payload := "{}"
7375

74-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
76+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
7577
req.Header.Set("Content-Type", "application/json")
7678
req.Header.Set("X-Github-Event", "noneexistant_event")
7779

@@ -89,7 +91,7 @@ func TestUnsubscribedEvent(t *testing.T) {
8991
func TestBadBody(t *testing.T) {
9092
payload := ""
9193

92-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
94+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
9395
req.Header.Set("Content-Type", "application/json")
9496
req.Header.Set("X-Github-Event", "commit_comment")
9597
req.Header.Set("X-Hub-Signature", "sha1=156404ad5f721c53151147f3d3d302329f95a3ab")
@@ -108,7 +110,7 @@ func TestBadBody(t *testing.T) {
108110
func TestBadSignatureLength(t *testing.T) {
109111
payload := "{}"
110112

111-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
113+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
112114
req.Header.Set("Content-Type", "application/json")
113115
req.Header.Set("X-Github-Event", "commit_comment")
114116
req.Header.Set("X-Hub-Signature", "")
@@ -127,7 +129,7 @@ func TestBadSignatureLength(t *testing.T) {
127129
func TestBadSignatureMatch(t *testing.T) {
128130
payload := "{}"
129131

130-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
132+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
131133
req.Header.Set("Content-Type", "application/json")
132134
req.Header.Set("X-Github-Event", "commit_comment")
133135
req.Header.Set("X-Hub-Signature", "sha1=111")
@@ -287,7 +289,7 @@ func TestCommitCommentEvent(t *testing.T) {
287289
}
288290
`
289291

290-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
292+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
291293
req.Header.Set("Content-Type", "application/json")
292294
req.Header.Set("X-Github-Event", "commit_comment")
293295
req.Header.Set("X-Hub-Signature", "sha1=156404ad5f721c53151147f3d3d302329f95a3ab")
@@ -420,7 +422,7 @@ func TestCreateEvent(t *testing.T) {
420422
}
421423
`
422424

423-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
425+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
424426
req.Header.Set("Content-Type", "application/json")
425427
req.Header.Set("X-Github-Event", "create")
426428
req.Header.Set("X-Hub-Signature", "sha1=77ff16ca116034bbeed77ebfce83b36572a9cbaf")
@@ -551,7 +553,7 @@ func TestDeleteEvent(t *testing.T) {
551553
}
552554
`
553555

554-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
556+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
555557
req.Header.Set("Content-Type", "application/json")
556558
req.Header.Set("X-Github-Event", "delete")
557559
req.Header.Set("X-Hub-Signature", "sha1=4ddef04fd05b504c7041e294fca3ad1804bc7be1")
@@ -713,7 +715,7 @@ func TestDeploymentEvent(t *testing.T) {
713715
}
714716
`
715717

716-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
718+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
717719
req.Header.Set("Content-Type", "application/json")
718720
req.Header.Set("X-Github-Event", "deployment")
719721
req.Header.Set("X-Hub-Signature", "sha1=bb47dc63ceb764a6b1f14fe123e299e5b814c67c")
@@ -905,7 +907,7 @@ func TestDeploymentStatusEvent(t *testing.T) {
905907
}
906908
`
907909

908-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
910+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
909911
req.Header.Set("Content-Type", "application/json")
910912
req.Header.Set("X-Github-Event", "deployment_status")
911913
req.Header.Set("X-Hub-Signature", "sha1=8dc0bd0be97440e282e1b4c9ec8445a8d095dc28")
@@ -1121,7 +1123,7 @@ func TestForkEvent(t *testing.T) {
11211123
}
11221124
`
11231125

1124-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
1126+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
11251127
req.Header.Set("Content-Type", "application/json")
11261128
req.Header.Set("X-Github-Event", "fork")
11271129
req.Header.Set("X-Hub-Signature", "sha1=cec5f8fb7c383514c622d3eb9e121891dfcca848")
@@ -1259,7 +1261,7 @@ func TestGollumEvent(t *testing.T) {
12591261
}
12601262
`
12611263

1262-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
1264+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
12631265
req.Header.Set("Content-Type", "application/json")
12641266
req.Header.Set("X-Github-Event", "gollum")
12651267
req.Header.Set("X-Hub-Signature", "sha1=a375a6dc8ceac7231ee022211f8eb85e2a84a5b9")
@@ -1461,7 +1463,7 @@ func TestIssueCommentEvent(t *testing.T) {
14611463
}
14621464
`
14631465

1464-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
1466+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
14651467
req.Header.Set("Content-Type", "application/json")
14661468
req.Header.Set("X-Github-Event", "issue_comment")
14671469
req.Header.Set("X-Hub-Signature", "sha1=e724c9f811fcf5f511aac32e4251b08ab1a0fd87")
@@ -1635,7 +1637,7 @@ func TestIssuesEvent(t *testing.T) {
16351637
}
16361638
`
16371639

1638-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
1640+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
16391641
req.Header.Set("Content-Type", "application/json")
16401642
req.Header.Set("X-Github-Event", "issues")
16411643
req.Header.Set("X-Hub-Signature", "sha1=266736f9446195ffefd3d0cfcd1e096ab129ccad")
@@ -1783,7 +1785,7 @@ func TestMemberEvent(t *testing.T) {
17831785
}
17841786
`
17851787

1786-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
1788+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
17871789
req.Header.Set("Content-Type", "application/json")
17881790
req.Header.Set("X-Github-Event", "member")
17891791
req.Header.Set("X-Hub-Signature", "sha1=597e7d6627a6636d4c3283e36631983fbd57bdd0")
@@ -1864,7 +1866,7 @@ func TestMembershipEvent(t *testing.T) {
18641866
}
18651867
`
18661868

1867-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
1869+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
18681870
req.Header.Set("Content-Type", "application/json")
18691871
req.Header.Set("X-Github-Event", "membership")
18701872
req.Header.Set("X-Hub-Signature", "sha1=16928c947b3707b0efcf8ceb074a5d5dedc9c76e")
@@ -2023,7 +2025,7 @@ func TestPageBuildEvent(t *testing.T) {
20232025
}
20242026
`
20252027

2026-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
2028+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
20272029
req.Header.Set("Content-Type", "application/json")
20282030
req.Header.Set("X-Github-Event", "page_build")
20292031
req.Header.Set("X-Hub-Signature", "sha1=b3abad8f9c1b3fc0b01c4eb107447800bb5000f9")
@@ -2151,7 +2153,7 @@ func TestPublicEvent(t *testing.T) {
21512153
}
21522154
`
21532155

2154-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
2156+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
21552157
req.Header.Set("Content-Type", "application/json")
21562158
req.Header.Set("X-Github-Event", "public")
21572159
req.Header.Set("X-Hub-Signature", "sha1=73edb2a8c69c1ac35efb797ede3dc2cde618c10c")
@@ -2617,7 +2619,7 @@ func TestPullRequestReviewCommentEvent(t *testing.T) {
26172619
}
26182620
`
26192621

2620-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
2622+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
26212623
req.Header.Set("Content-Type", "application/json")
26222624
req.Header.Set("X-Github-Event", "pull_request_review_comment")
26232625
req.Header.Set("X-Hub-Signature", "sha1=a9ece15dbcbb85fa5f00a0bf409494af2cbc5b60")
@@ -3049,7 +3051,7 @@ func TestPullRequestEvent(t *testing.T) {
30493051
}
30503052
`
30513053

3052-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
3054+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
30533055
req.Header.Set("Content-Type", "application/json")
30543056
req.Header.Set("X-Github-Event", "pull_request")
30553057
req.Header.Set("X-Hub-Signature", "sha1=5b342f365078abd366111158b17a8edf5b41ef2a")
@@ -3230,7 +3232,7 @@ func TestPushEvent(t *testing.T) {
32303232
}
32313233
`
32323234

3233-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
3235+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
32343236
req.Header.Set("Content-Type", "application/json")
32353237
req.Header.Set("X-Github-Event", "push")
32363238
req.Header.Set("X-Hub-Signature", "sha1=d683a72295b08a42a55bf6fbf2598dc7603e0b98")
@@ -3369,7 +3371,7 @@ func TestRepositoryEvent(t *testing.T) {
33693371
}
33703372
`
33713373

3372-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
3374+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
33733375
req.Header.Set("Content-Type", "application/json")
33743376
req.Header.Set("X-Github-Event", "repository")
33753377
req.Header.Set("X-Hub-Signature", "sha1=df442a8af41edd2d42ccdd997938d1d111b0f94e")
@@ -3537,7 +3539,7 @@ func TestReleaseEvent(t *testing.T) {
35373539
}
35383540
`
35393541

3540-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
3542+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
35413543
req.Header.Set("Content-Type", "application/json")
35423544
req.Header.Set("X-Github-Event", "release")
35433545
req.Header.Set("X-Hub-Signature", "sha1=e62bb4c51bc7dde195b9525971c2e3aecb394390")
@@ -3763,7 +3765,7 @@ func TestStatusEvent(t *testing.T) {
37633765
}
37643766
`
37653767

3766-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
3768+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
37673769
req.Header.Set("Content-Type", "application/json")
37683770
req.Header.Set("X-Github-Event", "status")
37693771
req.Header.Set("X-Hub-Signature", "sha1=3caa5f062a2deb7cce1482314bb9b4c99bf0ab45")
@@ -3912,7 +3914,7 @@ func TestTeamAddEvent(t *testing.T) {
39123914
}
39133915
`
39143916

3915-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
3917+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
39163918
req.Header.Set("Content-Type", "application/json")
39173919
req.Header.Set("X-Github-Event", "team_add")
39183920
req.Header.Set("X-Hub-Signature", "sha1=5f3953476e270b79cc6763780346110da880609a")
@@ -4041,7 +4043,7 @@ func TestWatchEvent(t *testing.T) {
40414043
}
40424044
`
40434045

4044-
req, err := http.NewRequest("POST", "http://localhost:3009/webhooks", bytes.NewBuffer([]byte(payload)))
4046+
req, err := http.NewRequest("POST", "http://127.0.0.1:3009/webhooks", bytes.NewBuffer([]byte(payload)))
40454047
req.Header.Set("Content-Type", "application/json")
40464048
req.Header.Set("X-Github-Event", "watch")
40474049
req.Header.Set("X-Hub-Signature", "sha1=a317bcfe69ccb8bece74c20c7378e5413c4772f1")

0 commit comments

Comments
 (0)