move FakeIndex from camli/search's private tests to camli/test so others can use it

Change-Id: I927add0bd645d92d6c36133ff8df5fa0fe33f770
This commit is contained in:
Brad Fitzpatrick 2011-07-06 11:20:25 -07:00
parent 05258e6e17
commit 443cfd5268
3 changed files with 31 additions and 27 deletions

View File

@ -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")

View File

@ -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))
}

View File

@ -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 // "<permanode>/<owner>" -> ClaimList
ownerClaims map[string]search.ClaimList // "<permanode>/<owner>" -> 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")
}