-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly append slash to HTTP store paths as per #112
- Loading branch information
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
}) | ||
} | ||
} |