-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelay_test.go
More file actions
48 lines (41 loc) · 1.11 KB
/
relay_test.go
File metadata and controls
48 lines (41 loc) · 1.11 KB
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
package main
import (
"bytes"
"gopkg.in/h2non/gock.v1"
"io/ioutil"
"net/http"
"os"
"testing"
)
func TestRelayRequest(t *testing.T) {
content, err := ioutil.ReadFile("tests/valid-hook.req")
if err != nil {
t.Skipf("%s", err.Error())
}
defer gock.Off()
gock.New("http://localhost:8080").
Post("/github-webhook").
Reply(http.StatusOK)
os.Setenv("JENKINS_ENDPOINT", "http://localhost:8080/github-webhook/")
buffer := bytes.NewBuffer(content)
err = RelayRequest(buffer, "application/json", "sha1=0000000000000000000000000000000000000000", "push")
if err != nil {
t.Fatalf("%s", err.Error())
}
}
func TestRelayTagRequest(t *testing.T) {
content, err := ioutil.ReadFile("tests/tag-hook.req")
if err != nil {
t.Skipf("%s", err.Error())
}
defer gock.Off()
gock.New("http://localhost:8080").
Post("/github-webhook").
Reply(http.StatusOK)
os.Setenv("JENKINS_ENDPOINT", "http://localhost:8080/github-webhook/")
buffer := bytes.NewBuffer(content)
err = RelayRequest(buffer, "application/json", "sha1=0000000000000000000000000000000000000000", "push")
if err != nil {
t.Fatalf("%s", err.Error())
}
}