-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotificationhub_test.go
73 lines (63 loc) · 2.12 KB
/
notificationhub_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
72
73
package notificationhubs_test
import (
"context"
"net/http"
"net/url"
"testing"
. "github.com/daresaydigital/azure-notificationhubs-go"
)
func Test_NewNotificationHub(t *testing.T) {
var (
errfmt = "NewNotificationHub test case %d error. Expected %s: %v, got: %v"
queryString = url.Values{apiVersionParam: {apiVersionValue}}.Encode()
testCases = []struct {
connectionString string
expectedHub *mockNotificationHub
}{
{
connectionString: connectionString,
expectedHub: &mockNotificationHub{
SasKeyValue: "testAccessKey",
SasKeyName: "testAccessKeyName",
HubURL: &url.URL{Host: "testhub-ns.servicebus.windows.net", Scheme: defaultScheme, Path: hubPath, RawQuery: queryString},
},
},
{
connectionString: "wrong_connection_string",
expectedHub: &mockNotificationHub{
SasKeyValue: "",
SasKeyName: "",
HubURL: &url.URL{Host: "", Scheme: defaultScheme, Path: hubPath, RawQuery: queryString},
},
},
}
)
for i, testCase := range testCases {
obtainedNotificationHub := NewNotificationHub(testCase.connectionString, hubPath)
if obtainedNotificationHub.SasKeyValue != testCase.expectedHub.SasKeyValue {
t.Errorf(errfmt, i, "NotificationHub.SasKeyValue", testCase.expectedHub.SasKeyValue, obtainedNotificationHub.SasKeyValue)
}
if obtainedNotificationHub.SasKeyName != testCase.expectedHub.SasKeyName {
t.Errorf(errfmt, i, "NotificationHub.SasKeyName", testCase.expectedHub.SasKeyName, obtainedNotificationHub.SasKeyName)
}
wantURL := testCase.expectedHub.HubURL.String()
gotURL := obtainedNotificationHub.HubURL.String()
if gotURL != wantURL {
t.Errorf(errfmt, i, "NotificationHub.hubURL", wantURL, gotURL)
}
}
}
func Test_HTTPRequestContext(t *testing.T) {
var (
nhub, mockClient = initTestItems()
)
mockClient.execFunc = func(req *http.Request) ([]byte, *http.Response, error) {
foo := req.Context().Value("foo")
if foo != "bar" {
t.Errorf(errfmt, "request context value", "foo", foo)
}
return nil, nil, nil
}
ctx := context.WithValue(context.Background(), "foo", "bar")
_, _, _ = nhub.Registrations(ctx)
}