Пример #1
0
func Site(s string) (catalog.Site, error) {
	if strings.HasPrefix(s, ".") || strings.HasPrefix(s, "/") {
		return file.NewSite(s)
	}
	if strings.HasPrefix(s, "dir:") {
		return file.NewSite(s[4:])
	}
	if strings.HasPrefix(s, "mock:") {
		return mock.NewSite(s)
	}
	return couchbase.NewSite(s)
}
Пример #2
0
func TestFetch(t *testing.T) {

	mocksite, err := mock.NewSite("mock:items=10")
	if err != nil {
		t.Errorf("Error creating mock site")
	}
	pool, err := mocksite.PoolByName("p0")
	if err != nil {
		t.Errorf("Error accessing pool p0")
	}
	bucket, err := pool.BucketByName("b0")
	if err != nil {
		t.Errorf("Error accessing bucket b0")
	}
	index, err := bucket.IndexByName("all_docs")
	if err != nil {
		t.Errorf("Error accessing scanner all_docs")
	}

	scanIndex := index.(catalog.ScanIndex)
	scan := NewScan(bucket, scanIndex, nil, "")
	fetch := NewFetch(bucket, nil, "bucket")
	fetch.SetSource(scan)

	fetchItemChannel, _ := fetch.GetChannels()

	stopChannel := make(misc.StopChannel)
	go fetch.Run(stopChannel)

	count := 0
	for item := range fetchItemChannel {
		bucketValue, err := item.Path("bucket")
		if err != nil {
			t.Errorf("Expected item to contain value at path bucket")
		}
		iValue, err := bucketValue.Path("i")
		if err != nil {
			t.Errorf("Expected item to contain value at path i")
		}
		i := iValue.Value()
		_, ok := i.(float64)
		if !ok {
			t.Errorf("Expected i to be a number")
		}
		count++
	}

	if count != 10 {
		t.Errorf("Expected %d items, got %d", 10, count)
	}

}
Пример #3
0
func TestScan(t *testing.T) {

	mocksite, err := mock.NewSite("mock:items=10")
	if err != nil {
		t.Errorf("Error creating mock site")
	}
	pool, err := mocksite.PoolByName("p0")
	if err != nil {
		t.Errorf("Error accessing pool p0")
	}
	bucket, err := pool.BucketByName("b0")
	if err != nil {
		t.Errorf("Error accessing bucket b0")
	}
	index, err := bucket.IndexByName("all_docs")
	if err != nil {
		t.Errorf("Error accessing scanner all_docs")
	}

	scanIndex := index.(catalog.ScanIndex)
	scan := NewScan(bucket, scanIndex, nil, "")

	scanItemChannel, _ := scan.GetChannels()

	stopChannel := make(misc.StopChannel)
	go scan.Run(stopChannel)

	count := 0
	for item := range scanItemChannel {
		meta := item.GetAttachment("meta")
		if meta == nil {
			t.Errorf("Expected item to contain metadata")
		}
		_, ok := meta.(map[string]interface{})["id"]
		if !ok {
			t.Errorf("Expected metadata to contain an id")
		}
		count++
	}

	if count != 10 {
		t.Errorf("Expected %d items, got %d", 10, count)
	}

}