-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_utils_test.go
73 lines (63 loc) · 2.55 KB
/
test_utils_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 (
"net/http"
"net/url"
"time"
. "github.com/daresaydigital/azure-notificationhubs-go"
"github.com/daresaydigital/azure-notificationhubs-go/utils"
)
// Internal constants for testing
const (
connectionString = "Endpoint=sb://testhub-ns.servicebus.windows.net/;SharedAccessKeyName=testAccessKeyName;SharedAccessKey=testAccessKey"
messagesURL = "https://testhub-ns.servicebus.windows.net/testhub/messages?api-version=2015-01"
schedulesURL = "https://testhub-ns.servicebus.windows.net/testhub/schedulednotifications?api-version=2015-01"
registrationsURL = "https://testhub-ns.servicebus.windows.net/testhub/registrations?api-version=2015-01"
installationsURL = "https://testhub-ns.servicebus.windows.net/testhub/installations?api-version=2015-01"
hubPath = "testhub"
apiVersionParam = "api-version"
apiVersionValue = "2015-01"
telemetryAPIVersionValue = "2016-07"
directParam = "direct"
defaultScheme = "https"
errfmt = "Expected %s: \n%v\ngot:\n%v"
postMethod = "POST"
putMethod = "PUT"
getMethod = "GET"
patchMethod = "PATCH"
deleteMethod = "DELETE"
)
var (
endOfEpoch, _ = time.Parse("2006-01-02T15:04:05.000Z", "9999-12-31T23:59:59.999Z")
mockTimeGeneratorFunc = utils.ExpirationTimeGeneratorFunc(func() int64 { return 123 })
realTimeGeneratorFunc = utils.NewExpirationTimeGenerator()
sasURIString = (&url.URL{Host: "testhub-ns.servicebus.windows.net", Scheme: defaultScheme}).String()
)
type mockNotificationHub struct {
SasKeyValue string
SasKeyName string
HubURL *url.URL
client utils.HTTPClient
expirationTimeGenerator utils.ExpirationTimeGenerator
}
type mockHubHTTPClient struct {
execFunc func(*http.Request) ([]byte, *http.Response, error)
}
func (mc *mockHubHTTPClient) Exec(req *http.Request) ([]byte, *http.Response, error) {
return mc.execFunc(req)
}
func initNotificationTestItems() (*NotificationHub, *Notification, *mockHubHTTPClient) {
var (
notification, _ = NewNotification(Template, []byte("test payload"))
nhub, mockClient = initTestItems()
)
return nhub, notification, mockClient
}
func initTestItems() (*NotificationHub, *mockHubHTTPClient) {
var (
mockClient = &mockHubHTTPClient{}
nhub = NewNotificationHub(connectionString, hubPath)
)
nhub.SetHTTPClient(mockClient)
nhub.SetExpirationTimeGenerator(mockTimeGeneratorFunc)
return nhub, mockClient
}