Beispiel #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)
}
Beispiel #2
0
func (t *EncryptingStore_LoadTest) CallsCrypter() {
	// Wrapped
	ciphertext := []byte{0xde, 0xad}

	ExpectCall(t.wrapped, "Load")(Any(), Any()).
		WillOnce(oglemock.Return(ciphertext, nil))

	// Crypter
	ExpectCall(t.crypter, "Decrypt")(DeepEquals(ciphertext)).
		WillOnce(oglemock.Return(nil, errors.New("")))

	// Call
	t.store.Load(t.ctx, blob.ComputeScore([]byte{}))
}
Beispiel #3
0
func (t *EncryptingStore_StoreTest) WrappedReturnsError() {
	// Crypter
	ExpectCall(t.crypter, "Encrypt")(Any(), Any()).
		WillOnce(oglemock.Return([]byte{}, nil))

	// Wrapped
	ExpectCall(t.wrapped, "Store")(Any(), Any()).
		WillOnce(oglemock.Return(blob.Score{}, errors.New("taco")))

	// Call
	_, err := t.store.Store(t.ctx, &blob.StoreRequest{})

	ExpectThat(err, Error(Equals("taco")))
}
Beispiel #4
0
func (t *EncryptingStore_LoadTest) CrypterReturnsError() {
	// Wrapped
	ExpectCall(t.wrapped, "Load")(Any(), Any()).
		WillOnce(oglemock.Return([]byte{}, nil))

	// Crypter
	ExpectCall(t.crypter, "Decrypt")(Any()).
		WillOnce(oglemock.Return(nil, errors.New("taco")))

	// Call
	_, err := t.store.Load(t.ctx, blob.ComputeScore([]byte{}))

	ExpectThat(err, Error(HasSubstr("Decrypt")))
	ExpectThat(err, Error(HasSubstr("taco")))
}
Beispiel #5
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")))
}
Beispiel #6
0
func (t *EncryptingStore_LoadTest) CrypterSucceeds() {
	// Wrapped
	ExpectCall(t.wrapped, "Load")(Any(), Any()).
		WillOnce(oglemock.Return([]byte{}, nil))

	// Crypter
	expected := []byte{0xde, 0xad}

	ExpectCall(t.crypter, "Decrypt")(Any()).
		WillOnce(oglemock.Return(expected, nil))

	// Call
	blob, err := t.store.Load(t.ctx, blob.ComputeScore([]byte{}))
	AssertEq(nil, err)

	ExpectThat(blob, DeepEquals(expected))
}
Beispiel #7
0
func (t *EncryptingStore_StoreTest) WrappedSucceeds() {
	// Crypter
	ExpectCall(t.crypter, "Encrypt")(Any(), Any()).
		WillOnce(oglemock.Return([]byte{}, nil))

	// Wrapped
	expected := blob.ComputeScore([]byte("taco"))

	ExpectCall(t.wrapped, "Store")(Any(), Any()).
		WillOnce(oglemock.Return(expected, nil))

	// Call
	score, err := t.store.Store(t.ctx, &blob.StoreRequest{})
	AssertEq(nil, err)

	ExpectThat(score, DeepEquals(expected))
}
Beispiel #8
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"))
}
Beispiel #9
0
func (t *EncryptingStore_StoreTest) CallsCrypter() {
	b := []byte{0xde, 0xad}

	// Crypter
	ExpectCall(t.crypter, "Encrypt")(Any(), DeepEquals(b)).
		WillOnce(oglemock.Return(nil, errors.New("")))

	// Call
	t.store.Store(t.ctx, &blob.StoreRequest{Blob: b})
}
Beispiel #10
0
func (t *EncryptingStore_LoadTest) WrappedReturnsError() {
	// Wrapped
	ExpectCall(t.wrapped, "Load")(Any(), Any()).
		WillOnce(oglemock.Return(nil, errors.New("taco")))

	// Call
	_, err := t.store.Load(t.ctx, blob.ComputeScore([]byte{}))

	ExpectThat(err, Error(Equals("taco")))
}
Beispiel #11
0
func (t *EncryptingStore_LoadTest) CallsWrapped() {
	score := blob.ComputeScore([]byte("taco"))

	// Wrapped
	ExpectCall(t.wrapped, "Load")(Any(), DeepEquals(score)).
		WillOnce(oglemock.Return(nil, errors.New("")))

	// Call
	t.store.Load(t.ctx, score)
}
Beispiel #12
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")))
}
Beispiel #13
0
func (t *EncryptingStore_StoreTest) CallsWrapped() {
	// Crypter
	encryptedBlob := []byte{0xde, 0xad}

	ExpectCall(t.crypter, "Encrypt")(Any(), Any()).
		WillOnce(oglemock.Return(encryptedBlob, nil))

	// Wrapped
	var req *blob.StoreRequest
	ExpectCall(t.wrapped, "Store")(Any(), Any()).
		WillOnce(oglemock.DoAll(
			oglemock.SaveArg(1, &req),
			oglemock.Return(blob.Score{}, errors.New(""))))

	// Call
	t.store.Store(t.ctx, &blob.StoreRequest{})

	AssertNe(nil, req)
	ExpectThat(req.Blob, DeepEquals(encryptedBlob))
}
Beispiel #14
0
func (t *EncryptingStore_StoreTest) CrypterReturnsError() {
	// Crypter
	ExpectCall(t.crypter, "Encrypt")(Any(), Any()).
		WillOnce(oglemock.Return(nil, errors.New("taco")))

	// Call
	_, err := t.store.Store(t.ctx, &blob.StoreRequest{})

	ExpectThat(err, Error(HasSubstr("Encrypt")))
	ExpectThat(err, Error(HasSubstr("taco")))
}
Beispiel #15
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"))
}