From 386ad357b714ad6c3de9c163b67e4f86f8ee9203 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 18 Mar 2011 21:17:26 -0700 Subject: [PATCH] camli/testing path cleanup. Break lib/go/testing into lib/go/camli/test and lib/go/camli/test/asserts Moves TestBlob stuff and package 'testing' flags out of everybody's command flags. Also moves towards making the project filesystem match the import paths. --- build.pl | 20 ++++++++----- lib/go/blobref/Makefile | 1 - lib/go/blobref/blobref_test.go | 2 +- lib/go/blobserver/blobhub_test.go | 2 +- lib/go/blobserver/handlers/enumerate_test.go | 2 +- lib/go/blobserver/localdisk/enumerate_test.go | 2 +- lib/go/blobserver/localdisk/localdisk_test.go | 2 +- lib/go/{testing => camli/test}/Makefile | 4 +-- lib/go/camli/test/asserts/Makefile | 7 +++++ .../test/asserts/asserts.go} | 2 +- .../testblob.go => camli/test/blob.go} | 30 ++++++++++--------- lib/go/jsonsign/jsonsign_test.go | 17 ++++++----- lib/go/schema/schema_test.go | 2 +- 13 files changed, 53 insertions(+), 40 deletions(-) rename lib/go/{testing => camli/test}/Makefile (69%) create mode 100644 lib/go/camli/test/asserts/Makefile rename lib/go/{testing/testing.go => camli/test/asserts/asserts.go} (99%) rename lib/go/{blobref/testblob.go => camli/test/blob.go} (61%) diff --git a/build.pl b/build.pl index c8f1f77b3..aa2204d06 100755 --- a/build.pl +++ b/build.pl @@ -284,23 +284,27 @@ TARGET: clients/go/camsync TARGET: lib/go/schema - lib/go/blobref - - lib/go/testing + - lib/go/camli/test/asserts -TARGET: lib/go/testing +TARGET: lib/go/camli/test/asserts + - lib/go/blobref TARGET: lib/go/client - lib/go/blobref TARGET: lib/go/jsonsign - lib/go/blobref - - lib/go/testing + - lib/go/camli/test/asserts + - lib/go/camli/test + +TARGET: lib/go/camli/test TARGET: lib/go/blobref - - lib/go/testing + - lib/go/camli/test/asserts TARGET: lib/go/blobserver - lib/go/blobref - - lib/go/testing + - lib/go/camli/test/asserts TARGET: lib/go/search - lib/go/blobref @@ -311,12 +315,12 @@ TARGET: lib/go/blobserver/handlers - server/go/httputil - lib/go/blobserver - lib/go/httprange - - lib/go/testing + - lib/go/camli/test/asserts TARGET: lib/go/blobserver/localdisk - lib/go/blobref - lib/go/blobserver - - lib/go/testing + - lib/go/camli/test/asserts TARGET: lib/go/httprange @@ -328,5 +332,5 @@ TARGET: lib/go/mysqlindexer - lib/go/blobref - lib/go/blobserver - lib/go/schema - - lib/go/testing + - lib/go/camli/test/asserts - lib/go/search diff --git a/lib/go/blobref/Makefile b/lib/go/blobref/Makefile index 35324e547..71fc93b5d 100644 --- a/lib/go/blobref/Makefile +++ b/lib/go/blobref/Makefile @@ -4,6 +4,5 @@ TARG=camli/blobref GOFILES=\ blobref.go\ fetcher.go\ - testblob.go\ include $(GOROOT)/src/Make.pkg diff --git a/lib/go/blobref/blobref_test.go b/lib/go/blobref/blobref_test.go index f4acbc434..af7564ccc 100644 --- a/lib/go/blobref/blobref_test.go +++ b/lib/go/blobref/blobref_test.go @@ -18,7 +18,7 @@ package blobref import ( "testing" - . "camli/testing" + . "camli/test/asserts" ) func TestAll(t *testing.T) { diff --git a/lib/go/blobserver/blobhub_test.go b/lib/go/blobserver/blobhub_test.go index 20f5a70fb..89866b661 100644 --- a/lib/go/blobserver/blobhub_test.go +++ b/lib/go/blobserver/blobhub_test.go @@ -18,7 +18,7 @@ package blobserver import ( "camli/blobref" - . "camli/testing" + . "camli/test/asserts" "testing" "time" ) diff --git a/lib/go/blobserver/handlers/enumerate_test.go b/lib/go/blobserver/handlers/enumerate_test.go index f8e55a968..17b054ae1 100644 --- a/lib/go/blobserver/handlers/enumerate_test.go +++ b/lib/go/blobserver/handlers/enumerate_test.go @@ -19,7 +19,7 @@ package handlers import ( "camli/blobref" "camli/blobserver" - . "camli/testing" + . "camli/test/asserts" "http" "http/httptest" "os" diff --git a/lib/go/blobserver/localdisk/enumerate_test.go b/lib/go/blobserver/localdisk/enumerate_test.go index fa371b873..ddd14b1e3 100644 --- a/lib/go/blobserver/localdisk/enumerate_test.go +++ b/lib/go/blobserver/localdisk/enumerate_test.go @@ -19,7 +19,7 @@ package localdisk import ( "camli/blobref" "camli/blobserver" - . "camli/testing" + . "camli/test/asserts" "fmt" "io/ioutil" diff --git a/lib/go/blobserver/localdisk/localdisk_test.go b/lib/go/blobserver/localdisk/localdisk_test.go index 6a3d30eaf..1aec87492 100644 --- a/lib/go/blobserver/localdisk/localdisk_test.go +++ b/lib/go/blobserver/localdisk/localdisk_test.go @@ -19,7 +19,7 @@ package localdisk import ( "camli/blobref" "camli/blobserver" - . "camli/testing" + . "camli/test/asserts" "crypto/sha1" "fmt" "io" diff --git a/lib/go/testing/Makefile b/lib/go/camli/test/Makefile similarity index 69% rename from lib/go/testing/Makefile rename to lib/go/camli/test/Makefile index 5cbc003a7..8b8d7b28e 100644 --- a/lib/go/testing/Makefile +++ b/lib/go/camli/test/Makefile @@ -1,7 +1,7 @@ include $(GOROOT)/src/Make.inc -TARG=camli/testing +TARG=camli/test GOFILES=\ - testing.go\ + blob.go\ include $(GOROOT)/src/Make.pkg diff --git a/lib/go/camli/test/asserts/Makefile b/lib/go/camli/test/asserts/Makefile new file mode 100644 index 000000000..8489bd249 --- /dev/null +++ b/lib/go/camli/test/asserts/Makefile @@ -0,0 +1,7 @@ +include $(GOROOT)/src/Make.inc + +TARG=camli/test/asserts +GOFILES=\ + asserts.go\ + +include $(GOROOT)/src/Make.pkg diff --git a/lib/go/testing/testing.go b/lib/go/camli/test/asserts/asserts.go similarity index 99% rename from lib/go/testing/testing.go rename to lib/go/camli/test/asserts/asserts.go index 6d85321d1..9a74f3ed4 100644 --- a/lib/go/testing/testing.go +++ b/lib/go/camli/test/asserts/asserts.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package testing +package asserts import ( "os" diff --git a/lib/go/blobref/testblob.go b/lib/go/camli/test/blob.go similarity index 61% rename from lib/go/blobref/testblob.go rename to lib/go/camli/test/blob.go index df2cef115..0ca32ebbd 100644 --- a/lib/go/blobref/testblob.go +++ b/lib/go/camli/test/blob.go @@ -14,39 +14,41 @@ See the License for the specific language governing permissions and limitations under the License. */ -package blobref +package test import ( + "camli/blobref" + "crypto/sha1" "io" "strings" "testing" ) -// TestBlob is a utility class for unit tests. -type TestBlob struct { - Val string +// Blob is a utility class for unit tests. +type Blob struct { + Contents string // the contents of the blob } -func (tb *TestBlob) BlobRef() *BlobRef { +func (tb *Blob) BlobRef() *blobref.BlobRef { h := sha1.New() - h.Write([]byte(tb.Val)) - return FromHash("sha1", h) + h.Write([]byte(tb.Contents)) + return blobref.FromHash("sha1", h) } -func (tb *TestBlob) BlobRefSlice() []*BlobRef { - return []*BlobRef{tb.BlobRef()} +func (tb *Blob) BlobRefSlice() []*blobref.BlobRef { + return []*blobref.BlobRef{tb.BlobRef()} } -func (tb *TestBlob) Size() int64 { - return int64(len(tb.Val)) +func (tb *Blob) Size() int64 { + return int64(len(tb.Contents)) } -func (tb *TestBlob) Reader() io.Reader { - return strings.NewReader(tb.Val) +func (tb *Blob) Reader() io.Reader { + return strings.NewReader(tb.Contents) } -func (tb *TestBlob) AssertMatches(t *testing.T, sb *SizedBlobRef) { +func (tb *Blob) AssertMatches(t *testing.T, sb *blobref.SizedBlobRef) { if sb.Size != tb.Size() { t.Fatalf("Got size %d; expected %d", sb.Size, tb.Size()) } diff --git a/lib/go/jsonsign/jsonsign_test.go b/lib/go/jsonsign/jsonsign_test.go index 9f3d3402d..62f01de36 100644 --- a/lib/go/jsonsign/jsonsign_test.go +++ b/lib/go/jsonsign/jsonsign_test.go @@ -18,7 +18,8 @@ package jsonsign import ( "camli/blobref" - . "camli/testing" + "camli/test" + . "camli/test/asserts" "fmt" "os" @@ -94,8 +95,8 @@ jyVNPb8AaaWVW1uZLg6Em61aKnbOG10B30m3CQ8dwBjF9hgmtcY0IZ/Y -----END PGP PUBLIC KEY BLOCK----- ` -var pubKeyBlob1 = &blobref.TestBlob{pubKey1} // user 1 -var pubKeyBlob2 = &blobref.TestBlob{pubKey2} // user 2 +var pubKeyBlob1 = &test.Blob{pubKey1} // user 1 +var pubKeyBlob2 = &test.Blob{pubKey2} // user 2 var testFetcher = &TestFetcher{} @@ -170,14 +171,14 @@ func TestSigning(t *testing.T) { type TestFetcher struct { l sync.Mutex - m map[string]*blobref.TestBlob + m map[string]*test.Blob } -func (tf *TestFetcher) AddBlob(b *blobref.TestBlob) { +func (tf *TestFetcher) AddBlob(b *test.Blob) { tf.l.Lock() defer tf.l.Unlock() if tf.m == nil { - tf.m = make(map[string]*blobref.TestBlob) + tf.m = make(map[string]*test.Blob) } tf.m[b.BlobRef().String()] = b } @@ -194,8 +195,8 @@ func (tf *TestFetcher) Fetch(ref *blobref.BlobRef) (file blobref.ReadSeekCloser, err = os.ENOENT return } - file = &strReader{tb.Val, 0} - size = int64(len(tb.Val)) + file = &strReader{tb.Contents, 0} + size = int64(len(tb.Contents)) return } diff --git a/lib/go/schema/schema_test.go b/lib/go/schema/schema_test.go index 5079ffae0..4623064df 100644 --- a/lib/go/schema/schema_test.go +++ b/lib/go/schema/schema_test.go @@ -17,7 +17,7 @@ limitations under the License. package schema import ( - . "camli/testing" + . "camli/test/asserts" "os" "strings" "testing"