[ARVADOS] updated: 63f2191f07851bc66756de518644f2259b938d88
git at public.curoverse.com
git at public.curoverse.com
Mon Sep 14 09:33:59 EDT 2015
Summary of changes:
services/keepstore/handler_test.go | 106 ++++++++---------
services/keepstore/handlers.go | 2 +-
services/keepstore/keepstore_test.go | 116 +++++++++----------
services/keepstore/perms.go | 53 ++++-----
services/keepstore/perms_test.go | 66 +++++------
services/keepstore/trash_worker_test.go | 70 +++++------
services/keepstore/volume_generic_test.go | 186 +++++++++++++++---------------
services/keepstore/volume_unix_test.go | 48 ++++----
8 files changed, 324 insertions(+), 323 deletions(-)
via 63f2191f07851bc66756de518644f2259b938d88 (commit)
from 0ad0ce519da703b3f13c0ad8a74ea8235b7d90e5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 63f2191f07851bc66756de518644f2259b938d88
Author: radhika <radhika at curoverse.com>
Date: Mon Sep 14 09:33:13 2015 -0400
7179: some more golint suggested updates
diff --git a/services/keepstore/handler_test.go b/services/keepstore/handler_test.go
index 8191466..4ea4329 100644
--- a/services/keepstore/handler_test.go
+++ b/services/keepstore/handler_test.go
@@ -46,22 +46,22 @@ func TestGetHandler(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllWritable()
- if err := vols[0].Put(TEST_HASH, TEST_BLOCK); err != nil {
+ if err := vols[0].Put(TestHash, TestBlock); err != nil {
t.Error(err)
}
// Create locators for testing.
// Turn on permission settings so we can generate signed locators.
enforcePermissions = true
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
blob_signature_ttl = 300 * time.Second
var (
- unsignedLocator = "/" + TEST_HASH
+ unsignedLocator = "/" + TestHash
validTimestamp = time.Now().Add(blob_signature_ttl)
expiredTimestamp = time.Now().Add(-time.Hour)
- signedLocator = "/" + SignLocator(TEST_HASH, known_token, validTimestamp)
- expiredLocator = "/" + SignLocator(TEST_HASH, known_token, expiredTimestamp)
+ signedLocator = "/" + SignLocator(TestHash, knownToken, validTimestamp)
+ expiredLocator = "/" + SignLocator(TestHash, knownToken, expiredTimestamp)
)
// -----------------
@@ -79,11 +79,11 @@ func TestGetHandler(t *testing.T) {
"Unauthenticated request, unsigned locator", http.StatusOK, response)
ExpectBody(t,
"Unauthenticated request, unsigned locator",
- string(TEST_BLOCK),
+ string(TestBlock),
response)
receivedLen := response.Header().Get("Content-Length")
- expectedLen := fmt.Sprintf("%d", len(TEST_BLOCK))
+ expectedLen := fmt.Sprintf("%d", len(TestBlock))
if receivedLen != expectedLen {
t.Errorf("expected Content-Length %s, got %s", expectedLen, receivedLen)
}
@@ -97,15 +97,15 @@ func TestGetHandler(t *testing.T) {
response = IssueRequest(&RequestTester{
method: "GET",
uri: signedLocator,
- apiToken: known_token,
+ apiToken: knownToken,
})
ExpectStatusCode(t,
"Authenticated request, signed locator", http.StatusOK, response)
ExpectBody(t,
- "Authenticated request, signed locator", string(TEST_BLOCK), response)
+ "Authenticated request, signed locator", string(TestBlock), response)
receivedLen = response.Header().Get("Content-Length")
- expectedLen = fmt.Sprintf("%d", len(TEST_BLOCK))
+ expectedLen = fmt.Sprintf("%d", len(TestBlock))
if receivedLen != expectedLen {
t.Errorf("expected Content-Length %s, got %s", expectedLen, receivedLen)
}
@@ -115,7 +115,7 @@ func TestGetHandler(t *testing.T) {
response = IssueRequest(&RequestTester{
method: "GET",
uri: unsignedLocator,
- apiToken: known_token,
+ apiToken: knownToken,
})
ExpectStatusCode(t, "unsigned locator", PermissionError.HTTPCode, response)
@@ -134,7 +134,7 @@ func TestGetHandler(t *testing.T) {
response = IssueRequest(&RequestTester{
method: "GET",
uri: expiredLocator,
- apiToken: known_token,
+ apiToken: knownToken,
})
ExpectStatusCode(t,
"Authenticated request, expired locator",
@@ -158,24 +158,24 @@ func TestPutHandler(t *testing.T) {
// Unauthenticated request, no server key
// => OK (unsigned response)
- unsignedLocator := "/" + TEST_HASH
+ unsignedLocator := "/" + TestHash
response := IssueRequest(
&RequestTester{
method: "PUT",
uri: unsignedLocator,
- requestBody: TEST_BLOCK,
+ requestBody: TestBlock,
})
ExpectStatusCode(t,
"Unauthenticated request, no server key", http.StatusOK, response)
ExpectBody(t,
"Unauthenticated request, no server key",
- TEST_HASH_PUT_RESPONSE, response)
+ TestHashPutResp, response)
// ------------------
// With a server key.
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
blob_signature_ttl = 300 * time.Second
// When a permission key is available, the locator returned
@@ -187,15 +187,15 @@ func TestPutHandler(t *testing.T) {
&RequestTester{
method: "PUT",
uri: unsignedLocator,
- requestBody: TEST_BLOCK,
- apiToken: known_token,
+ requestBody: TestBlock,
+ apiToken: knownToken,
})
ExpectStatusCode(t,
"Authenticated PUT, signed locator, with server key",
http.StatusOK, response)
responseLocator := strings.TrimSpace(response.Body.String())
- if VerifySignature(responseLocator, known_token) != nil {
+ if VerifySignature(responseLocator, knownToken) != nil {
t.Errorf("Authenticated PUT, signed locator, with server key:\n"+
"response '%s' does not contain a valid signature",
responseLocator)
@@ -207,7 +207,7 @@ func TestPutHandler(t *testing.T) {
&RequestTester{
method: "PUT",
uri: unsignedLocator,
- requestBody: TEST_BLOCK,
+ requestBody: TestBlock,
})
ExpectStatusCode(t,
@@ -215,7 +215,7 @@ func TestPutHandler(t *testing.T) {
http.StatusOK, response)
ExpectBody(t,
"Unauthenticated PUT, unsigned locator, with server key",
- TEST_HASH_PUT_RESPONSE, response)
+ TestHashPutResp, response)
}
func TestPutAndDeleteSkipReadonlyVolumes(t *testing.T) {
@@ -228,8 +228,8 @@ func TestPutAndDeleteSkipReadonlyVolumes(t *testing.T) {
IssueRequest(
&RequestTester{
method: "PUT",
- uri: "/" + TEST_HASH,
- requestBody: TEST_BLOCK,
+ uri: "/" + TestHash,
+ requestBody: TestBlock,
})
defer func(orig bool) {
never_delete = orig
@@ -238,8 +238,8 @@ func TestPutAndDeleteSkipReadonlyVolumes(t *testing.T) {
IssueRequest(
&RequestTester{
method: "DELETE",
- uri: "/" + TEST_HASH,
- requestBody: TEST_BLOCK,
+ uri: "/" + TestHash,
+ requestBody: TestBlock,
apiToken: data_manager_token,
})
type expect struct {
@@ -286,10 +286,10 @@ func TestIndexHandler(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllWritable()
- vols[0].Put(TEST_HASH, TEST_BLOCK)
- vols[1].Put(TEST_HASH_2, TEST_BLOCK_2)
- vols[0].Put(TEST_HASH+".meta", []byte("metadata"))
- vols[1].Put(TEST_HASH_2+".meta", []byte("metadata"))
+ vols[0].Put(TestHash, TestBlock)
+ vols[1].Put(TestHash2, TestBlock2)
+ vols[0].Put(TestHash+".meta", []byte("metadata"))
+ vols[1].Put(TestHash2+".meta", []byte("metadata"))
data_manager_token = "DATA MANAGER TOKEN"
@@ -300,7 +300,7 @@ func TestIndexHandler(t *testing.T) {
authenticatedReq := &RequestTester{
method: "GET",
uri: "/index",
- apiToken: known_token,
+ apiToken: knownToken,
}
superuserReq := &RequestTester{
method: "GET",
@@ -309,16 +309,16 @@ func TestIndexHandler(t *testing.T) {
}
unauthPrefixReq := &RequestTester{
method: "GET",
- uri: "/index/" + TEST_HASH[0:3],
+ uri: "/index/" + TestHash[0:3],
}
authPrefixReq := &RequestTester{
method: "GET",
- uri: "/index/" + TEST_HASH[0:3],
- apiToken: known_token,
+ uri: "/index/" + TestHash[0:3],
+ apiToken: knownToken,
}
superuserPrefixReq := &RequestTester{
method: "GET",
- uri: "/index/" + TEST_HASH[0:3],
+ uri: "/index/" + TestHash[0:3],
apiToken: data_manager_token,
}
@@ -383,8 +383,8 @@ func TestIndexHandler(t *testing.T) {
http.StatusOK,
response)
- expected := `^` + TEST_HASH + `\+\d+ \d+\n` +
- TEST_HASH_2 + `\+\d+ \d+\n\n$`
+ expected := `^` + TestHash + `\+\d+ \d+\n` +
+ TestHash2 + `\+\d+ \d+\n\n$`
match, _ := regexp.MatchString(expected, response.Body.String())
if !match {
t.Errorf(
@@ -400,7 +400,7 @@ func TestIndexHandler(t *testing.T) {
http.StatusOK,
response)
- expected = `^` + TEST_HASH + `\+\d+ \d+\n\n$`
+ expected = `^` + TestHash + `\+\d+ \d+\n\n$`
match, _ = regexp.MatchString(expected, response.Body.String())
if !match {
t.Errorf(
@@ -445,7 +445,7 @@ func TestDeleteHandler(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllWritable()
- vols[0].Put(TEST_HASH, TEST_BLOCK)
+ vols[0].Put(TestHash, TestBlock)
// Explicitly set the blob_signature_ttl to 0 for these
// tests, to ensure the MockVolume deletes the blocks
@@ -459,24 +459,24 @@ func TestDeleteHandler(t *testing.T) {
unauthReq := &RequestTester{
method: "DELETE",
- uri: "/" + TEST_HASH,
+ uri: "/" + TestHash,
}
userReq := &RequestTester{
method: "DELETE",
- uri: "/" + TEST_HASH,
+ uri: "/" + TestHash,
apiToken: userToken,
}
superuserExistingBlockReq := &RequestTester{
method: "DELETE",
- uri: "/" + TEST_HASH,
+ uri: "/" + TestHash,
apiToken: data_manager_token,
}
superuserNonexistentBlockReq := &RequestTester{
method: "DELETE",
- uri: "/" + TEST_HASH_2,
+ uri: "/" + TestHash2,
apiToken: data_manager_token,
}
@@ -531,7 +531,7 @@ func TestDeleteHandler(t *testing.T) {
expectedDc, responseDc)
}
// Confirm the block has been deleted
- _, err := vols[0].Get(TEST_HASH)
+ _, err := vols[0].Get(TestHash)
var blockDeleted = os.IsNotExist(err)
if !blockDeleted {
t.Error("superuserExistingBlockReq: block not deleted")
@@ -539,7 +539,7 @@ func TestDeleteHandler(t *testing.T) {
// A DELETE request on a block newer than blob_signature_ttl
// should return success but leave the block on the volume.
- vols[0].Put(TEST_HASH, TEST_BLOCK)
+ vols[0].Put(TestHash, TestBlock)
blob_signature_ttl = time.Hour
response = IssueRequest(superuserExistingBlockReq)
@@ -555,7 +555,7 @@ func TestDeleteHandler(t *testing.T) {
expectedDc, responseDc)
}
// Confirm the block has NOT been deleted.
- _, err = vols[0].Get(TEST_HASH)
+ _, err = vols[0].Get(TestHash)
if err != nil {
t.Errorf("testing delete on new block: %s\n", err)
}
@@ -830,8 +830,8 @@ func TestPutNeedsOnlyOneBuffer(t *testing.T) {
response := IssueRequest(
&RequestTester{
method: "PUT",
- uri: "/" + TEST_HASH,
- requestBody: TEST_BLOCK,
+ uri: "/" + TestHash,
+ requestBody: TestBlock,
})
ExpectStatusCode(t,
"TestPutNeedsOnlyOneBuffer", http.StatusOK, response)
@@ -860,18 +860,18 @@ func TestPutHandlerNoBufferleak(t *testing.T) {
for i := 0; i < maxBuffers+1; i++ {
// Unauthenticated request, no server key
// => OK (unsigned response)
- unsignedLocator := "/" + TEST_HASH
+ unsignedLocator := "/" + TestHash
response := IssueRequest(
&RequestTester{
method: "PUT",
uri: unsignedLocator,
- requestBody: TEST_BLOCK,
+ requestBody: TestBlock,
})
ExpectStatusCode(t,
"TestPutHandlerBufferleak", http.StatusOK, response)
ExpectBody(t,
"TestPutHandlerBufferleak",
- TEST_HASH_PUT_RESPONSE, response)
+ TestHashPutResp, response)
}
ok <- true
}()
@@ -893,7 +893,7 @@ func TestGetHandlerNoBufferleak(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllWritable()
- if err := vols[0].Put(TEST_HASH, TEST_BLOCK); err != nil {
+ if err := vols[0].Put(TestHash, TestBlock); err != nil {
t.Error(err)
}
@@ -902,7 +902,7 @@ func TestGetHandlerNoBufferleak(t *testing.T) {
for i := 0; i < maxBuffers+1; i++ {
// Unauthenticated request, unsigned locator
// => OK
- unsignedLocator := "/" + TEST_HASH
+ unsignedLocator := "/" + TestHash
response := IssueRequest(
&RequestTester{
method: "GET",
@@ -912,7 +912,7 @@ func TestGetHandlerNoBufferleak(t *testing.T) {
"Unauthenticated request, unsigned locator", http.StatusOK, response)
ExpectBody(t,
"Unauthenticated request, unsigned locator",
- string(TEST_BLOCK),
+ string(TestBlock),
response)
}
ok <- true
diff --git a/services/keepstore/handlers.go b/services/keepstore/handlers.go
index 0974549..8c9b849 100644
--- a/services/keepstore/handlers.go
+++ b/services/keepstore/handlers.go
@@ -618,7 +618,7 @@ func IsValidLocator(loc string) bool {
var authRe = regexp.MustCompile(`^OAuth2\s+(.*)`)
-// GetAPIToken returns the OAuth2 token from the Authorization
+// GetApiToken returns the OAuth2 token from the Authorization
// header of a HTTP request, or an empty string if no matching
// token is found.
func GetApiToken(req *http.Request) string {
diff --git a/services/keepstore/keepstore_test.go b/services/keepstore/keepstore_test.go
index eaf3560..dc641ab 100644
--- a/services/keepstore/keepstore_test.go
+++ b/services/keepstore/keepstore_test.go
@@ -12,19 +12,19 @@ import (
"testing"
)
-var TEST_BLOCK = []byte("The quick brown fox jumps over the lazy dog.")
-var TEST_HASH = "e4d909c290d0fb1ca068ffaddf22cbd0"
-var TEST_HASH_PUT_RESPONSE = "e4d909c290d0fb1ca068ffaddf22cbd0+44\n"
+var TestBlock = []byte("The quick brown fox jumps over the lazy dog.")
+var TestHash = "e4d909c290d0fb1ca068ffaddf22cbd0"
+var TestHashPutResp = "e4d909c290d0fb1ca068ffaddf22cbd0+44\n"
-var TEST_BLOCK_2 = []byte("Pack my box with five dozen liquor jugs.")
-var TEST_HASH_2 = "f15ac516f788aec4f30932ffb6395c39"
+var TestBlock2 = []byte("Pack my box with five dozen liquor jugs.")
+var TestHash2 = "f15ac516f788aec4f30932ffb6395c39"
-var TEST_BLOCK_3 = []byte("Now is the time for all good men to come to the aid of their country.")
-var TEST_HASH_3 = "eed29bbffbc2dbe5e5ee0bb71888e61f"
+var TestBlock3 = []byte("Now is the time for all good men to come to the aid of their country.")
+var TestHash3 = "eed29bbffbc2dbe5e5ee0bb71888e61f"
-// BAD_BLOCK is used to test collisions and corruption.
+// BadBlock is used to test collisions and corruption.
// It must not match any test hashes.
-var BAD_BLOCK = []byte("The magic words are squeamish ossifrage.")
+var BadBlock = []byte("The magic words are squeamish ossifrage.")
// TODO(twp): Tests still to be written
//
@@ -55,17 +55,17 @@ func TestGetBlock(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllReadable()
- if err := vols[1].Put(TEST_HASH, TEST_BLOCK); err != nil {
+ if err := vols[1].Put(TestHash, TestBlock); err != nil {
t.Error(err)
}
// Check that GetBlock returns success.
- result, err := GetBlock(TEST_HASH)
+ result, err := GetBlock(TestHash)
if err != nil {
t.Errorf("GetBlock error: %s", err)
}
- if fmt.Sprint(result) != fmt.Sprint(TEST_BLOCK) {
- t.Errorf("expected %s, got %s", TEST_BLOCK, result)
+ if fmt.Sprint(result) != fmt.Sprint(TestBlock) {
+ t.Errorf("expected %s, got %s", TestBlock, result)
}
}
@@ -80,7 +80,7 @@ func TestGetBlockMissing(t *testing.T) {
defer KeepVM.Close()
// Check that GetBlock returns failure.
- result, err := GetBlock(TEST_HASH)
+ result, err := GetBlock(TestHash)
if err != NotFoundError {
t.Errorf("Expected NotFoundError, got %v", result)
}
@@ -98,10 +98,10 @@ func TestGetBlockCorrupt(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllReadable()
- vols[0].Put(TEST_HASH, BAD_BLOCK)
+ vols[0].Put(TestHash, BadBlock)
// Check that GetBlock returns failure.
- result, err := GetBlock(TEST_HASH)
+ result, err := GetBlock(TestHash)
if err != DiskHashError {
t.Errorf("Expected DiskHashError, got %v (buf: %v)", err, result)
}
@@ -122,18 +122,18 @@ func TestPutBlockOK(t *testing.T) {
defer KeepVM.Close()
// Check that PutBlock stores the data as expected.
- if err := PutBlock(TEST_BLOCK, TEST_HASH); err != nil {
+ if err := PutBlock(TestBlock, TestHash); err != nil {
t.Fatalf("PutBlock: %v", err)
}
vols := KeepVM.AllReadable()
- result, err := vols[1].Get(TEST_HASH)
+ result, err := vols[1].Get(TestHash)
if err != nil {
t.Fatalf("Volume #0 Get returned error: %v", err)
}
- if string(result) != string(TEST_BLOCK) {
+ if string(result) != string(TestBlock) {
t.Fatalf("PutBlock stored '%s', Get retrieved '%s'",
- string(TEST_BLOCK), string(result))
+ string(TestBlock), string(result))
}
}
@@ -152,18 +152,18 @@ func TestPutBlockOneVol(t *testing.T) {
vols[0].(*MockVolume).Bad = true
// Check that PutBlock stores the data as expected.
- if err := PutBlock(TEST_BLOCK, TEST_HASH); err != nil {
+ if err := PutBlock(TestBlock, TestHash); err != nil {
t.Fatalf("PutBlock: %v", err)
}
- result, err := GetBlock(TEST_HASH)
+ result, err := GetBlock(TestHash)
if err != nil {
t.Fatalf("GetBlock: %v", err)
}
- if string(result) != string(TEST_BLOCK) {
+ if string(result) != string(TestBlock) {
t.Error("PutBlock/GetBlock mismatch")
t.Fatalf("PutBlock stored '%s', GetBlock retrieved '%s'",
- string(TEST_BLOCK), string(result))
+ string(TestBlock), string(result))
}
}
@@ -180,12 +180,12 @@ func TestPutBlockMD5Fail(t *testing.T) {
// Check that PutBlock returns the expected error when the hash does
// not match the block.
- if err := PutBlock(BAD_BLOCK, TEST_HASH); err != RequestHashError {
+ if err := PutBlock(BadBlock, TestHash); err != RequestHashError {
t.Error("Expected RequestHashError, got %v", err)
}
// Confirm that GetBlock fails to return anything.
- if result, err := GetBlock(TEST_HASH); err != NotFoundError {
+ if result, err := GetBlock(TestHash); err != NotFoundError {
t.Errorf("GetBlock succeeded after a corrupt block store (result = %s, err = %v)",
string(result), err)
}
@@ -202,17 +202,17 @@ func TestPutBlockCorrupt(t *testing.T) {
KeepVM = MakeTestVolumeManager(2)
defer KeepVM.Close()
- // Store a corrupted block under TEST_HASH.
+ // Store a corrupted block under TestHash.
vols := KeepVM.AllWritable()
- vols[0].Put(TEST_HASH, BAD_BLOCK)
- if err := PutBlock(TEST_BLOCK, TEST_HASH); err != nil {
+ vols[0].Put(TestHash, BadBlock)
+ if err := PutBlock(TestBlock, TestHash); err != nil {
t.Errorf("PutBlock: %v", err)
}
- // The block on disk should now match TEST_BLOCK.
- if block, err := GetBlock(TEST_HASH); err != nil {
+ // The block on disk should now match TestBlock.
+ if block, err := GetBlock(TestHash); err != nil {
t.Errorf("GetBlock: %v", err)
- } else if bytes.Compare(block, TEST_BLOCK) != 0 {
+ } else if bytes.Compare(block, TestBlock) != 0 {
t.Errorf("GetBlock returned: '%s'", string(block))
}
}
@@ -260,35 +260,35 @@ func TestPutBlockTouchFails(t *testing.T) {
// Store a block and then make the underlying volume bad,
// so a subsequent attempt to update the file timestamp
// will fail.
- vols[0].Put(TEST_HASH, BAD_BLOCK)
- old_mtime, err := vols[0].Mtime(TEST_HASH)
+ vols[0].Put(TestHash, BadBlock)
+ oldMtime, err := vols[0].Mtime(TestHash)
if err != nil {
- t.Fatalf("vols[0].Mtime(%s): %s\n", TEST_HASH, err)
+ t.Fatalf("vols[0].Mtime(%s): %s\n", TestHash, err)
}
// vols[0].Touch will fail on the next call, so the volume
// manager will store a copy on vols[1] instead.
vols[0].(*MockVolume).Touchable = false
- if err := PutBlock(TEST_BLOCK, TEST_HASH); err != nil {
+ if err := PutBlock(TestBlock, TestHash); err != nil {
t.Fatalf("PutBlock: %v", err)
}
vols[0].(*MockVolume).Touchable = true
// Now the mtime on the block on vols[0] should be unchanged, and
// there should be a copy of the block on vols[1].
- new_mtime, err := vols[0].Mtime(TEST_HASH)
+ newMtime, err := vols[0].Mtime(TestHash)
if err != nil {
- t.Fatalf("vols[0].Mtime(%s): %s\n", TEST_HASH, err)
+ t.Fatalf("vols[0].Mtime(%s): %s\n", TestHash, err)
}
- if !new_mtime.Equal(old_mtime) {
- t.Errorf("mtime was changed on vols[0]:\nold_mtime = %v\nnew_mtime = %v\n",
- old_mtime, new_mtime)
+ if !newMtime.Equal(oldMtime) {
+ t.Errorf("mtime was changed on vols[0]:\noldMtime = %v\nnewMtime = %v\n",
+ oldMtime, newMtime)
}
- result, err := vols[1].Get(TEST_HASH)
+ result, err := vols[1].Get(TestHash)
if err != nil {
t.Fatalf("vols[1]: %v", err)
}
- if bytes.Compare(result, TEST_BLOCK) != 0 {
+ if bytes.Compare(result, TestBlock) != 0 {
t.Errorf("new block does not match test block\nnew block = %v\n", result)
}
}
@@ -388,23 +388,23 @@ func TestIndex(t *testing.T) {
defer KeepVM.Close()
vols := KeepVM.AllReadable()
- vols[0].Put(TEST_HASH, TEST_BLOCK)
- vols[1].Put(TEST_HASH_2, TEST_BLOCK_2)
- vols[0].Put(TEST_HASH_3, TEST_BLOCK_3)
- vols[0].Put(TEST_HASH+".meta", []byte("metadata"))
- vols[1].Put(TEST_HASH_2+".meta", []byte("metadata"))
+ vols[0].Put(TestHash, TestBlock)
+ vols[1].Put(TestHash2, TestBlock2)
+ vols[0].Put(TestHash3, TestBlock3)
+ vols[0].Put(TestHash+".meta", []byte("metadata"))
+ vols[1].Put(TestHash2+".meta", []byte("metadata"))
buf := new(bytes.Buffer)
vols[0].IndexTo("", buf)
vols[1].IndexTo("", buf)
- index_rows := strings.Split(string(buf.Bytes()), "\n")
- sort.Strings(index_rows)
- sorted_index := strings.Join(index_rows, "\n")
- expected := `^\n` + TEST_HASH + `\+\d+ \d+\n` +
- TEST_HASH_3 + `\+\d+ \d+\n` +
- TEST_HASH_2 + `\+\d+ \d+$`
-
- match, err := regexp.MatchString(expected, sorted_index)
+ indexRows := strings.Split(string(buf.Bytes()), "\n")
+ sort.Strings(indexRows)
+ sortedIndex := strings.Join(indexRows, "\n")
+ expected := `^\n` + TestHash + `\+\d+ \d+\n` +
+ TestHash3 + `\+\d+ \d+\n` +
+ TestHash2 + `\+\d+ \d+$`
+
+ match, err := regexp.MatchString(expected, sortedIndex)
if err == nil {
if !match {
t.Errorf("IndexLocators returned:\n%s", string(buf.Bytes()))
@@ -420,8 +420,8 @@ func TestIndex(t *testing.T) {
// MakeTestVolumeManager returns a RRVolumeManager with the specified
// number of MockVolumes.
-func MakeTestVolumeManager(num_volumes int) VolumeManager {
- vols := make([]Volume, num_volumes)
+func MakeTestVolumeManager(numVolumes int) VolumeManager {
+ vols := make([]Volume, numVolumes)
for i := range vols {
vols[i] = CreateMockVolume()
}
diff --git a/services/keepstore/perms.go b/services/keepstore/perms.go
index 65160b1..5579238 100644
--- a/services/keepstore/perms.go
+++ b/services/keepstore/perms.go
@@ -51,65 +51,66 @@ import (
var PermissionSecret []byte
// MakePermSignature returns a string representing the signed permission
-// hint for the blob identified by blob_hash, api_token and expiration timestamp.
-func MakePermSignature(blob_hash string, api_token string, expiry string) string {
+// hint for the blob identified by blobHash, apiToken and expiration timestamp.
+func MakePermSignature(blobHash string, apiToken string, expiry string) string {
hmac := hmac.New(sha1.New, PermissionSecret)
- hmac.Write([]byte(blob_hash))
+ hmac.Write([]byte(blobHash))
hmac.Write([]byte("@"))
- hmac.Write([]byte(api_token))
+ hmac.Write([]byte(apiToken))
hmac.Write([]byte("@"))
hmac.Write([]byte(expiry))
digest := hmac.Sum(nil)
return fmt.Sprintf("%x", digest)
}
-// SignLocator takes a blob_locator, an api_token and an expiry time, and
+// SignLocator takes a blobLocator, an apiToken and an expiry time, and
// returns a signed locator string.
-func SignLocator(blob_locator string, api_token string, expiry time.Time) string {
+func SignLocator(blobLocator string, apiToken string, expiry time.Time) string {
// If no permission secret or API token is available,
// return an unsigned locator.
- if PermissionSecret == nil || api_token == "" {
- return blob_locator
+ if PermissionSecret == nil || apiToken == "" {
+ return blobLocator
}
// Extract the hash from the blob locator, omitting any size hint that may be present.
- blob_hash := strings.Split(blob_locator, "+")[0]
+ blobHash := strings.Split(blobLocator, "+")[0]
// Return the signed locator string.
- timestamp_hex := fmt.Sprintf("%08x", expiry.Unix())
- return blob_locator +
- "+A" + MakePermSignature(blob_hash, api_token, timestamp_hex) +
- "@" + timestamp_hex
+ timestampHex := fmt.Sprintf("%08x", expiry.Unix())
+ return blobLocator +
+ "+A" + MakePermSignature(blobHash, apiToken, timestampHex) +
+ "@" + timestampHex
}
var signedLocatorRe = regexp.MustCompile(`^([[:xdigit:]]{32}).*\+A([[:xdigit:]]{40})@([[:xdigit:]]{8})`)
-// VerifySignature returns nil if the signature on the signed_locator
-// can be verified using the given api_token. Otherwise it returns
+// VerifySignature returns nil if the signature on the signedLocator
+// can be verified using the given apiToken. Otherwise it returns
// either ExpiredError (if the timestamp has expired, which is
// something the client could have figured out independently) or
// PermissionError.
-func VerifySignature(signed_locator string, api_token string) error {
- matches := signedLocatorRe.FindStringSubmatch(signed_locator)
+func VerifySignature(signedLocator string, apiToken string) error {
+ matches := signedLocatorRe.FindStringSubmatch(signedLocator)
if matches == nil {
// Could not find a permission signature at all
return PermissionError
}
- blob_hash := matches[1]
- sig_hex := matches[2]
- exp_hex := matches[3]
- if exp_time, err := ParseHexTimestamp(exp_hex); err != nil {
+ blobHash := matches[1]
+ sigHex := matches[2]
+ expHex := matches[3]
+ if expTime, err := ParseHexTimestamp(expHex); err != nil {
return PermissionError
- } else if exp_time.Before(time.Now()) {
+ } else if expTime.Before(time.Now()) {
return ExpiredError
}
- if sig_hex != MakePermSignature(blob_hash, api_token, exp_hex) {
+ if sigHex != MakePermSignature(blobHash, apiToken, expHex) {
return PermissionError
}
return nil
}
-func ParseHexTimestamp(timestamp_hex string) (ts time.Time, err error) {
- if ts_int, e := strconv.ParseInt(timestamp_hex, 16, 0); e == nil {
- ts = time.Unix(ts_int, 0)
+// ParseHexTimestamp parses timestamp
+func ParseHexTimestamp(timestampHex string) (ts time.Time, err error) {
+ if tsInt, e := strconv.ParseInt(timestampHex, 16, 0); e == nil {
+ ts = time.Unix(tsInt, 0)
} else {
err = e
}
diff --git a/services/keepstore/perms_test.go b/services/keepstore/perms_test.go
index e43cb8d..59516af 100644
--- a/services/keepstore/perms_test.go
+++ b/services/keepstore/perms_test.go
@@ -6,91 +6,91 @@ import (
)
const (
- known_hash = "acbd18db4cc2f85cedef654fccc4a4d8"
- known_locator = known_hash + "+3"
- known_token = "hocfupkn2pjhrpgp2vxv8rsku7tvtx49arbc9s4bvu7p7wxqvk"
- known_key = "13u9fkuccnboeewr0ne3mvapk28epf68a3bhj9q8sb4l6e4e5mkk" +
+ knownHash = "acbd18db4cc2f85cedef654fccc4a4d8"
+ knownLocator = knownHash + "+3"
+ knownToken = "hocfupkn2pjhrpgp2vxv8rsku7tvtx49arbc9s4bvu7p7wxqvk"
+ knownKey = "13u9fkuccnboeewr0ne3mvapk28epf68a3bhj9q8sb4l6e4e5mkk" +
"p6nhj2mmpscgu1zze5h5enydxfe3j215024u16ij4hjaiqs5u4pzsl3nczmaoxnc" +
"ljkm4875xqn4xv058koz3vkptmzhyheiy6wzevzjmdvxhvcqsvr5abhl15c2d4o4" +
"jhl0s91lojy1mtrzqqvprqcverls0xvy9vai9t1l1lvvazpuadafm71jl4mrwq2y" +
"gokee3eamvjy8qq1fvy238838enjmy5wzy2md7yvsitp5vztft6j4q866efym7e6" +
"vu5wm9fpnwjyxfldw3vbo01mgjs75rgo7qioh8z8ij7jpyp8508okhgbbex3ceei" +
"786u5rw2a9gx743dj3fgq2irk"
- known_signature = "257f3f5f5f0a4e4626a18fc74bd42ec34dcb228a"
- known_timestamp = "7fffffff"
- known_sig_hint = "+A" + known_signature + "@" + known_timestamp
- known_signed_locator = known_locator + known_sig_hint
+ knownSignature = "257f3f5f5f0a4e4626a18fc74bd42ec34dcb228a"
+ knownTimestamp = "7fffffff"
+ knownSigHint = "+A" + knownSignature + "@" + knownTimestamp
+ knownSignedLocator = knownLocator + knownSigHint
)
func TestSignLocator(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- if ts, err := ParseHexTimestamp(known_timestamp); err != nil {
- t.Errorf("bad known_timestamp %s", known_timestamp)
+ if ts, err := ParseHexTimestamp(knownTimestamp); err != nil {
+ t.Errorf("bad knownTimestamp %s", knownTimestamp)
} else {
- if known_signed_locator != SignLocator(known_locator, known_token, ts) {
+ if knownSignedLocator != SignLocator(knownLocator, knownToken, ts) {
t.Fail()
}
}
}
func TestVerifySignature(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- if VerifySignature(known_signed_locator, known_token) != nil {
+ if VerifySignature(knownSignedLocator, knownToken) != nil {
t.Fail()
}
}
func TestVerifySignatureExtraHints(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- if VerifySignature(known_locator+"+K at xyzzy"+known_sig_hint, known_token) != nil {
+ if VerifySignature(knownLocator+"+K at xyzzy"+knownSigHint, knownToken) != nil {
t.Fatal("Verify cannot handle hint before permission signature")
}
- if VerifySignature(known_locator+known_sig_hint+"+Zfoo", known_token) != nil {
+ if VerifySignature(knownLocator+knownSigHint+"+Zfoo", knownToken) != nil {
t.Fatal("Verify cannot handle hint after permission signature")
}
- if VerifySignature(known_locator+"+K at xyzzy"+known_sig_hint+"+Zfoo", known_token) != nil {
+ if VerifySignature(knownLocator+"+K at xyzzy"+knownSigHint+"+Zfoo", knownToken) != nil {
t.Fatal("Verify cannot handle hints around permission signature")
}
}
// The size hint on the locator string should not affect signature validation.
func TestVerifySignatureWrongSize(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- if VerifySignature(known_hash+"+999999"+known_sig_hint, known_token) != nil {
+ if VerifySignature(knownHash+"+999999"+knownSigHint, knownToken) != nil {
t.Fatal("Verify cannot handle incorrect size hint")
}
- if VerifySignature(known_hash+known_sig_hint, known_token) != nil {
+ if VerifySignature(knownHash+knownSigHint, knownToken) != nil {
t.Fatal("Verify cannot handle missing size hint")
}
}
func TestVerifySignatureBadSig(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- bad_locator := known_locator + "+Aaaaaaaaaaaaaaaa@" + known_timestamp
- if VerifySignature(bad_locator, known_token) != PermissionError {
+ badLocator := knownLocator + "+Aaaaaaaaaaaaaaaa@" + knownTimestamp
+ if VerifySignature(badLocator, knownToken) != PermissionError {
t.Fail()
}
}
func TestVerifySignatureBadTimestamp(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- bad_locator := known_locator + "+A" + known_signature + "@OOOOOOOl"
- if VerifySignature(bad_locator, known_token) != PermissionError {
+ badLocator := knownLocator + "+A" + knownSignature + "@OOOOOOOl"
+ if VerifySignature(badLocator, knownToken) != PermissionError {
t.Fail()
}
}
@@ -99,27 +99,27 @@ func TestVerifySignatureBadSecret(t *testing.T) {
PermissionSecret = []byte("00000000000000000000")
defer func() { PermissionSecret = nil }()
- if VerifySignature(known_signed_locator, known_token) != PermissionError {
+ if VerifySignature(knownSignedLocator, knownToken) != PermissionError {
t.Fail()
}
}
func TestVerifySignatureBadToken(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
- if VerifySignature(known_signed_locator, "00000000") != PermissionError {
+ if VerifySignature(knownSignedLocator, "00000000") != PermissionError {
t.Fail()
}
}
func TestVerifySignatureExpired(t *testing.T) {
- PermissionSecret = []byte(known_key)
+ PermissionSecret = []byte(knownKey)
defer func() { PermissionSecret = nil }()
yesterday := time.Now().AddDate(0, 0, -1)
- expired_locator := SignLocator(known_hash, known_token, yesterday)
- if VerifySignature(expired_locator, known_token) != ExpiredError {
+ expiredLocator := SignLocator(knownHash, knownToken, yesterday)
+ if VerifySignature(expiredLocator, knownToken) != ExpiredError {
t.Fail()
}
}
diff --git a/services/keepstore/trash_worker_test.go b/services/keepstore/trash_worker_test.go
index a626d9b..016ad28 100644
--- a/services/keepstore/trash_worker_test.go
+++ b/services/keepstore/trash_worker_test.go
@@ -55,15 +55,15 @@ func TestTrashWorkerIntegration_GetNonExistingLocator(t *testing.T) {
func TestTrashWorkerIntegration_LocatorInVolume1(t *testing.T) {
never_delete = false
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH_2,
- Block2: TEST_BLOCK_2,
+ Locator2: TestHash2,
+ Block2: TestBlock2,
CreateData: true,
- DeleteLocator: TEST_HASH, // first locator
+ DeleteLocator: TestHash, // first locator
ExpectLocator1: false,
ExpectLocator2: true,
@@ -77,15 +77,15 @@ func TestTrashWorkerIntegration_LocatorInVolume1(t *testing.T) {
func TestTrashWorkerIntegration_LocatorInVolume2(t *testing.T) {
never_delete = false
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH_2,
- Block2: TEST_BLOCK_2,
+ Locator2: TestHash2,
+ Block2: TestBlock2,
CreateData: true,
- DeleteLocator: TEST_HASH_2, // locator 2
+ DeleteLocator: TestHash2, // locator 2
ExpectLocator1: true,
ExpectLocator2: false,
@@ -99,15 +99,15 @@ func TestTrashWorkerIntegration_LocatorInVolume2(t *testing.T) {
func TestTrashWorkerIntegration_LocatorInBothVolumes(t *testing.T) {
never_delete = false
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH,
- Block2: TEST_BLOCK,
+ Locator2: TestHash,
+ Block2: TestBlock,
CreateData: true,
- DeleteLocator: TEST_HASH,
+ DeleteLocator: TestHash,
ExpectLocator1: false,
ExpectLocator2: false,
@@ -121,16 +121,16 @@ func TestTrashWorkerIntegration_LocatorInBothVolumes(t *testing.T) {
func TestTrashWorkerIntegration_MtimeMatchesForLocator1ButNotForLocator2(t *testing.T) {
never_delete = false
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH,
- Block2: TEST_BLOCK,
+ Locator2: TestHash,
+ Block2: TestBlock,
CreateData: true,
DifferentMtimes: true,
- DeleteLocator: TEST_HASH,
+ DeleteLocator: TestHash,
ExpectLocator1: true,
ExpectLocator2: false,
@@ -145,16 +145,16 @@ func TestTrashWorkerIntegration_MtimeMatchesForLocator1ButNotForLocator2(t *test
func TestTrashWorkerIntegration_TwoDifferentLocatorsInVolume1(t *testing.T) {
never_delete = false
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH_2,
- Block2: TEST_BLOCK_2,
+ Locator2: TestHash2,
+ Block2: TestBlock2,
CreateData: true,
CreateInVolume1: true,
- DeleteLocator: TEST_HASH, // locator 1
+ DeleteLocator: TestHash, // locator 1
ExpectLocator1: false,
ExpectLocator2: true,
@@ -168,18 +168,18 @@ func TestTrashWorkerIntegration_TwoDifferentLocatorsInVolume1(t *testing.T) {
func TestTrashWorkerIntegration_SameLocatorInTwoVolumesWithDefaultTrashLifeTime(t *testing.T) {
never_delete = false
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH_2,
- Block2: TEST_BLOCK_2,
+ Locator2: TestHash2,
+ Block2: TestBlock2,
CreateData: true,
CreateInVolume1: true,
UseTrashLifeTime: true,
- DeleteLocator: TEST_HASH, // locator 1
+ DeleteLocator: TestHash, // locator 1
// Since trash life time is in effect, block won't be deleted.
ExpectLocator1: true,
@@ -194,15 +194,15 @@ func TestTrashWorkerIntegration_SameLocatorInTwoVolumesWithDefaultTrashLifeTime(
func TestTrashWorkerIntegration_NeverDelete(t *testing.T) {
never_delete = true
testData := TrashWorkerTestData{
- Locator1: TEST_HASH,
- Block1: TEST_BLOCK,
+ Locator1: TestHash,
+ Block1: TestBlock,
- Locator2: TEST_HASH,
- Block2: TEST_BLOCK,
+ Locator2: TestHash,
+ Block2: TestBlock,
CreateData: true,
- DeleteLocator: TEST_HASH,
+ DeleteLocator: TestHash,
ExpectLocator1: true,
ExpectLocator2: true,
diff --git a/services/keepstore/volume_generic_test.go b/services/keepstore/volume_generic_test.go
index d14d5a4..0218d40 100644
--- a/services/keepstore/volume_generic_test.go
+++ b/services/keepstore/volume_generic_test.go
@@ -57,17 +57,17 @@ func testGet(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- v.PutRaw(TEST_HASH, TEST_BLOCK)
+ v.PutRaw(TestHash, TestBlock)
- buf, err := v.Get(TEST_HASH)
+ buf, err := v.Get(TestHash)
if err != nil {
t.Error(err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK) != 0 {
- t.Errorf("expected %s, got %s", string(TEST_BLOCK), string(buf))
+ if bytes.Compare(buf, TestBlock) != 0 {
+ t.Errorf("expected %s, got %s", string(TestBlock), string(buf))
}
}
@@ -77,8 +77,8 @@ func testGetNoSuchBlock(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- if _, err := v.Get(TEST_HASH_2); err == nil {
- t.Errorf("Expected error while getting non-existing block %v", TEST_HASH_2)
+ if _, err := v.Get(TestHash2); err == nil {
+ t.Errorf("Expected error while getting non-existing block %v", TestHash2)
}
}
@@ -88,10 +88,10 @@ func testCompareSameContent(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- v.PutRaw(TEST_HASH, TEST_BLOCK)
+ v.PutRaw(TestHash, TestBlock)
// Compare the block locator with same content
- err := v.Compare(TEST_HASH, TEST_BLOCK)
+ err := v.Compare(TestHash, TestBlock)
if err != nil {
t.Errorf("Got err %q, expected nil", err)
}
@@ -104,10 +104,10 @@ func testCompareWithDifferentContent(t *testing.T, factory TestableVolumeFactory
v := factory(t)
defer v.Teardown()
- v.PutRaw(TEST_HASH, TEST_BLOCK)
+ v.PutRaw(TestHash, TestBlock)
// Compare the block locator with different content; collision
- err := v.Compare(TEST_HASH, []byte("baddata"))
+ err := v.Compare(TestHash, []byte("baddata"))
if err == nil {
t.Errorf("Expected error due to collision")
}
@@ -121,9 +121,9 @@ func testCompareWithBadData(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- v.PutRaw(TEST_HASH, []byte("baddata"))
+ v.PutRaw(TestHash, []byte("baddata"))
- err := v.Compare(TEST_HASH, TEST_BLOCK)
+ err := v.Compare(TestHash, TestBlock)
if err == nil {
t.Errorf("Expected error due to corruption")
}
@@ -139,14 +139,14 @@ func testPutBlockWithSameContent(t *testing.T, factory TestableVolumeFactory) {
return
}
- err := v.Put(TEST_HASH, TEST_BLOCK)
+ err := v.Put(TestHash, TestBlock)
if err != nil {
- t.Errorf("Got err putting block %q: %q, expected nil", TEST_BLOCK, err)
+ t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
}
- err = v.Put(TEST_HASH, TEST_BLOCK)
+ err = v.Put(TestHash, TestBlock)
if err != nil {
- t.Errorf("Got err putting block second time %q: %q, expected nil", TEST_BLOCK, err)
+ t.Errorf("Got err putting block second time %q: %q, expected nil", TestBlock, err)
}
}
@@ -160,25 +160,25 @@ func testPutBlockWithDifferentContent(t *testing.T, factory TestableVolumeFactor
return
}
- err := v.Put(TEST_HASH, TEST_BLOCK)
+ err := v.Put(TestHash, TestBlock)
if err != nil {
- t.Errorf("Got err putting block %q: %q, expected nil", TEST_BLOCK, err)
+ t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
}
- putErr := v.Put(TEST_HASH, TEST_BLOCK_2)
- buf, getErr := v.Get(TEST_HASH)
+ putErr := v.Put(TestHash, TestBlock2)
+ buf, getErr := v.Get(TestHash)
if putErr == nil {
// Put must not return a nil error unless it has
// overwritten the existing data.
- if bytes.Compare(buf, TEST_BLOCK_2) != 0 {
- t.Errorf("Put succeeded but Get returned %+v, expected %+v", buf, TEST_BLOCK_2)
+ if bytes.Compare(buf, TestBlock2) != 0 {
+ t.Errorf("Put succeeded but Get returned %+v, expected %+v", buf, TestBlock2)
}
} else {
// It is permissible for Put to fail, but it must
// leave us with either the original data, the new
// data, or nothing at all.
- if getErr == nil && bytes.Compare(buf, TEST_BLOCK) != 0 && bytes.Compare(buf, TEST_BLOCK_2) != 0 {
- t.Errorf("Put failed but Get returned %+v, which is neither %+v nor %+v", buf, TEST_BLOCK, TEST_BLOCK_2)
+ if getErr == nil && bytes.Compare(buf, TestBlock) != 0 && bytes.Compare(buf, TestBlock2) != 0 {
+ t.Errorf("Put failed but Get returned %+v, which is neither %+v nor %+v", buf, TestBlock, TestBlock2)
}
}
if getErr == nil {
@@ -196,42 +196,42 @@ func testPutMultipleBlocks(t *testing.T, factory TestableVolumeFactory) {
return
}
- err := v.Put(TEST_HASH, TEST_BLOCK)
+ err := v.Put(TestHash, TestBlock)
if err != nil {
- t.Errorf("Got err putting block %q: %q, expected nil", TEST_BLOCK, err)
+ t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err)
}
- err = v.Put(TEST_HASH_2, TEST_BLOCK_2)
+ err = v.Put(TestHash2, TestBlock2)
if err != nil {
- t.Errorf("Got err putting block %q: %q, expected nil", TEST_BLOCK_2, err)
+ t.Errorf("Got err putting block %q: %q, expected nil", TestBlock2, err)
}
- err = v.Put(TEST_HASH_3, TEST_BLOCK_3)
+ err = v.Put(TestHash3, TestBlock3)
if err != nil {
- t.Errorf("Got err putting block %q: %q, expected nil", TEST_BLOCK_3, err)
+ t.Errorf("Got err putting block %q: %q, expected nil", TestBlock3, err)
}
- data, err := v.Get(TEST_HASH)
+ data, err := v.Get(TestHash)
if err != nil {
t.Error(err)
- } else if bytes.Compare(data, TEST_BLOCK) != 0 {
- t.Errorf("Block present, but content is incorrect: Expected: %v Found: %v", data, TEST_BLOCK)
+ } else if bytes.Compare(data, TestBlock) != 0 {
+ t.Errorf("Block present, but content is incorrect: Expected: %v Found: %v", data, TestBlock)
}
bufs.Put(data)
- data, err = v.Get(TEST_HASH_2)
+ data, err = v.Get(TestHash2)
if err != nil {
t.Error(err)
- } else if bytes.Compare(data, TEST_BLOCK_2) != 0 {
- t.Errorf("Block present, but content is incorrect: Expected: %v Found: %v", data, TEST_BLOCK_2)
+ } else if bytes.Compare(data, TestBlock2) != 0 {
+ t.Errorf("Block present, but content is incorrect: Expected: %v Found: %v", data, TestBlock2)
}
bufs.Put(data)
- data, err = v.Get(TEST_HASH_3)
+ data, err = v.Get(TestHash3)
if err != nil {
t.Error(err)
- } else if bytes.Compare(data, TEST_BLOCK_3) != 0 {
- t.Errorf("Block present, but content is incorrect: Expected: %v Found: %v", data, TEST_BLOCK_3)
+ } else if bytes.Compare(data, TestBlock3) != 0 {
+ t.Errorf("Block present, but content is incorrect: Expected: %v Found: %v", data, TestBlock3)
}
bufs.Put(data)
}
@@ -248,7 +248,7 @@ func testPutAndTouch(t *testing.T, factory TestableVolumeFactory) {
return
}
- if err := v.Put(TEST_HASH, TEST_BLOCK); err != nil {
+ if err := v.Put(TestHash, TestBlock); err != nil {
t.Error(err)
}
@@ -260,20 +260,20 @@ func testPutAndTouch(t *testing.T, factory TestableVolumeFactory) {
// Set the stored block's mtime far enough in the past that we
// can see the difference between "timestamp didn't change"
// and "timestamp granularity is too low".
- v.TouchWithDate(TEST_HASH, time.Now().Add(-20*time.Second))
+ v.TouchWithDate(TestHash, time.Now().Add(-20*time.Second))
// Make sure v.Mtime() agrees the above Utime really worked.
- if t0, err := v.Mtime(TEST_HASH); err != nil || t0.IsZero() || !t0.Before(threshold) {
+ if t0, err := v.Mtime(TestHash); err != nil || t0.IsZero() || !t0.Before(threshold) {
t.Errorf("Setting mtime failed: %v, %v", t0, err)
}
// Write the same block again.
- if err := v.Put(TEST_HASH, TEST_BLOCK); err != nil {
+ if err := v.Put(TestHash, TestBlock); err != nil {
t.Error(err)
}
// Verify threshold < t1
- if t1, err := v.Mtime(TEST_HASH); err != nil {
+ if t1, err := v.Mtime(TestHash); err != nil {
t.Error(err)
} else if t1.Before(threshold) {
t.Errorf("t1 %v should be >= threshold %v after v.Put ", t1, threshold)
@@ -286,7 +286,7 @@ func testTouchNoSuchBlock(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- if err := v.Touch(TEST_HASH); err == nil {
+ if err := v.Touch(TestHash); err == nil {
t.Error("Expected error when attempted to touch a non-existing block")
}
}
@@ -311,9 +311,9 @@ func testIndexTo(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- v.PutRaw(TEST_HASH, TEST_BLOCK)
- v.PutRaw(TEST_HASH_2, TEST_BLOCK_2)
- v.PutRaw(TEST_HASH_3, TEST_BLOCK_3)
+ v.PutRaw(TestHash, TestBlock)
+ v.PutRaw(TestHash2, TestBlock2)
+ v.PutRaw(TestHash3, TestBlock3)
buf := new(bytes.Buffer)
v.IndexTo("", buf)
@@ -321,9 +321,9 @@ func testIndexTo(t *testing.T, factory TestableVolumeFactory) {
sort.Strings(indexRows)
sortedIndex := strings.Join(indexRows, "\n")
m, err := regexp.MatchString(
- `^\n`+TEST_HASH+`\+\d+ \d+\n`+
- TEST_HASH_3+`\+\d+ \d+\n`+
- TEST_HASH_2+`\+\d+ \d+$`,
+ `^\n`+TestHash+`\+\d+ \d+\n`+
+ TestHash3+`\+\d+ \d+\n`+
+ TestHash2+`\+\d+ \d+$`,
sortedIndex)
if err != nil {
t.Error(err)
@@ -335,7 +335,7 @@ func testIndexTo(t *testing.T, factory TestableVolumeFactory) {
buf = new(bytes.Buffer)
v.IndexTo(prefix, buf)
- m, err := regexp.MatchString(`^`+TEST_HASH_2+`\+\d+ \d+\n$`, string(buf.Bytes()))
+ m, err := regexp.MatchString(`^`+TestHash2+`\+\d+ \d+\n$`, string(buf.Bytes()))
if err != nil {
t.Error(err)
} else if !m {
@@ -365,16 +365,16 @@ func testDeleteNewBlock(t *testing.T, factory TestableVolumeFactory) {
return
}
- v.Put(TEST_HASH, TEST_BLOCK)
+ v.Put(TestHash, TestBlock)
- if err := v.Delete(TEST_HASH); err != nil {
+ if err := v.Delete(TestHash); err != nil {
t.Error(err)
}
- data, err := v.Get(TEST_HASH)
+ data, err := v.Get(TestHash)
if err != nil {
t.Error(err)
- } else if bytes.Compare(data, TEST_BLOCK) != 0 {
- t.Error("Block still present, but content is incorrect: %+v != %+v", data, TEST_BLOCK)
+ } else if bytes.Compare(data, TestBlock) != 0 {
+ t.Error("Block still present, but content is incorrect: %+v != %+v", data, TestBlock)
}
bufs.Put(data)
}
@@ -390,13 +390,13 @@ func testDeleteOldBlock(t *testing.T, factory TestableVolumeFactory) {
return
}
- v.Put(TEST_HASH, TEST_BLOCK)
- v.TouchWithDate(TEST_HASH, time.Now().Add(-2*blob_signature_ttl*time.Second))
+ v.Put(TestHash, TestBlock)
+ v.TouchWithDate(TestHash, time.Now().Add(-2*blob_signature_ttl*time.Second))
- if err := v.Delete(TEST_HASH); err != nil {
+ if err := v.Delete(TestHash); err != nil {
t.Error(err)
}
- if _, err := v.Get(TEST_HASH); err == nil || !os.IsNotExist(err) {
+ if _, err := v.Get(TestHash); err == nil || !os.IsNotExist(err) {
t.Errorf("os.IsNotExist(%v) should have been true", err.Error())
}
}
@@ -407,7 +407,7 @@ func testDeleteNoSuchBlock(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- if err := v.Delete(TEST_HASH_2); err == nil {
+ if err := v.Delete(TestHash2); err == nil {
t.Errorf("Expected error when attempting to delete a non-existing block")
}
}
@@ -454,38 +454,38 @@ func testUpdateReadOnly(t *testing.T, factory TestableVolumeFactory) {
return
}
- v.PutRaw(TEST_HASH, TEST_BLOCK)
+ v.PutRaw(TestHash, TestBlock)
// Get from read-only volume should succeed
- _, err := v.Get(TEST_HASH)
+ _, err := v.Get(TestHash)
if err != nil {
t.Errorf("got err %v, expected nil", err)
}
// Put a new block to read-only volume should result in error
- err = v.Put(TEST_HASH_2, TEST_BLOCK_2)
+ err = v.Put(TestHash2, TestBlock2)
if err == nil {
t.Errorf("Expected error when putting block in a read-only volume")
}
- _, err = v.Get(TEST_HASH_2)
+ _, err = v.Get(TestHash2)
if err == nil {
t.Errorf("Expected error when getting block whose put in read-only volume failed")
}
// Touch a block in read-only volume should result in error
- err = v.Touch(TEST_HASH)
+ err = v.Touch(TestHash)
if err == nil {
t.Errorf("Expected error when touching block in a read-only volume")
}
// Delete a block from a read-only volume should result in error
- err = v.Delete(TEST_HASH)
+ err = v.Delete(TestHash)
if err == nil {
t.Errorf("Expected error when deleting block from a read-only volume")
}
// Overwriting an existing block in read-only volume should result in error
- err = v.Put(TEST_HASH, TEST_BLOCK)
+ err = v.Put(TestHash, TestBlock)
if err == nil {
t.Errorf("Expected error when putting block in a read-only volume")
}
@@ -497,43 +497,43 @@ func testGetConcurrent(t *testing.T, factory TestableVolumeFactory) {
v := factory(t)
defer v.Teardown()
- v.PutRaw(TEST_HASH, TEST_BLOCK)
- v.PutRaw(TEST_HASH_2, TEST_BLOCK_2)
- v.PutRaw(TEST_HASH_3, TEST_BLOCK_3)
+ v.PutRaw(TestHash, TestBlock)
+ v.PutRaw(TestHash2, TestBlock2)
+ v.PutRaw(TestHash3, TestBlock3)
sem := make(chan int)
go func(sem chan int) {
- buf, err := v.Get(TEST_HASH)
+ buf, err := v.Get(TestHash)
if err != nil {
t.Errorf("err1: %v", err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK) != 0 {
- t.Errorf("buf should be %s, is %s", string(TEST_BLOCK), string(buf))
+ if bytes.Compare(buf, TestBlock) != 0 {
+ t.Errorf("buf should be %s, is %s", string(TestBlock), string(buf))
}
sem <- 1
}(sem)
go func(sem chan int) {
- buf, err := v.Get(TEST_HASH_2)
+ buf, err := v.Get(TestHash2)
if err != nil {
t.Errorf("err2: %v", err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK_2) != 0 {
- t.Errorf("buf should be %s, is %s", string(TEST_BLOCK_2), string(buf))
+ if bytes.Compare(buf, TestBlock2) != 0 {
+ t.Errorf("buf should be %s, is %s", string(TestBlock2), string(buf))
}
sem <- 1
}(sem)
go func(sem chan int) {
- buf, err := v.Get(TEST_HASH_3)
+ buf, err := v.Get(TestHash3)
if err != nil {
t.Errorf("err3: %v", err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK_3) != 0 {
- t.Errorf("buf should be %s, is %s", string(TEST_BLOCK_3), string(buf))
+ if bytes.Compare(buf, TestBlock3) != 0 {
+ t.Errorf("buf should be %s, is %s", string(TestBlock3), string(buf))
}
sem <- 1
}(sem)
@@ -556,7 +556,7 @@ func testPutConcurrent(t *testing.T, factory TestableVolumeFactory) {
sem := make(chan int)
go func(sem chan int) {
- err := v.Put(TEST_HASH, TEST_BLOCK)
+ err := v.Put(TestHash, TestBlock)
if err != nil {
t.Errorf("err1: %v", err)
}
@@ -564,7 +564,7 @@ func testPutConcurrent(t *testing.T, factory TestableVolumeFactory) {
}(sem)
go func(sem chan int) {
- err := v.Put(TEST_HASH_2, TEST_BLOCK_2)
+ err := v.Put(TestHash2, TestBlock2)
if err != nil {
t.Errorf("err2: %v", err)
}
@@ -572,7 +572,7 @@ func testPutConcurrent(t *testing.T, factory TestableVolumeFactory) {
}(sem)
go func(sem chan int) {
- err := v.Put(TEST_HASH_3, TEST_BLOCK_3)
+ err := v.Put(TestHash3, TestBlock3)
if err != nil {
t.Errorf("err3: %v", err)
}
@@ -585,30 +585,30 @@ func testPutConcurrent(t *testing.T, factory TestableVolumeFactory) {
}
// Double check that we actually wrote the blocks we expected to write.
- buf, err := v.Get(TEST_HASH)
+ buf, err := v.Get(TestHash)
if err != nil {
t.Errorf("Get #1: %v", err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK) != 0 {
- t.Errorf("Get #1: expected %s, got %s", string(TEST_BLOCK), string(buf))
+ if bytes.Compare(buf, TestBlock) != 0 {
+ t.Errorf("Get #1: expected %s, got %s", string(TestBlock), string(buf))
}
- buf, err = v.Get(TEST_HASH_2)
+ buf, err = v.Get(TestHash2)
if err != nil {
t.Errorf("Get #2: %v", err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK_2) != 0 {
- t.Errorf("Get #2: expected %s, got %s", string(TEST_BLOCK_2), string(buf))
+ if bytes.Compare(buf, TestBlock2) != 0 {
+ t.Errorf("Get #2: expected %s, got %s", string(TestBlock2), string(buf))
}
- buf, err = v.Get(TEST_HASH_3)
+ buf, err = v.Get(TestHash3)
if err != nil {
t.Errorf("Get #3: %v", err)
}
bufs.Put(buf)
- if bytes.Compare(buf, TEST_BLOCK_3) != 0 {
- t.Errorf("Get #3: expected %s, got %s", string(TEST_BLOCK_3), string(buf))
+ if bytes.Compare(buf, TestBlock3) != 0 {
+ t.Errorf("Get #3: expected %s, got %s", string(TestBlock3), string(buf))
}
}
diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go
index d6b1c80..4f1e84c 100644
--- a/services/keepstore/volume_unix_test.go
+++ b/services/keepstore/volume_unix_test.go
@@ -88,9 +88,9 @@ func TestUnixVolumeWithGenericTestsSerialized(t *testing.T) {
func TestGetNotFound(t *testing.T) {
v := NewTestableUnixVolume(t, false, false)
defer v.Teardown()
- v.Put(TEST_HASH, TEST_BLOCK)
+ v.Put(TestHash, TestBlock)
- buf, err := v.Get(TEST_HASH_2)
+ buf, err := v.Get(TestHash2)
switch {
case os.IsNotExist(err):
break
@@ -105,16 +105,16 @@ func TestPut(t *testing.T) {
v := NewTestableUnixVolume(t, false, false)
defer v.Teardown()
- err := v.Put(TEST_HASH, TEST_BLOCK)
+ err := v.Put(TestHash, TestBlock)
if err != nil {
t.Error(err)
}
- p := fmt.Sprintf("%s/%s/%s", v.root, TEST_HASH[:3], TEST_HASH)
+ p := fmt.Sprintf("%s/%s/%s", v.root, TestHash[:3], TestHash)
if buf, err := ioutil.ReadFile(p); err != nil {
t.Error(err)
- } else if bytes.Compare(buf, TEST_BLOCK) != 0 {
+ } else if bytes.Compare(buf, TestBlock) != 0 {
t.Errorf("Write should have stored %s, did store %s",
- string(TEST_BLOCK), string(buf))
+ string(TestBlock), string(buf))
}
}
@@ -123,7 +123,7 @@ func TestPutBadVolume(t *testing.T) {
defer v.Teardown()
os.Chmod(v.root, 000)
- err := v.Put(TEST_HASH, TEST_BLOCK)
+ err := v.Put(TestHash, TestBlock)
if err == nil {
t.Error("Write should have failed")
}
@@ -133,24 +133,24 @@ func TestUnixVolumeReadonly(t *testing.T) {
v := NewTestableUnixVolume(t, false, true)
defer v.Teardown()
- v.PutRaw(TEST_HASH, TEST_BLOCK)
+ v.PutRaw(TestHash, TestBlock)
- _, err := v.Get(TEST_HASH)
+ _, err := v.Get(TestHash)
if err != nil {
t.Errorf("got err %v, expected nil", err)
}
- err = v.Put(TEST_HASH, TEST_BLOCK)
+ err = v.Put(TestHash, TestBlock)
if err != MethodDisabledError {
t.Errorf("got err %v, expected MethodDisabledError", err)
}
- err = v.Touch(TEST_HASH)
+ err = v.Touch(TestHash)
if err != MethodDisabledError {
t.Errorf("got err %v, expected MethodDisabledError", err)
}
- err = v.Delete(TEST_HASH)
+ err = v.Delete(TestHash)
if err != MethodDisabledError {
t.Errorf("got err %v, expected MethodDisabledError", err)
}
@@ -200,9 +200,9 @@ func TestUnixVolumeGetFuncWorkerError(t *testing.T) {
v := NewTestableUnixVolume(t, false, false)
defer v.Teardown()
- v.Put(TEST_HASH, TEST_BLOCK)
+ v.Put(TestHash, TestBlock)
mockErr := errors.New("Mock error")
- err := v.getFunc(v.blockPath(TEST_HASH), func(rdr io.Reader) error {
+ err := v.getFunc(v.blockPath(TestHash), func(rdr io.Reader) error {
return mockErr
})
if err != mockErr {
@@ -215,7 +215,7 @@ func TestUnixVolumeGetFuncFileError(t *testing.T) {
defer v.Teardown()
funcCalled := false
- err := v.getFunc(v.blockPath(TEST_HASH), func(rdr io.Reader) error {
+ err := v.getFunc(v.blockPath(TestHash), func(rdr io.Reader) error {
funcCalled = true
return nil
})
@@ -231,13 +231,13 @@ func TestUnixVolumeGetFuncWorkerWaitsOnMutex(t *testing.T) {
v := NewTestableUnixVolume(t, false, false)
defer v.Teardown()
- v.Put(TEST_HASH, TEST_BLOCK)
+ v.Put(TestHash, TestBlock)
mtx := NewMockMutex()
v.locker = mtx
funcCalled := make(chan struct{})
- go v.getFunc(v.blockPath(TEST_HASH), func(rdr io.Reader) error {
+ go v.getFunc(v.blockPath(TestHash), func(rdr io.Reader) error {
funcCalled <- struct{}{}
return nil
})
@@ -266,26 +266,26 @@ func TestUnixVolumeCompare(t *testing.T) {
v := NewTestableUnixVolume(t, false, false)
defer v.Teardown()
- v.Put(TEST_HASH, TEST_BLOCK)
- err := v.Compare(TEST_HASH, TEST_BLOCK)
+ v.Put(TestHash, TestBlock)
+ err := v.Compare(TestHash, TestBlock)
if err != nil {
t.Errorf("Got err %q, expected nil", err)
}
- err = v.Compare(TEST_HASH, []byte("baddata"))
+ err = v.Compare(TestHash, []byte("baddata"))
if err != CollisionError {
t.Errorf("Got err %q, expected %q", err, CollisionError)
}
- v.Put(TEST_HASH, []byte("baddata"))
- err = v.Compare(TEST_HASH, TEST_BLOCK)
+ v.Put(TestHash, []byte("baddata"))
+ err = v.Compare(TestHash, TestBlock)
if err != DiskHashError {
t.Errorf("Got err %q, expected %q", err, DiskHashError)
}
- p := fmt.Sprintf("%s/%s/%s", v.root, TEST_HASH[:3], TEST_HASH)
+ p := fmt.Sprintf("%s/%s/%s", v.root, TestHash[:3], TestHash)
os.Chmod(p, 000)
- err = v.Compare(TEST_HASH, TEST_BLOCK)
+ err = v.Compare(TestHash, TestBlock)
if err == nil || strings.Index(err.Error(), "permission denied") < 0 {
t.Errorf("Got err %q, expected %q", err, "permission denied")
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list