Debian Codegraph @

fastly/request_test.go

raw symbols SCIP
1 package fastly
2
3 import (
4 "net/url"
5 "strings"
6 "testing"
7 )
8
9 func TestClient_RawRequest(t *testing.T) {
10 validAPIHosts := []string{
11 "https://api.fastly.com",
12 "https://api.fastly.com/",
13 }
14 purgeAPIPaths := []string{
15 "/service/myservice/purge/",
16 "service/myservice/purge/",
17 }
18 cacheKeys := []string{
19 "/",
20 "text//text",
21 "$-_.+!*'(),,;/?:@=&\"<>#%{}|\\^~[]`",
22 }
23 c := &Client{}
24 for _, h := range validAPIHosts {
25 var err error
26 c.url, err = url.Parse(h)
27 if err != nil {
28 t.Fatalf("Unable to parse url %s: %s\n", h, err)
29 }
30 for _, p := range purgeAPIPaths {
31 for _, k := range cacheKeys {
32 r, err := c.RawRequest("GET", p+url.PathEscape(k), nil)
33 // Cannot test results for success if we get an error
34 if err != nil {
35 t.Fatal("Could not make RawRequest for ", h, p, k)
36 }
37 t.Log("Encoded path returned: ", r.URL.EscapedPath())
38 pk := p + url.PathEscape(k)
39 if p[0] != '/' {
40 pk = "/" + pk
41 }
42 t.Log("Encoded path expected: ", pk)
43 // Insure we don't get a path starting with an extra slash
44 // e.g. //service/myservice/purge/mykey
45 if r.URL.Path[1] == '/' {
46 t.Fatalf("Host and APIPath were joined incorrectly. Got: %s\n", r.URL.Path)
47 }
48 // Insure the encoded path isn't altered
49 if strings.Index(r.URL.EscapedPath(), p+url.PathEscape(k)) == -1 {
50 t.Fatalf("RawRequest altered the encoded path. New encoded path: %s, expecting: %s\n", r.URL.EscapedPath(), p+url.PathEscape(k))
51 }
52 }
53 }
54 }
55 }