-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_test.go
More file actions
63 lines (43 loc) · 1.01 KB
/
Copy pathgithub_test.go
File metadata and controls
63 lines (43 loc) · 1.01 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package github
import (
"io"
"os"
"testing"
)
func TestGenerateSignature(t *testing.T) {
secret := "s33kret"
expected_sig := "sha1=3f9dc35631573aa328f0ea9c09849883859151c8"
msg := "fixtures/events/push.json"
fh, err := os.Open(msg)
if err != nil {
t.Fatalf("Failed to open %s, %v", msg, err)
}
defer fh.Close()
body, err := io.ReadAll(fh)
if err != nil {
t.Fatalf("Failed to read %s, %v", msg, err)
}
sig, err := GenerateSignature(string(body), secret)
if err != nil {
t.Fatalf("Failed to generate signature, %v", err)
}
if sig != expected_sig {
t.Fatalf("Unexpected signature: %s", sig)
}
}
func TestUnmarshalEvent(t *testing.T) {
msg := "fixtures/events/push.json"
fh, err := os.Open(msg)
if err != nil {
t.Fatalf("Failed to open %s, %v", msg, err)
}
defer fh.Close()
body, err := io.ReadAll(fh)
if err != nil {
t.Fatalf("Failed to read %s, %v", msg, err)
}
_, err = UnmarshalEvent("push", body)
if err != nil {
t.Fatalf("Unable to unmarshal push event, %v", err)
}
}