Beispiel #1
0
func ScanPutMatch(t btesting.T, bucketId typing.BucketId,
	settings *ScanSettings,
	scanEntries []ScanEntry) {

	// First put some entries
	for _, entry := range scanEntries {
		t.Request(btesting.Request{
			Input: btesting.Object{
				"Operation": "Put",
				"Data": btesting.Object{
					"BucketId": writer.BucketId(bucketId),
					"Key":      writer.Key(entry.Key),
					"Value":    "", // Currently empty value
				},
			},
			Expecting: btesting.Object{
				"Code": eval.RetcodeOk(),
			},
		})
		if t.Failed() {
			return
		}
	}

	// ... then see if we can find them
	ScanMatch(t, bucketId, settings, scanEntries)
}
Beispiel #2
0
func CreateBucket(t btesting.T, bucketTypeId typing.BucketTypeId,
	outBucketId *typing.BucketId) {

	t.Request(btesting.Request{
		Input: btesting.Object{
			"Operation": "CreateBucket",
			"Data": btesting.Object{
				"TypeId": writer.BucketType(bucketTypeId),
			},
		},
		Expecting: btesting.Object{
			"Code": eval.RetcodeOk(),
			"Data": btesting.Object{
				"Id": eval.IsAnyBucketId(outBucketId),
			},
		},
	})
}
Beispiel #3
0
func Put(t btesting.T, bucketId typing.BucketId,
	key typing.Key,
	value typing.Value) {

	t.Request(btesting.Request{
		Input: btesting.Object{
			"Operation": "Put",
			"Data": btesting.Object{
				"BucketId": writer.BucketId(bucketId),
				"Key":      writer.Key(key),
				"Value":    writer.Value(value),
			},
		},
		Expecting: btesting.Object{
			"Code": eval.RetcodeOk(),
		},
	})
}
Beispiel #4
0
// 1. Creates a bucket (storage)
// 2. Sees what metadata can be found for hat bucket.
func testScanMetadata(t btesting.T) {
	// The haser bucket is the simplest one, it currently only has one single metadata:
	// 'const.system.type_id'

	// First create a bucket
	var bucketId typing.BucketId
	operations.CreateBucket(t, typing.TypeId_Store, &bucketId)
	if t.Failed() {
		return
	}

	var keyAsBinary []byte
	t.Request(btesting.Request{
		Input: btesting.Object{
			"Operation": "Scan",
			"Data": btesting.Object{
				"BucketId": fmt.Sprintf(":meta-id:%v", bucketId.ToBase32String()),
				"FromKey":  "",
				"Limit":    1,
			},
		},
		Expecting: btesting.Object{
			"Code": eval.RetcodeOk(),
			"Data": btesting.Object{
				"HasMore": false,
				"Results": btesting.Array{
					btesting.Object{
						"Key": btesting.Array{eval.IsAnyBinaryB32(&keyAsBinary)},
					},
				},
			},
		},
	})
	if t.Failed() {
		return
	}
	keyAsString := string(keyAsBinary)
	if keyAsString != "const.system.type_id" {
		t.Errorf("Expecting to have the metadata const.system.type_id but have %v",
			keyAsString)
		return
	}
}
Beispiel #5
0
func CreateBucketWithMetadata(t btesting.T, bucketTypeId typing.BucketTypeId,
	metadata map[string][]byte,
	outBucketId *typing.BucketId) {
	t.Request(btesting.Request{
		Input: btesting.Object{
			"Operation": "CreateBucket",
			"Data": btesting.Object{
				"TypeId":   writer.BucketType(bucketTypeId),
				"Metadata": writer.Metadata(metadata),
			},
		},
		Expecting: btesting.Object{
			"Code": eval.RetcodeOk(),
			"Data": btesting.Object{
				"Id": eval.IsAnyBucketId(outBucketId),
			},
		},
	})
}
Beispiel #6
0
func ScanMatch(t btesting.T, bucketId typing.BucketId,
	settings *ScanSettings,
	scanEntries []ScanEntry) {

	var resultsSlice []interface{}

	t.Request(btesting.Request{
		Input: btesting.Object{
			"Operation": "Scan",
			"Data": btesting.Object{
				"BucketId":      writer.BucketId(bucketId),
				"FromKey":       settings.FromKey,
				"FromExclusive": settings.FromExclusive,
				"ToKey":         settings.ToKeyOptional,
				"ToExclusive":   settings.ToExclusive,
				"Reverse":       settings.Reverse,
				"Limit":         settings.Limit,
				"Skip":          settings.Skip,
			},
		},
		Expecting: btesting.Object{
			"Code": eval.RetcodeOk(),
			"Data": btesting.Object{
				"HasMore": settings.ExpectToHaveMore,
				"Results": eval.IsAnySlice(&resultsSlice),
			},
		},
	})
	if t.Failed() {
		return
	}

	// Test if all values can be found
	var matched bool
	var collectedErrorMsgs []string
	for _, entry := range scanEntries {
		collectedErrorMsgs = nil
		matched = false
		for _, actual := range resultsSlice {
			actualObj, ok := actual.(map[string]interface{})
			if !ok {
				t.Errorf("Got something that's no a object in the results, it's %T.", actual)
				return
			}
			keyInterface := actualObj["Key"]
			t.Evaluator().Evaluate(entry.Key, keyInterface)
			if !t.Failed() {
				// Ok, we have a match
				matched = true
			} else {
				collectedErrorMsgs = append(collectedErrorMsgs, t.FailedMessage())
				// Clear failure and try next
				t.ClearFailure()
			}
		}
		if matched != entry.Match {
			// Error
			t.Errorf("Entry with key %v expected to match? %v, actually matched? %v. "+
				"All results: %v. Collected errors: %v",
				entry.Key, entry.Match, matched, resultsSlice, collectedErrorMsgs)
			return
		}
	}
}