diff --git a/lib/go/camli/search/handler.go b/lib/go/camli/search/handler.go index f5bb6cf2d..a70491e69 100644 --- a/lib/go/camli/search/handler.go +++ b/lib/go/camli/search/handler.go @@ -45,6 +45,10 @@ type Handler struct { owner *blobref.BlobRef } +func NewHandler(index Index, owner *blobref.BlobRef) *Handler { + return &Handler{index, owner} +} + func newHandlerFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handler, os.Error) { indexPrefix := conf.RequiredString("index") // TODO: add optional help tips here? ownerBlobStr := conf.RequiredString("owner") diff --git a/lib/go/camli/search/handler_test.go b/lib/go/camli/search/handler_test.go index 7f8d1f4a1..f4c086367 100644 --- a/lib/go/camli/search/handler_test.go +++ b/lib/go/camli/search/handler_test.go @@ -14,18 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -package search +package search_test import ( + . "camli/search" + "bytes" "json" "testing" "camli/blobref" + "camli/test" ) type describeTest struct { - setup func(fi *FakeIndex) + setup func(fi *test.FakeIndex) blob string // blobref to describe depth int @@ -37,14 +40,14 @@ var owner = blobref.MustParse("abcown-123") var describeTests = []describeTest{ { - func(fi *FakeIndex) {}, + func(fi *test.FakeIndex) {}, "abc-555", 1, map[string]interface{}{}, }, { - func(fi *FakeIndex) { + func(fi *test.FakeIndex) { fi.AddMeta(blobref.MustParse("abc-555"), "image/jpeg", 999) }, "abc-555", @@ -59,7 +62,7 @@ var describeTests = []describeTest{ }, { - func(fi *FakeIndex) { + func(fi *test.FakeIndex) { pn := blobref.MustParse("perma-123") fi.AddMeta(pn, "application/json; camliType=permanode", 123) fi.AddClaim(owner, pn, "set-attribute", "camliContent", "foo-232") @@ -101,17 +104,17 @@ var describeTests = []describeTest{ } func TestDescribe(t *testing.T) { - for testn, test := range describeTests { - idx := NewFakeIndex() - test.setup(idx) + for testn, tt := range describeTests { + idx := test.NewFakeIndex() + tt.setup(idx) - h := &Handler{index: idx, owner: owner} + h := NewHandler(idx, owner) js := make(map[string]interface{}) dr := h.NewDescribeRequest() - dr.Describe(blobref.MustParse(test.blob), test.depth) + dr.Describe(blobref.MustParse(tt.blob), tt.depth) dr.PopulateJSON(js) got, _ := json.MarshalIndent(js, "", " ") - want, _ := json.MarshalIndent(test.expect, "", " ") + want, _ := json.MarshalIndent(tt.expect, "", " ") if !bytes.Equal(got, want) { t.Errorf("test %d:\nwant: %s\n got: %s", testn, string(want), string(got)) } diff --git a/lib/go/camli/search/fakeindex_test.go b/lib/go/camli/test/fakeindex.go similarity index 80% rename from lib/go/camli/search/fakeindex_test.go rename to lib/go/camli/test/fakeindex.go index 3888f8a78..a741f4ed2 100644 --- a/lib/go/camli/search/fakeindex_test.go +++ b/lib/go/camli/test/fakeindex.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package search +package test import ( "os" @@ -22,25 +22,26 @@ import ( "time" "camli/blobref" + "camli/search" ) type FakeIndex struct { lk sync.Mutex mimeType map[string]string // blobref -> type size map[string]int64 - ownerClaims map[string]ClaimList // "/" -> ClaimList + ownerClaims map[string]search.ClaimList // "/" -> ClaimList cllk sync.Mutex clock int64 } -var _ Index = (*FakeIndex)(nil) +var _ search.Index = (*FakeIndex)(nil) func NewFakeIndex() *FakeIndex { return &FakeIndex{ mimeType: make(map[string]string), size: make(map[string]int64), - ownerClaims: make(map[string]ClaimList), + ownerClaims: make(map[string]search.ClaimList), } } @@ -68,7 +69,7 @@ func (fi *FakeIndex) AddClaim(owner, permanode *blobref.BlobRef, claimType, attr defer fi.lk.Unlock() date := fi.nextDate() - claim := &Claim{ + claim := &search.Claim{ Permanode: permanode, Signer: nil, BlobRef: nil, @@ -85,19 +86,15 @@ func (fi *FakeIndex) AddClaim(owner, permanode *blobref.BlobRef, claimType, attr // Interface implementation // -func (fi *FakeIndex) GetRecentPermanodes(dest chan *Result, -owner []*blobref.BlobRef, -limit int) os.Error { +func (fi *FakeIndex) GetRecentPermanodes(dest chan *search.Result, owner []*blobref.BlobRef, limit int) os.Error { panic("NOIMPL") } -func (fi *FakeIndex) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, -signer *blobref.BlobRef, -tag string, limit int) os.Error { +func (fi *FakeIndex) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, signer *blobref.BlobRef, tag string, limit int) os.Error { panic("NOIMPL") } -func (fi *FakeIndex) GetOwnerClaims(permaNode, owner *blobref.BlobRef) (ClaimList, os.Error) { +func (fi *FakeIndex) GetOwnerClaims(permaNode, owner *blobref.BlobRef) (search.ClaimList, os.Error) { fi.lk.Lock() defer fi.lk.Unlock() return fi.ownerClaims[permaNode.String()+"/"+owner.String()], nil @@ -118,7 +115,7 @@ func (fi *FakeIndex) ExistingFileSchemas(bytesRef *blobref.BlobRef) ([]*blobref. panic("NOIMPL") } -func (fi *FakeIndex) GetFileInfo(fileRef *blobref.BlobRef) (*FileInfo, os.Error) { +func (fi *FakeIndex) GetFileInfo(fileRef *blobref.BlobRef) (*search.FileInfo, os.Error) { panic("NOIMPL") } @@ -126,14 +123,14 @@ func (fi *FakeIndex) PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, v panic("NOIMPL") } -func (fi *FakeIndex) PathsOfSignerTarget(signer, target *blobref.BlobRef) ([]*Path, os.Error) { +func (fi *FakeIndex) PathsOfSignerTarget(signer, target *blobref.BlobRef) ([]*search.Path, os.Error) { panic("NOIMPL") } -func (fi *FakeIndex) PathsLookup(signer, base *blobref.BlobRef, suffix string) ([]*Path, os.Error) { +func (fi *FakeIndex) PathsLookup(signer, base *blobref.BlobRef, suffix string) ([]*search.Path, os.Error) { panic("NOIMPL") } -func (fi *FakeIndex) PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*Path, os.Error) { +func (fi *FakeIndex) PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*search.Path, os.Error) { panic("NOIMPL") }