// Prepare two test Keep volumes. Our block is stored on the second volume.
KeepVM = MakeTestVolumeManager(2)
- defer func() { KeepVM.Quit() }()
+ defer KeepVM.Quit()
vols := KeepVM.Volumes()
if err := vols[0].Put(TEST_HASH, TEST_BLOCK); err != nil {
permission_ttl = time.Duration(300) * time.Second
var (
- unsigned_locator = "http://localhost:25107/" + TEST_HASH
+ unsigned_locator = "/" + TEST_HASH
valid_timestamp = time.Now().Add(permission_ttl)
expired_timestamp = time.Now().Add(-time.Hour)
- signed_locator = "http://localhost:25107/" + SignLocator(TEST_HASH, known_token, valid_timestamp)
- expired_locator = "http://localhost:25107/" + SignLocator(TEST_HASH, known_token, expired_timestamp)
+ signed_locator = "/" + SignLocator(TEST_HASH, known_token, valid_timestamp)
+ expired_locator = "/" + SignLocator(TEST_HASH, known_token, expired_timestamp)
)
// -----------------
// Prepare two test Keep volumes.
KeepVM = MakeTestVolumeManager(2)
- defer func() { KeepVM.Quit() }()
+ defer KeepVM.Quit()
// Set up a REST router for testing the handlers.
rest := MakeRESTRouter()
// Unauthenticated request, no server key
// => OK (unsigned response)
- unsigned_locator := "http://localhost:25107/" + TEST_HASH
+ unsigned_locator := "/" + TEST_HASH
response := IssueRequest(rest,
&RequestTester{
method: "PUT",
// Include multiple blocks on different volumes, and
// some metadata files (which should be omitted from index listings)
KeepVM = MakeTestVolumeManager(2)
- defer func() { KeepVM.Quit() }()
+ defer KeepVM.Quit()
vols := KeepVM.Volumes()
vols[0].Put(TEST_HASH, TEST_BLOCK)
unauthenticated_req := &RequestTester{
method: "GET",
- uri: "http://localhost:25107/index",
+ uri: "/index",
}
authenticated_req := &RequestTester{
method: "GET",
- uri: "http://localhost:25107/index",
+ uri: "/index",
api_token: known_token,
}
superuser_req := &RequestTester{
method: "GET",
- uri: "http://localhost:25107/index",
+ uri: "/index",
api_token: data_manager_token,
}
unauth_prefix_req := &RequestTester{
method: "GET",
- uri: "http://localhost:25107/index/" + TEST_HASH[0:3],
+ uri: "/index/" + TEST_HASH[0:3],
}
auth_prefix_req := &RequestTester{
method: "GET",
- uri: "http://localhost:25107/index/" + TEST_HASH[0:3],
+ uri: "/index/" + TEST_HASH[0:3],
api_token: known_token,
}
superuser_prefix_req := &RequestTester{
method: "GET",
- uri: "http://localhost:25107/index/" + TEST_HASH[0:3],
+ uri: "/index/" + TEST_HASH[0:3],
api_token: data_manager_token,
}
// TestDeleteHandler
//
-// Cases to test:
+// Cases tested:
//
// With no token and with a non-data-manager token:
// * Delete existing block
// Include multiple blocks on different volumes, and
// some metadata files (which should be omitted from index listings)
KeepVM = MakeTestVolumeManager(2)
- defer func() { KeepVM.Quit() }()
+ defer KeepVM.Quit()
vols := KeepVM.Volumes()
vols[0].Put(TEST_HASH, TEST_BLOCK)
unauth_req := &RequestTester{
method: "DELETE",
- uri: "http://localhost:25107/" + TEST_HASH,
+ uri: "/" + TEST_HASH,
}
user_req := &RequestTester{
method: "DELETE",
- uri: "http://localhost:25107/" + TEST_HASH,
+ uri: "/" + TEST_HASH,
api_token: user_token,
}
superuser_existing_block_req := &RequestTester{
method: "DELETE",
- uri: "http://localhost:25107/" + TEST_HASH,
+ uri: "/" + TEST_HASH,
api_token: data_manager_token,
}
superuser_nonexistent_block_req := &RequestTester{
method: "DELETE",
- uri: "http://localhost:25107/" + TEST_HASH_2,
+ uri: "/" + TEST_HASH_2,
api_token: data_manager_token,
}
Deleted int `json:"copies_deleted"`
Failed int `json:"copies_failed"`
}
- var dc deletecounter
+ var dc, expected_dc deletecounter
response = IssueRequest(rest, superuser_nonexistent_block_req)
ExpectStatusCode(t,
"data manager request, nonexistent block",
- http.StatusOK,
+ http.StatusNotFound,
response)
// Expect response {"copies_deleted":0,"copies_failed":0}
+ expected_dc = deletecounter{0, 0}
json.NewDecoder(response.Body).Decode(&dc)
- if dc.Deleted != 0 || dc.Failed != 0 {
- t.Errorf("superuser_nonexistent_block_req: response = %+v", dc)
+ if dc != expected_dc {
+ t.Errorf("superuser_nonexistent_block_req\nexpected: %+v\nreceived: %+v",
+ expected_dc, dc)
}
// Authenticated admin request for existing block.
http.StatusOK,
response)
// Expect response {"copies_deleted":1,"copies_failed":0}
+ expected_dc = deletecounter{1, 0}
json.NewDecoder(response.Body).Decode(&dc)
- if dc.Deleted != 1 || dc.Failed != 0 {
- t.Errorf("superuser_existing_block_req: response = %+v", dc)
+ if dc != expected_dc {
+ t.Errorf("superuser_existing_block_req\nexpected: %+v\nreceived: %+v",
+ expected_dc, dc)
}
// Confirm the block has been deleted
_, err := vols[0].Get(TEST_HASH)