-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscriptions_test.go
62 lines (52 loc) · 1.22 KB
/
subscriptions_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
package twitch_test
import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"testing"
"github.com/joeyak/go-twitch-eventsub/v2"
)
func TestEventVersion(t *testing.T) {
testCases := []struct {
Name string
Version string
Expected string
}{
{"Override", "-1", "-1"},
{"Default", "", "2"},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
assertEventOccured(t, func(ch chan struct{}) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Error(err)
}
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
request, err := io.ReadAll(r.Body)
if err != nil {
panic(err)
}
r.Body.Close()
var subscription twitch.SubscriptionRequest
err = json.Unmarshal(request, &subscription)
if err != nil {
panic(err)
}
if subscription.Version != tc.Expected {
t.Error("versions did not match")
}
close(ch)
})
go http.Serve(listener, mux)
twitch.SubscribeEventUrl(twitch.SubscribeRequest{
Event: twitch.SubChannelUpdate,
VersionOverride: tc.Version,
}, fmt.Sprintf("http://%s", listener.Addr().String()))
})
})
}
}