• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang assert.Equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中go/intra/xiaojukeji/com/golang/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestSuiteGetters

func TestSuiteGetters(t *testing.T) {
	suite := new(SuiteTester)
	suite.SetT(t)
	assert.NotNil(t, suite.Assert())
	assert.Equal(t, suite.Assertions, suite.Assert())
	assert.NotNil(t, suite.Require())
	assert.Equal(t, suite.require, suite.Require())
}
开发者ID:hurricane1026,项目名称:testify,代码行数:8,代码来源:suite_test.go


示例2: Test_Arguments_Get

/*
	Arguments helper methods
*/
func Test_Arguments_Get(t *testing.T) {

	var args Arguments = []interface{}{"string", 123, true}

	assert.Equal(t, "string", args.Get(0).(string))
	assert.Equal(t, 123, args.Get(1).(int))
	assert.Equal(t, true, args.Get(2).(bool))

}
开发者ID:hurricane1026,项目名称:testify,代码行数:12,代码来源:mock_test.go


示例3: Test_Mock_On

func Test_Mock_On(t *testing.T) {

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

	assert.Equal(t, mockedService.On("TheExampleMethod"), &mockedService.Mock)
	assert.Equal(t, "TheExampleMethod", mockedService.onMethodName)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:9,代码来源:mock_test.go


示例4: Test_Mock_Called_blocks

func Test_Mock_Called_blocks(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.Mock.On("asyncCall", 1, 2, 3).Return(5, "6", true).After(2 * time.Millisecond)

	ch := make(chan Arguments)

	go asyncCall(&mockedService.Mock, ch)

	select {
	case <-ch:
		t.Fatal("should have waited")
	case <-time.After(1 * time.Millisecond):
	}

	returnArguments := <-ch

	if assert.Equal(t, 1, len(mockedService.Mock.Calls)) {
		assert.Equal(t, "asyncCall", mockedService.Mock.Calls[0].Method)
		assert.Equal(t, 1, mockedService.Mock.Calls[0].Arguments[0])
		assert.Equal(t, 2, mockedService.Mock.Calls[0].Arguments[1])
		assert.Equal(t, 3, mockedService.Mock.Calls[0].Arguments[2])
	}

	if assert.Equal(t, 3, len(returnArguments)) {
		assert.Equal(t, 5, returnArguments[0])
		assert.Equal(t, "6", returnArguments[1])
		assert.Equal(t, true, returnArguments[2])
	}

}
开发者ID:hurricane1026,项目名称:testify,代码行数:32,代码来源:mock_test.go


示例5: Test_Mock_On_WithArgs

func Test_Mock_On_WithArgs(t *testing.T) {

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

	assert.Equal(t, mockedService.On("TheExampleMethod", 1, 2, 3), &mockedService.Mock)
	assert.Equal(t, "TheExampleMethod", mockedService.onMethodName)
	assert.Equal(t, 1, mockedService.onMethodArguments[0])
	assert.Equal(t, 2, mockedService.onMethodArguments[1])
	assert.Equal(t, 3, mockedService.onMethodArguments[2])

}
开发者ID:hurricane1026,项目名称:testify,代码行数:12,代码来源:mock_test.go


示例6: Test_Mock_On_WithFuncTypeArg

func Test_Mock_On_WithFuncTypeArg(t *testing.T) {

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

	assert.Equal(t, mockedService.On("TheExampleMethodFuncType", AnythingOfType("mock.ExampleFuncType")).Return(nil), &mockedService.Mock)
	assert.Equal(t, "TheExampleMethodFuncType", mockedService.onMethodName)
	assert.Equal(t, AnythingOfType("mock.ExampleFuncType"), mockedService.onMethodArguments[0])

	fn := func(string) error { return nil }
	mockedService.TheExampleMethodFuncType(fn)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:13,代码来源:mock_test.go


示例7: Test_Mock_Return_Run

func Test_Mock_Return_Run(t *testing.T) {

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

	assert.Equal(t, mockedService.Mock.On("TheExampleMethod3", AnythingOfType("*mock.ExampleType")).Return(nil).Run(func(args Arguments) {
		arg := args.Get(0).(*ExampleType)
		arg.ran = true
	}), &mockedService.Mock)

	// ensure the call was created
	if assert.Equal(t, 1, len(mockedService.Mock.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)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:29,代码来源:mock_test.go


示例8: Test_Arguments_Error

func Test_Arguments_Error(t *testing.T) {

	var err error = errors.New("An Error")
	var args Arguments = []interface{}{"string", 123, true, err}
	assert.Equal(t, err, args.Error(3))

}
开发者ID:hurricane1026,项目名称:testify,代码行数:7,代码来源:mock_test.go


示例9: Test_Mock_On_WithVariadicFuncWithInterface

func Test_Mock_On_WithVariadicFuncWithInterface(t *testing.T) {

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

	assert.Equal(t, mockedService.On("TheExampleMethodVariadicInterface", []interface{}{1, 2, 3}).Return(nil), &mockedService.Mock)
	assert.Equal(t, "TheExampleMethodVariadicInterface", mockedService.onMethodName)
	assert.Equal(t, []interface{}{1, 2, 3}, mockedService.onMethodArguments[0])

	assert.NotPanics(t, func() {
		mockedService.TheExampleMethodVariadicInterface(1, 2, 3)
	})
	assert.Panics(t, func() {
		mockedService.TheExampleMethodVariadicInterface(1, 2)
	})

}
开发者ID:hurricane1026,项目名称:testify,代码行数:17,代码来源:mock_test.go


示例10: Test_Mock_findExpectedCall

func Test_Mock_findExpectedCall(t *testing.T) {

	m := new(Mock)
	m.On("One", 1).Return("one")
	m.On("Two", 2).Return("two")
	m.On("Two", 3).Return("three")

	f, c := m.findExpectedCall("Two", 3)

	if assert.Equal(t, 2, f) {
		if assert.NotNil(t, c) {
			assert.Equal(t, "Two", c.Method)
			assert.Equal(t, 3, c.Arguments[0])
			assert.Equal(t, "three", c.ReturnArguments[0])
		}
	}

}
开发者ID:hurricane1026,项目名称:testify,代码行数:18,代码来源:mock_test.go


示例11: AssertNumberOfCalls

// AssertNumberOfCalls asserts that the method was called expectedCalls times.
func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls int) bool {
	var actualCalls int = 0
	for _, call := range m.calls() {
		if call.Method == methodName {
			actualCalls++
		}
	}
	return assert.Equal(t, actualCalls, expectedCalls, fmt.Sprintf("Expected number of calls (%d) does not match the actual number of calls (%d).", expectedCalls, actualCalls))
}
开发者ID:hurricane1026,项目名称:testify,代码行数:10,代码来源:mock.go


示例12: Test_Arguments_Diff_WithAnythingOfTypeArgument

func Test_Arguments_Diff_WithAnythingOfTypeArgument(t *testing.T) {

	var args Arguments = []interface{}{"string", AnythingOfType("int"), true}
	var count int
	_, count = args.Diff([]interface{}{"string", 123, true})

	assert.Equal(t, 0, count)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:9,代码来源:mock_test.go


示例13: Test_Arguments_Diff_WithAnythingArgument_InActualToo

func Test_Arguments_Diff_WithAnythingArgument_InActualToo(t *testing.T) {

	var args Arguments = []interface{}{"string", Anything, true}
	var count int
	_, count = args.Diff([]interface{}{"string", 123, true})

	assert.Equal(t, 0, count)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:9,代码来源:mock_test.go


示例14: Test_Arguments_Diff_DifferentNumberOfArgs

func Test_Arguments_Diff_DifferentNumberOfArgs(t *testing.T) {

	var args Arguments = []interface{}{"string", 123, true}
	var diff string
	var count int
	diff, count = args.Diff([]interface{}{"string", 456, "false", "extra"})

	assert.Equal(t, 3, count)
	assert.Contains(t, diff, `extra != (Missing)`)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:11,代码来源:mock_test.go


示例15: Test_Arguments_Diff_WithAnythingOfTypeArgument_Failing

func Test_Arguments_Diff_WithAnythingOfTypeArgument_Failing(t *testing.T) {

	var args Arguments = []interface{}{"string", AnythingOfType("string"), true}
	var count int
	var diff string
	diff, count = args.Diff([]interface{}{"string", 123, true})

	assert.Equal(t, 1, count)
	assert.Contains(t, diff, `string != type int - %!s(int=123)`)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:11,代码来源:mock_test.go


示例16: Test_Mock_findExpectedCall_For_Unknown_Method

func Test_Mock_findExpectedCall_For_Unknown_Method(t *testing.T) {

	m := new(Mock)
	m.On("One", 1).Return("one")
	m.On("Two", 2).Return("two")
	m.On("Two", 3).Return("three")

	f, _ := m.findExpectedCall("Two")

	assert.Equal(t, -1, f)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:12,代码来源:mock_test.go


示例17: Test_Arguments_Diff

func Test_Arguments_Diff(t *testing.T) {

	var args Arguments = []interface{}{"Hello World", 123, true}
	var diff string
	var count int
	diff, count = args.Diff([]interface{}{"Hello World", 456, "false"})

	assert.Equal(t, 2, count)
	assert.Contains(t, diff, `%!s(int=456) != %!s(int=123)`)
	assert.Contains(t, diff, `false != %!s(bool=true)`)

}
开发者ID:hurricane1026,项目名称:testify,代码行数:12,代码来源:mock_test.go


示例18: Test_Mock_TestData

func Test_Mock_TestData(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	if assert.NotNil(t, mockedService.TestData()) {

		mockedService.TestData().Set("something", 123)
		assert.Equal(t, 123, mockedService.TestData().Get("something").Data())

	}

}
开发者ID:hurricane1026,项目名称:testify,代码行数:12,代码来源:mock_test.go


示例19: Test_Mock_Return_After

func Test_Mock_Return_After(t *testing.T) {

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

	assert.Equal(t, mockedService.Mock.On("TheExampleMethod", "A", "B", true).Return(1, "two", true).After(time.Second), &mockedService.Mock)

	// ensure the call was created
	if assert.Equal(t, 1, len(mockedService.Mock.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)

	}

}
开发者ID:hurricane1026,项目名称:testify,代码行数:24,代码来源:mock_test.go


示例20: Test_Mock_Called

func Test_Mock_Called(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("Test_Mock_Called", 1, 2, 3).Return(5, "6", true)

	returnArguments := mockedService.Called(1, 2, 3)

	if assert.Equal(t, 1, len(mockedService.Calls)) {
		assert.Equal(t, "Test_Mock_Called", mockedService.Calls[0].Method)
		assert.Equal(t, 1, mockedService.Calls[0].Arguments[0])
		assert.Equal(t, 2, mockedService.Calls[0].Arguments[1])
		assert.Equal(t, 3, mockedService.Calls[0].Arguments[2])
	}

	if assert.Equal(t, 3, len(returnArguments)) {
		assert.Equal(t, 5, returnArguments[0])
		assert.Equal(t, "6", returnArguments[1])
		assert.Equal(t, true, returnArguments[2])
	}

}
开发者ID:hurricane1026,项目名称:testify,代码行数:22,代码来源:mock_test.go



注:本文中的go/intra/xiaojukeji/com/golang/testify/assert.Equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sops.KeySource类代码示例发布时间:2022-05-28
下一篇:
Golang importer.Default函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap