forked from folbricht/desync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremotehttp_test.go
42 lines (39 loc) · 1.33 KB
/
remotehttp_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 desync
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestHTTPStoreURL(t *testing.T) {
var requestURI string
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestURI = r.RequestURI
}))
defer ts.Close()
u, _ := url.Parse(ts.URL)
chunkID := ChunkID{1, 2, 3, 4}
tests := map[string]struct {
storePath string
serverPath string
}{
"no path": {"", "/0102/0102030400000000000000000000000000000000000000000000000000000000.cacnk"},
"slash only": {"/", "/0102/0102030400000000000000000000000000000000000000000000000000000000.cacnk"},
"no trailing slash": {"/path", "/path/0102/0102030400000000000000000000000000000000000000000000000000000000.cacnk"},
"with trailing slash": {"/path/", "/path/0102/0102030400000000000000000000000000000000000000000000000000000000.cacnk"},
"long path": {"/path1/path2", "/path1/path2/0102/0102030400000000000000000000000000000000000000000000000000000000.cacnk"},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
u.Path = test.storePath
s, err := NewRemoteHTTPStore(u, StoreOptions{})
if err != nil {
t.Fatal(err)
}
s.GetChunk(chunkID)
if requestURI != test.serverPath {
t.Fatalf("got request uri '%s', want '%s'", requestURI, test.serverPath)
}
})
}
}