示例#1
0
func TestEquals(t *testing.T) {
	assert := assert.New(t)

	r0 := Parse("sha1-0000000000000000000000000000000000000000")
	r01 := Parse("sha1-0000000000000000000000000000000000000000")
	r1 := Parse("sha1-0000000000000000000000000000000000000001")

	assert.Equal(r0, r01)
	assert.Equal(r01, r0)
	assert.NotEqual(r0, r1)
	assert.NotEqual(r1, r0)
}
示例#2
0
func Test_Mock_Return_Run(t *testing.T) {

	// make a test impl object
	var mockedService = new(TestExampleImplementation)

	fn := func(args Arguments) {
		arg := args.Get(0).(*ExampleType)
		arg.ran = true
	}

	c := mockedService.Mock.
		On("TheExampleMethod3", AnythingOfType("*mock.ExampleType")).
		Return(nil).
		Run(fn)

	require.Equal(t, []*Call{c}, mockedService.ExpectedCalls)

	call := mockedService.Mock.ExpectedCalls[0]

	assert.Equal(t, "TheExampleMethod3", call.Method)
	assert.Equal(t, AnythingOfType("*mock.ExampleType"), call.Arguments[0])
	assert.Equal(t, nil, call.ReturnArguments[0])
	assert.Equal(t, 0, call.Repeatability)
	assert.NotEqual(t, nil, call.WaitFor)
	assert.NotNil(t, call.Run)

	et := ExampleType{}
	assert.Equal(t, false, et.ran)
	mockedService.TheExampleMethod3(&et)
	assert.Equal(t, true, et.ran)
}
示例#3
0
func Test_Mock_Return_After(t *testing.T) {

	// make a test impl object
	var mockedService = new(TestExampleImplementation)

	c := mockedService.Mock.
		On("TheExampleMethod", "A", "B", true).
		Return(1, "two", true).
		After(time.Second)

	require.Equal(t, []*Call{c}, mockedService.ExpectedCalls)

	call := mockedService.Mock.ExpectedCalls[0]

	assert.Equal(t, "TheExampleMethod", call.Method)
	assert.Equal(t, "A", call.Arguments[0])
	assert.Equal(t, "B", call.Arguments[1])
	assert.Equal(t, true, call.Arguments[2])
	assert.Equal(t, 1, call.ReturnArguments[0])
	assert.Equal(t, "two", call.ReturnArguments[1])
	assert.Equal(t, true, call.ReturnArguments[2])
	assert.Equal(t, 0, call.Repeatability)
	assert.NotEqual(t, nil, call.WaitFor)

}
示例#4
0
func TestConstructQueryString(t *testing.T) {
	assert := assert.New(t)
	prefix := "TestConstructQueryString"

	d1, e1 := ioutil.TempDir(os.TempDir(), prefix)
	defer os.RemoveAll(d1)
	d2, e2 := ioutil.TempDir(os.TempDir(), prefix)
	defer os.RemoveAll(d2)

	assert.NoError(e1)
	assert.NoError(e2)

	qs, stores := constructQueryString([]string{
		"foo=bar",
		"store1=ldb:" + d1,
		"store2=ldb:" + d2,
		"store3=ldb:" + d1,
		"hello=world",
	})

	assert.Equal(5, len(qs))
	assert.Equal("bar", qs.Get("foo"))
	assert.True(strings.HasPrefix(qs.Get("store1"), dsPathPrefix))
	assert.True(strings.HasPrefix(qs.Get("store2"), dsPathPrefix))
	assert.True(strings.HasPrefix(qs.Get("store3"), dsPathPrefix))
	assert.Equal(qs.Get("store1"), qs.Get("store3"))
	assert.NotEqual(qs.Get("store1"), qs.Get("store2"))
	assert.Equal(2, len(stores))
}
示例#5
0
func TestDigestSlice(t *testing.T) {
	r := New(Sha1Digest{})
	d := r.DigestSlice()
	assert.Equal(t, r.DigestSlice(), d)
	// DigestSlice() must return a copy otherwise things get weird.
	d[0] = 0x01
	assert.NotEqual(t, r.DigestSlice(), d)
}
示例#6
0
// NotEqual asserts that the specified values are NOT equal.
//
//    assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
	if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
		t.FailNow()
	}
}
示例#7
0
// TestTwo is another example of a test.
func (suite *SuiteTester) TestTwo() {
	beforeCount := suite.TestTwoRunCount
	suite.TestTwoRunCount++
	assert.NotEqual(suite.T(), suite.TestTwoRunCount, beforeCount)
	suite.NotEqual(suite.TestTwoRunCount, beforeCount)
}