-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.test.go
71 lines (62 loc) · 1.55 KB
/
client.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
package main
import (
"log"
"os"
"os/signal"
"testing"
)
func TestQuery(t *testing.T) {
// Configure the client
token := os.Getenv("TOKEN")
client := Client{
token: token,
subscriptionEndpoint: `wss://v1.igloo.ooo/subscriptions`,
queryEndpoint: "https://v1.igloo.ooo/graphql",
}
// Execute a query
resp, queryErr := client.Query(` {
floatVariable(id: "c3fd95b8-5333-4d81-9fbf-0323398ec66b") {
id
value
}
}`)
if queryErr != nil {
log.Fatal(queryErr)
}
log.Println("Initial Value: ", resp["floatVariable"].(map[string]interface{})["value"])
}
func BenchmarkSubscription(t *testing.B) {
// Configure the client
token := os.Getenv("TOKEN")
client := Client{
token: token,
subscriptionEndpoint: `wss://v1.igloo.ooo/subscriptions`,
queryEndpoint: "https://v1.igloo.ooo/graphql",
}
// Open the subscription
subscriptionQuery := `subscription{variableUpdated(id: "c3fd95b8-5333-4d81-9fbf-0323398ec66b"){id ...on FloatVariable{value}}}`
messages, Stop, err := client.Subscribe(subscriptionQuery)
if err != nil {
log.Fatal(err)
}
// Listen for CTRL-C to Stop the subscription
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
go func() {
<-interrupt
Stop()
}()
// Iterate messages and print them to console
i := 0
for message := range messages {
i++
if message.Error != nil {
log.Fatal(message.Error)
}
data := (*message.Payload)["variableUpdated"].(map[string]interface{})
log.Println("Value: ", data["value"])
if i > 2 {
break
}
}
}