Пример #1
0
func (r *Runner) assertDetail(key string, actual interface{}, expected *parse.Value) bool {
	if !expected.Equal(actual) {
		actualVal := parse.ParseValue([]byte(fmt.Sprintf("%v", actual)))
		r.log(key, fmt.Sprintf("expected %s: %s  actual %T: %s", expected.Type(), expected, actual, actualVal))
		return false
	}
	return true
}
Пример #2
0
func (r *Runner) assertDetail(line *parse.Line, key string, actual interface{}, expected *parse.Value) bool {
	if !expected.Equal(actual) {
		actualVal := parse.ParseValue([]byte(fmt.Sprintf("%v", actual)))
		actualString := actualVal.String()
		if v, ok := actual.(string); ok {
			actualString = fmt.Sprintf(`"%s"`, v)
		}

		if expected.Type() == actualVal.Type() {
			r.log(key, fmt.Sprintf("expected: %s  actual: %s", expected, actualString))
		} else {
			r.log(key, fmt.Sprintf("expected %s: %s  actual %T: %s", expected.Type(), expected, actual, actualString))
		}

		return false
	}
	// capture any vars (// e.g. {placeholder})
	if capture := line.Capture(); len(capture) > 0 {
		r.capture(capture, actual)
	}
	return true
}
Пример #3
0
func (r *Runner) assertData(line *parse.Line, data interface{}, errData error, key string, expected *parse.Value) bool {
	if errData != nil {
		r.log(key, fmt.Sprintf("expected %s: %s  actual: failed to parse body: %s", expected.Type(), expected, errData))
		return false
	}
	if data == nil {
		r.log(key, fmt.Sprintf("expected %s: %s  actual: no data", expected.Type(), expected))
		return false
	}
	actual, ok := m.GetOK(map[string]interface{}{"Data": data}, key)
	if !ok && expected.Data != nil {
		r.log(key, fmt.Sprintf("expected %s: %s  actual: (missing)", expected.Type(), expected))
		return false
	}
	// capture any vars (// e.g. {placeholder})
	if capture := line.Capture(); len(capture) > 0 {
		r.capture(capture, actual)
	}
	if !ok && expected.Data == nil {
		return true
	}
	if !expected.Equal(actual) {
		actualVal := parse.ParseValue([]byte(fmt.Sprintf("%v", actual)))
		actualString := actualVal.String()
		if v, ok := actual.(string); ok {
			actualString = fmt.Sprintf(`"%s"`, v)
		}
		if expected.Type() == actualVal.Type() {
			r.log(key, fmt.Sprintf("expected: %s  actual: %s", expected, actualString))
		} else {
			r.log(key, fmt.Sprintf("expected %s: %s  actual %T: %s", expected.Type(), expected, actual, actualString))
		}
		return false
	}
	return true
}
Пример #4
0
func (r *Runner) assertData(data interface{}, errData error, key string, expected *parse.Value) bool {
	if errData != nil {
		r.log(key, fmt.Sprintf("expected %s: %s  actual: failed to parse body: %s", expected.Type(), expected, errData))
		return false
	}
	if data == nil {
		r.log(key, fmt.Sprintf("expected %s: %s  actual: no data", expected.Type(), expected))
		return false
	}
	actual, ok := m.GetOK(map[string]interface{}{"Data": data}, key)
	if !ok && expected.Data != nil {
		r.log(key, fmt.Sprintf("expected %s: %s  actual: (missing)", expected.Type(), expected))
		return false
	}
	if !ok && expected.Data == nil {
		return true
	}
	if !expected.Equal(actual) {
		actualVal := parse.ParseValue([]byte(fmt.Sprintf("%v", actual)))
		r.log(key, fmt.Sprintf("expected %s: %s  actual %T: %s", expected.Type(), expected, actual, actualVal))
		return false
	}
	return true
}