Esempio n. 1
0
func (t *IntegrationTest) ExpectedCalls() {
	// Expectations
	t.controller.ExpectCall(t.reader, "Read", "", 112)(nil).
		WillOnce(oglemock.Return(17, nil)).
		WillOnce(oglemock.Return(19, nil))

	t.controller.ExpectCall(t.reader, "Read", "", 112)(Not(Equals(nil))).
		WillOnce(oglemock.Return(23, errors.New("taco")))

	// Calls
	var n int
	var err error

	n, err = t.reader.Read(nil)
	ExpectEq(17, n)
	ExpectEq(nil, err)

	n, err = t.reader.Read([]byte{})
	ExpectEq(23, n)
	ExpectThat(err, Error(Equals("taco")))

	n, err = t.reader.Read(nil)
	ExpectEq(19, n)
	ExpectEq(nil, err)

	// Errors
	AssertEq(0, len(t.reporter.errors), "%v", t.reporter.errors)
	AssertEq(0, len(t.reporter.fatalErrors), "%v", t.reporter.fatalErrors)
}
Esempio n. 2
0
func (t *IntegrationTest) WrongTypeForReturn() {
	t.controller.ExpectCall(t.reader, "Read", "foo.go", 112)(nil).
		WillOnce(oglemock.Return(0, errors.New(""))).
		WillOnce(oglemock.Return("taco", errors.New("")))

	// Errors
	AssertEq(0, len(t.reporter.errors), "%v", t.reporter.errors)
	AssertEq(1, len(t.reporter.fatalErrors), "%v", t.reporter.fatalErrors)

	r := t.reporter.fatalErrors[0]
	ExpectEq("foo.go", r.fileName)
	ExpectEq(112, r.lineNumber)
	ExpectThat(r.err, Error(HasSubstr("Return")))
	ExpectThat(r.err, Error(HasSubstr("arg 0")))
	ExpectThat(r.err, Error(HasSubstr("int")))
	ExpectThat(r.err, Error(HasSubstr("string")))
}
Esempio n. 3
0
func (t *DoAllTest) SingleAction() {
	f := func(a int) string { return "" }
	a0 := oglemock.Return("taco")

	action := oglemock.DoAll(a0)
	AssertEq(nil, action.SetSignature(reflect.TypeOf(f)))

	rets := action.Invoke([]interface{}{17})
	ExpectThat(rets, ElementsAre("taco"))
}
Esempio n. 4
0
func (t *DoAllTest) LastActionDoesntLikeSignature() {
	f := func(a int, b string) {}

	a0 := oglemock.Invoke(f)
	a1 := oglemock.Invoke(f)
	a2 := oglemock.Return(17)

	err := oglemock.DoAll(a0, a1, a2).SetSignature(reflect.TypeOf(f))
	ExpectThat(err, Error(HasSubstr("Action 2")))
	ExpectThat(err, Error(HasSubstr("1 vals; expected 0")))
}
Esempio n. 5
0
func (t *DoAllTest) MultipleActions() {
	f := func(a int) string { return "" }

	var saved int
	a0 := oglemock.SaveArg(0, &saved)
	a1 := oglemock.Return("taco")

	action := oglemock.DoAll(a0, a1)
	AssertEq(nil, action.SetSignature(reflect.TypeOf(f)))

	rets := action.Invoke([]interface{}{17})
	ExpectEq(17, saved)
	ExpectThat(rets, ElementsAre("taco"))
}