-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrpush_test.go
65 lines (49 loc) · 1.36 KB
/
nrpush_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
package nrpush_test
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"github.com/reddotpay/nrpush"
)
func ExampleNRPush_Push() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"success": true, "uuid": "73dda6fb-001f-b000-0000-016e157e6878"}`)
}))
defer ts.Close()
n := nrpush.New("somepushkey123", "111111", "transaction")
n.Endpoint = ts.URL
// nrpush.Verbose = true
uuid, err := n.Push(context.Background(), map[string]interface{}{
"amount": 100.00,
"product": "test",
"eventType": "someotherevent",
})
if err != nil {
panic(err)
}
fmt.Printf("New Relic UUID: %s", uuid)
// Output:
// New Relic UUID: 73dda6fb-001f-b000-0000-016e157e6878
}
func ExampleNRPush_PushBatch() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"success": true, "uuid": "73dda6fb-001f-b000-0000-016e157e6878"}`)
}))
defer ts.Close()
n := nrpush.New("somepushkey123", "111111", "transaction")
n.Endpoint = ts.URL
uuid, err := n.PushBatch(context.Background(), []interface{}{
map[string]interface{}{
"amount": 100.00,
"product": "test",
"eventType": "someotherevent",
},
})
if err != nil {
panic(err)
}
fmt.Printf("New Relic UUID: %s", uuid)
// Output:
// New Relic UUID: 73dda6fb-001f-b000-0000-016e157e6878
}