-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_test.go
42 lines (33 loc) · 924 Bytes
/
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
package edgegrid
import (
"io/ioutil"
"testing"
"strings"
)
func TestApiRequest(t *testing.T) {
api := NewFromIni(".edgerc")
resp, err := api.Send("POST", "/ccu/v3/invalidate/url/production", "{ \"objects\" : [ \"http://example.com\" ]}")
if err != nil {
t.Error(err)
}
if resp.Status != "201" {
contents, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Error(err)
}
t.Log(string(contents))
}
}
func TestSignedRequest(t *testing.T) {
e := new(EdgeGrid)
e.clientToken = "test"
e.clientSecret = "testSecret"
e.accessToken = "testAccess"
signedRequest := e.signedRequest("POST", "/somwhere", nil, "")
if strings.Index(signedRequest, "EG1-HMAC-SHA256") != 0 {
t.Error("Bad signed request: missing hash declaration: ", signedRequest)
}
if !strings.Contains(signedRequest, "client_token="+e.clientToken+";") {
t.Error("Bad signed request: missing client token: ", signedRequest)
}
}