Exemplo n.º 1
0
func (t *TestCase) TestName() string {
	out := ""
	for _, v := range strings.Split(t.Description, " ") {
		out += util.Capitalize(v)
	}
	return out
}
Exemplo n.º 2
0
func (t *TestAssertion) GoCode() string {
	call, actual, expected := "", "", fmt.Sprintf("%#v", t.Expected)

	if expected == "<nil>" {
		expected = "nil"
	}

	switch t.Context {
	case "error":
		actual = "err"
	case "data":
		actual = "resp"
	default:
		panic("unsupported assertion context " + t.Context)
	}

	if t.Path != "" {
		actual += "." + util.Capitalize(t.Path)
	}

	switch t.Assertion {
	case "typeof":
		return "" // do nothing for typeof checks
	case "equal":
		if actual == "err" && expected == "nil" {
			call = "assert.NoError"
		} else {
			call = "assert.Equal"
		}
	case "notequal":
		call = "assert.NotEqual"
	case "contains":
		call = "utilassert.Match"
	default:
		panic("unsupported assertion type " + t.Assertion)
	}

	return fmt.Sprintf("%s(t, %s, %s)\n", call, expected, actual)
}