Exemple #1
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
		}
	}
}