-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
108 lines (97 loc) · 2.59 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package azqlite
import (
"context"
"encoding/base64"
"net/http"
"net/http/httptest"
"testing"
)
func TestNewClient(t *testing.T) {
accountName, accountKey := "name", "key"
accountKey = base64.StdEncoding.EncodeToString([]byte(accountKey))
s, err := NewClient(Config{
AccountName: accountName,
AccountKey: accountKey,
})
if err != nil {
t.Fatalf("NewService returned error: %v", err)
}
if s == nil {
t.Fatal("NewService returned nil")
}
if s.serviceURL.String() != "https://name.queue.core.windows.net" {
t.Fatalf("NewService returned incorrect serviceURL: %v", s.serviceURL)
}
}
func TestCreateQueue(t *testing.T) {
serverCalled := false
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
serverCalled = true
w.WriteHeader(http.StatusCreated)
}))
defer testServer.Close()
accountName, accountKey := "name", "key"
accountKey = base64.StdEncoding.EncodeToString([]byte(accountKey))
serviceURL := testServer.URL + "/%s"
s, err := NewClient(Config{
AccountName: accountName,
AccountKey: accountKey,
AzureServiceURL: serviceURL,
})
if err != nil {
t.Fatalf("NewService returned error: %v", err)
}
ctx := context.Background()
q, err := s.CreateQueue(ctx, "test")
if err != nil {
t.Fatalf("CreateQueue returned error: %v", err)
}
if q == nil {
t.Fatal("CreateQueue returned nil")
}
if !serverCalled {
t.Fatal("CreateQueue did not make HTTP call")
}
}
func TestDeleteQueue(t *testing.T) {
serverCalled := false
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
serverCalled = true
w.WriteHeader(http.StatusNoContent)
}))
defer testServer.Close()
accountName, accountKey := "name", "key"
accountKey = base64.StdEncoding.EncodeToString([]byte(accountKey))
serviceURL := testServer.URL + "/%s"
s, err := NewClient(Config{
AccountName: accountName,
AccountKey: accountKey,
AzureServiceURL: serviceURL,
})
if err != nil {
t.Fatalf("NewService returned error: %v", err)
}
ctx := context.Background()
err = s.DeleteQueue(ctx, "test")
if err != nil {
t.Fatalf("DeleteQueue returned error: %v", err)
}
if !serverCalled {
t.Fatal("DeleteQueue did not make HTTP call")
}
}
func TestGetQueue(t *testing.T) {
accountName, accountKey := "name", "key"
accountKey = base64.StdEncoding.EncodeToString([]byte(accountKey))
s, err := NewClient(Config{
AccountName: accountName,
AccountKey: accountKey,
})
if err != nil {
t.Fatalf("NewService returned error: %v", err)
}
q := s.GetQueue("test")
if q == nil {
t.Fatal("NewQueue returned nil")
}
}