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

Golang assert.Equal函数代码示例

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

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



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

示例1: TestCentosSetUserPassword

func TestCentosSetUserPassword(t *testing.T) {
	deps, centos := buildCentos()

	centos.SetUserPassword("my-user", "my-encrypted-password")
	assert.Equal(t, 1, len(deps.cmdRunner.RunCommands))
	assert.Equal(t, []string{"usermod", "-p", "my-encrypted-password", "my-user"}, deps.cmdRunner.RunCommands[0])
}
开发者ID:kangaroo,项目名称:bosh,代码行数:7,代码来源:centos_test.go


示例2: TestSearchService_Code

func TestSearchService_Code(t *testing.T) {
	setup()
	defer tearDown()

	stubGet(t, "/search/code", "code_search", nil)

	searchResults, result := client.Search().Code(nil, M{
		"query": "addClass in:file language:js repo:jquery/jquery"})

	assert.False(t, result.HasError())
	assert.False(t, searchResults.IncompleteResults)
	assert.Equal(t, 7, searchResults.TotalCount)
	assert.Equal(t, 7, len(searchResults.Items))
	assert.EqualValues(t, "classes.js", searchResults.Items[0].Name)
	assert.EqualValues(t, "src/attributes/classes.js", searchResults.Items[0].Path)
	assert.EqualValues(t,
		"f9dba94f7de43d6b6b7256e05e0d17c4741a4cde", searchResults.Items[0].SHA)
	assert.EqualValues(t,
		"https://api.github.com/repositories/167174/contents/src/attributes/classes.js?ref=53aa87f3bf4284763405f3eb8affff296e55ba4f", string(searchResults.Items[0].URL))
	assert.EqualValues(t,
		"https://api.github.com/repositories/167174/git/blobs/f9dba94f7de43d6b6b7256e05e0d17c4741a4cde", searchResults.Items[0].GitURL)
	assert.EqualValues(t,
		"https://github.com/jquery/jquery/blob/53aa87f3bf4284763405f3eb8affff296e55ba4f/src/attributes/classes.js", searchResults.Items[0].HTMLURL)
	assert.Equal(t, 167174, searchResults.Items[0].Repository.ID)
	assert.EqualValues(t,
		"jquery/jquery", searchResults.Items[0].Repository.FullName)
}
开发者ID:pcasaretto,项目名称:go-octokit,代码行数:27,代码来源:search_test.go


示例3: TestNew

func TestNew(t *testing.T) {
	// Generate 10 ids
	ids := make([]ID, 10)
	for i := 0; i < 10; i++ {
		ids[i] = New()
	}
	for i := 1; i < 10; i++ {
		prevID := ids[i-1]
		id := ids[i]
		// Test for uniqueness among all other 9 generated ids
		for j, tid := range ids {
			if j != i {
				assert.NotEqual(t, id, tid, "Generated ID is not unique")
			}
		}
		// Check that timestamp was incremented and is within 30 seconds of the previous one
		secs := id.Time().Sub(prevID.Time()).Seconds()
		assert.Equal(t, (secs >= 0 && secs <= 30), true, "Wrong timestamp in generated ID")
		// Check that machine ids are the same
		assert.Equal(t, id.Machine(), prevID.Machine())
		// Check that pids are the same
		assert.Equal(t, id.Pid(), prevID.Pid())
		// Test for proper increment
		delta := int(id.Counter() - prevID.Counter())
		assert.Equal(t, delta, 1, "Wrong increment in generated ID")
	}
}
开发者ID:rs,项目名称:xid,代码行数:27,代码来源:id_test.go


示例4: TestCullInvalidConnections

func TestCullInvalidConnections(t *testing.T) {
	d := newDefaultDaemon()
	// Is fine
	d.ExpectingIntroductions[addr] = time.Now()
	// Is expired
	d.ExpectingIntroductions[addrb] = util.ZeroTime()
	// Is not in pool
	d.ExpectingIntroductions[addrc] = util.ZeroTime()
	d.Peers.Peers.AddPeer(addr)
	d.Peers.Peers.AddPeer(addrb)
	d.Peers.Peers.AddPeer(addrc)
	d.Pool.Pool.Addresses[addr] = gnetConnection(addr)
	d.Pool.Pool.Addresses[addrb] = gnetConnection(addrb)
	d.Pool.Pool.Addresses[addrb].Id = 2
	d.Pool.Pool.Pool[1] = d.Pool.Pool.Addresses[addr]
	d.Pool.Pool.Pool[2] = d.Pool.Pool.Addresses[addrb]

	assert.NotPanics(t, d.cullInvalidConnections)

	assert.Equal(t, len(d.ExpectingIntroductions), 1)
	assert.Equal(t, len(d.Peers.Peers.Peerlist), 2)
	assert.Equal(t, len(d.Pool.Pool.DisconnectQueue), 1)
	if len(d.Pool.Pool.DisconnectQueue) == 0 {
		t.Fatal("pool.Pool.DisconnectQueue not empty, would block")
	}
	de := <-d.Pool.Pool.DisconnectQueue
	assert.Equal(t, de.ConnId, 2)
	assert.Equal(t, de.Reason, DisconnectIntroductionTimeout)
	shutdown(d)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:30,代码来源:daemon_test.go


示例5: TestFormIsValid

// TestFormIsValid tests data that come from request (url.Values)
func TestFormIsValid(t *testing.T) {
	postData := url.Values{
		"field1": []string{"Foo"},
		"field2": []string{"Bar"},
		"fieldX": []string{"Ham"},
	}

	f := Form{
		Fields: map[string]*Field{
			"field1": &Field{
				Type: &Input{},
			},
			"field2": &Field{
				Type: &Input{},
			},
		},
	}

	assert.Equal(
		t, f.CleanedData, *new(Data),
		"CleanedData should be empty at beggining")

	assert.True(t, f.IsValid(postData), "Form should pass")
	assert.Equal(
		t, f.CleanedData, Data{"field1": "Foo", "field2": "Bar"},
		"Forms CleanedData field should contain cleaned data")

	assert.True(t, f.IsValid(url.Values{}), "Form should pass")
	assert.Equal(
		t, f.CleanedData, Data{"field1": "", "field2": ""},
		"Form should pass")
}
开发者ID:Alkemic,项目名称:forms,代码行数:33,代码来源:form_test.go


示例6: TestServiceSummaryGetSummariesInCurrentSpace

func TestServiceSummaryGetSummariesInCurrentSpace(t *testing.T) {
	req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
		Method:   "GET",
		Path:     "/v2/spaces/my-space-guid/summary",
		Response: serviceInstanceSummariesResponse,
	})

	ts, handler, repo := createServiceSummaryRepo(t, req)
	defer ts.Close()

	serviceInstances, apiResponse := repo.GetSummariesInCurrentSpace()
	assert.True(t, handler.AllRequestsCalled())

	assert.True(t, apiResponse.IsSuccessful())
	assert.Equal(t, 1, len(serviceInstances))

	instance1 := serviceInstances[0]
	assert.Equal(t, instance1.Name, "my-service-instance")
	assert.Equal(t, instance1.ServicePlan.Name, "spark")
	assert.Equal(t, instance1.ServiceOffering.Label, "cleardb")
	assert.Equal(t, instance1.ServiceOffering.Label, "cleardb")
	assert.Equal(t, instance1.ServiceOffering.Provider, "cleardb-provider")
	assert.Equal(t, instance1.ServiceOffering.Version, "n/a")
	assert.Equal(t, len(instance1.ApplicationNames), 2)
	assert.Equal(t, instance1.ApplicationNames[0], "app1")
	assert.Equal(t, instance1.ApplicationNames[1], "app2")
}
开发者ID:pmuellr,项目名称:cli,代码行数:27,代码来源:service_summary_test.go


示例7: TestMakePrivateConnections

func TestMakePrivateConnections(t *testing.T) {
	d := newDefaultDaemon()
	defer shutdown(d)
	d.Pool.Config.DialTimeout = time.Hour
	addr := "192.168.1.198:43071"
	addrb := "192.168.1.197:43072"
	// Two privates
	p, err := d.Peers.Peers.AddPeer(addr)
	assert.Nil(t, err)
	p.Private = true
	p, err = d.Peers.Peers.AddPeer(addrb)
	assert.Nil(t, err)
	p.Private = true
	// Not private
	p, err = d.Peers.Peers.AddPeer(addrc)
	assert.Nil(t, err)
	p.Private = false

	// Disabled
	d.Config.DisableOutgoingConnections = true
	d.makePrivateConnections()
	assert.Equal(t, len(d.pendingConnections), 0)

	// Enabled
	d.Config.DisableOutgoingConnections = false
	d.makePrivateConnections()
	assert.Equal(t, len(d.pendingConnections), 2)
	assert.NotNil(t, d.pendingConnections[addr])
	assert.NotNil(t, d.pendingConnections[addrb])
	assert.Nil(t, d.pendingConnections[addrc])
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:31,代码来源:daemon_test.go


示例8: TestOutputService9ProtocolTestSupportsHeaderMapsCase1

func TestOutputService9ProtocolTestSupportsHeaderMapsCase1(t *testing.T) {
	svc := NewOutputService9ProtocolTest(nil)

	buf := bytes.NewReader([]byte("{}"))
	req, out := svc.OutputService9TestCaseOperation1Request(nil)
	req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}

	// set headers
	req.HTTPResponse.Header.Set("Content-Length", "10")
	req.HTTPResponse.Header.Set("X-Bam", "boo")
	req.HTTPResponse.Header.Set("X-Foo", "bar")

	// unmarshal response
	restjson.UnmarshalMeta(req)
	restjson.Unmarshal(req)
	assert.NoError(t, req.Error)

	// assert response
	assert.NotNil(t, out) // ensure out variable is used
	assert.Equal(t, "10", *out.AllHeaders["Content-Length"])
	assert.Equal(t, "boo", *out.AllHeaders["X-Bam"])
	assert.Equal(t, "bar", *out.AllHeaders["X-Foo"])
	assert.Equal(t, "boo", *out.PrefixedHeaders["Bam"])
	assert.Equal(t, "bar", *out.PrefixedHeaders["Foo"])

}
开发者ID:jloper3,项目名称:amazon-ecs-cli,代码行数:26,代码来源:unmarshal_test.go


示例9: TestSimpleEvent

func TestSimpleEvent(t *testing.T) {
	transp := newMockTransport()
	client := newClientTestDriver(newLumberjackClient(transp, 5*time.Second))

	event := common.MapStr{"name": "me", "line": 10}
	client.Publish([]common.MapStr{event})

	// receive window message
	buf := streambuf.New(nil)
	win, err := recvMessage(buf, transp)
	assert.Nil(t, err)

	// receive data message
	msg, err := recvMessage(buf, transp)
	assert.Nil(t, err)

	// send ack
	sendAck(transp, 1)

	// stop test driver
	transp.Close()
	client.Stop()

	// validate
	assert.NotNil(t, win)
	assert.NotNil(t, msg)
	assert.Equal(t, 1, len(msg.events))
	msg = msg.events[0]
	assert.Equal(t, "me", msg.doc["name"])
	assert.Equal(t, 10.0, msg.doc["line"])
}
开发者ID:kbering,项目名称:libbeat,代码行数:31,代码来源:client_test.go


示例10: TestFilterFlags

func TestFilterFlags(t *testing.T) {
	result := filterFlags("text/html ")
	assert.Equal(t, result, "text/html")

	result = filterFlags("text/html;")
	assert.Equal(t, result, "text/html")
}
开发者ID:lholiveira,项目名称:go-getting-started,代码行数:7,代码来源:utils_test.go


示例11: TestAddRoute

func TestAddRoute(t *testing.T) {
	node1, node2 := NewNode(), NewNode()
	assert.Len(t, node1.RouteForwardingRules, 0, "Should be 0 routes")

	ccid := node1.AddControlChannel()
	node1.Tick() // run channels consuming

	tf := transport.NewTransportFactory()
	tf.ConnectNodeToNode(node1, node2)
	tr1, _ := tf.GetTransports()
	tid1 := tr1.Id

	incomingRouteId := messages.RandRouteId()
	outgoingRouteId := messages.RandRouteId()

	msg := messages.AddRouteControlMessage{
		(messages.TransportId)(0),
		tr1.Id,
		incomingRouteId,
		outgoingRouteId,
	}
	msgS := messages.Serialize(messages.MsgAddRouteControlMessage, msg)

	controlMessage := messages.InControlMessage{ccid, msgS}

	node1.InjectControlMessage(controlMessage)
	time.Sleep(1 * time.Millisecond)

	assert.Len(t, node1.RouteForwardingRules, 1, "Should be 1 routes")
	assert.Equal(t, node1.RouteForwardingRules[incomingRouteId].IncomingRoute, incomingRouteId)
	assert.Equal(t, node1.RouteForwardingRules[incomingRouteId].OutgoingRoute, outgoingRouteId)
	assert.Equal(t, node1.RouteForwardingRules[incomingRouteId].OutgoingTransport, tid1)

	fmt.Println("--------------------\n")
}
开发者ID:skycoin,项目名称:skycoin,代码行数:35,代码来源:node_test.go


示例12: TestChooseData

func TestChooseData(t *testing.T) {
	A := "a"
	B := "b"
	assert.Equal(t, chooseData(A, B), A)
	assert.Equal(t, chooseData(nil, B), B)
	assert.Panics(t, func() { chooseData(nil, nil) })
}
开发者ID:lholiveira,项目名称:go-getting-started,代码行数:7,代码来源:utils_test.go


示例13: assertRequestIsProcessedSynchronously

func assertRequestIsProcessedSynchronously(t *testing.T, req boshmbus.Request) {
	settings, handler, platform, taskService, actionFactory := getAgentDependencies()

	// when action is successful
	actionFactory.CreateAction = &fakeaction.TestAction{
		RunValue: "some value",
	}

	agent := New(settings, handler, platform, taskService, actionFactory)

	err := agent.Run()
	assert.NoError(t, err)
	assert.True(t, handler.ReceivedRun)

	resp := handler.Func(req)
	assert.Equal(t, req.Method, actionFactory.CreateMethod)
	assert.Equal(t, req.GetPayload(), actionFactory.CreateAction.RunPayload)
	assert.Equal(t, boshmbus.NewValueResponse("some value"), resp)

	// when action returns an error
	actionFactory.CreateAction = &fakeaction.TestAction{
		RunErr: errors.New("some error"),
	}

	agent = New(settings, handler, platform, taskService, actionFactory)
	agent.Run()

	resp = handler.Func(req)
	boshassert.MatchesJsonString(t, resp, `{"exception":{"message":"some error"}}`)
}
开发者ID:joanesespanol,项目名称:bosh,代码行数:30,代码来源:agent_test.go


示例14: TestCentosSetupDhcp

func TestCentosSetupDhcp(t *testing.T) {
	deps, centos := buildCentos()
	testCentosSetupDhcp(t, deps, centos)

	assert.Equal(t, len(deps.cmdRunner.RunCommands), 1)
	assert.Equal(t, deps.cmdRunner.RunCommands[0], []string{"service", "network", "restart"})
}
开发者ID:kangaroo,项目名称:bosh,代码行数:7,代码来源:centos_test.go


示例15: testStateTrace

func testStateTrace(t *testing.T, transitions []transition) *Registry {
	assert := assert.New(t)

	registry := NewInMemoryRegistry()
	a, _ := fakePodTask("a")
	a, _ = registry.Register(a, nil)

	// initial pending state
	assert.Equal(a.State, StatePending)

	for _, transition := range transitions {
		if transition.expectPanic {
			assert.Panics(func() {
				registry.UpdateStatus(fakeStatusUpdate(a.ID, transition.statusUpdate))
			})
		} else {
			a, _ = registry.UpdateStatus(fakeStatusUpdate(a.ID, transition.statusUpdate))
			if transition.expectedState == nil {
				a, _ = registry.Get(a.ID)
				assert.Nil(a, "expected task to be deleted from registry after status update to %v", transition.statusUpdate)
			} else {
				assert.Equal(a.State, *transition.expectedState)
			}
		}
	}

	return &registry
}
开发者ID:qinguoan,项目名称:vulcan,代码行数:28,代码来源:registry_test.go


示例16: TestCreateSpendsWithBurn

func TestCreateSpendsWithBurn(t *testing.T) {
	now := tNow()
	amt := wallet.Balance{10e6, 100}
	uxs := makeUxBalances([]wallet.Balance{
		wallet.Balance{1e6, 50},
		wallet.Balance{8e6, 40},
		wallet.Balance{2e6, 60},
	}, now)
	// Force them to get sorted
	uxs[2].Head.BkSeq = uint64(0)
	uxs[1].Head.BkSeq = uint64(1)
	uxs[0].Head.BkSeq = uint64(2)
	cuxs := append(coin.UxArray{}, uxs...)
	// Should spend 8e6,2e6 for the exact amount, but have to add 1e6 to
	// obtain +50 for a 50% fee
	spends, err := createSpends(now, uxs, amt, 0, 2)
	assert.Nil(t, err)
	assert.Equal(t, len(spends), 3)
	assert.Equal(t, spends, coin.UxArray{cuxs[2], cuxs[1], cuxs[0]})

	have := wallet.Balance{0, 0}
	for _, ux := range spends {
		have = have.Add(wallet.NewBalanceFromUxOut(now, &ux))
	}
	burn, change, err := calculateBurnAndChange(have.Hours, amt.Hours, 0, 2)
	assert.Equal(t, burn, uint64(50))
	assert.Equal(t, change, uint64(0))
	assert.Nil(t, err)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:29,代码来源:spend_test.go


示例17: TestRead

func TestRead(t *testing.T) {
	assert := assert.New(t)
	ds := datas.NewDataStore(chunks.NewMemoryStore())

	dataString := `a,1,true
b,2,false
`
	r := NewCSVReader(bytes.NewBufferString(dataString), ',')

	headers := []string{"A", "B", "C"}
	kinds := KindSlice{types.StringKind, types.Int8Kind, types.BoolKind}
	l, typeRef, typeDef := Read(r, "test", headers, kinds, ds)

	assert.Equal(uint64(2), l.Len())

	assert.True(typeRef.IsUnresolved())

	desc, ok := typeDef.Desc.(types.StructDesc)
	assert.True(ok)
	assert.Len(desc.Fields, 3)
	assert.Equal("A", desc.Fields[0].Name)
	assert.Equal("B", desc.Fields[1].Name)
	assert.Equal("C", desc.Fields[2].Name)

	assert.True(l.Get(0).(types.Struct).Get("A").Equals(types.NewString("a")))
	assert.True(l.Get(1).(types.Struct).Get("A").Equals(types.NewString("b")))

	assert.True(l.Get(0).(types.Struct).Get("B").Equals(types.Int8(1)))
	assert.True(l.Get(1).(types.Struct).Get("B").Equals(types.Int8(2)))

	assert.True(l.Get(0).(types.Struct).Get("C").Equals(types.Bool(true)))
	assert.True(l.Get(1).(types.Struct).Get("C").Equals(types.Bool(false)))
}
开发者ID:arv,项目名称:noms-old,代码行数:33,代码来源:read_test.go


示例18: TestBlobLen

func TestBlobLen(t *testing.T) {
	assert := assert.New(t)
	b := NewBlob(&bytes.Buffer{})
	assert.Equal(uint64(0), b.Len())
	b = NewBlob(bytes.NewBuffer([]byte{0x01}))
	assert.Equal(uint64(1), b.Len())
}
开发者ID:arv,项目名称:noms-old,代码行数:7,代码来源:blob_test.go


示例19: TestSendPings

func TestSendPings(t *testing.T) {
	d := newDefaultDaemon()
	defer shutdown(d)
	c := gnetConnection(addr)
	go d.Pool.Pool.ConnectionWriteLoop(c)
	d.Pool.Pool.Pool[1] = c
	assert.NotPanics(t, d.Pool.sendPings)
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 1)
	if len(d.Pool.Pool.SendResults) == 0 {
		t.Fatal("SendResults empty, would block")
	}
	sr := <-d.Pool.Pool.SendResults
	assert.Equal(t, sr.Connection, c)
	assert.Nil(t, sr.Error)
	_, ok := sr.Message.(*PingMessage)
	assert.True(t, ok)
	assert.False(t, c.LastSent.IsZero())

	// No pings should be sent, since we just pinged
	lastSent := c.LastSent
	assert.NotPanics(t, d.Pool.sendPings)
	wait()
	assert.Equal(t, len(d.Pool.Pool.SendResults), 0)
	assert.Equal(t, c.LastSent, lastSent)
}
开发者ID:kinghuabg,项目名称:skycoin,代码行数:26,代码来源:daemon_test.go


示例20: TestUpdateUser

func TestUpdateUser(t *testing.T) {
	assert := assert.New(t)
	s := sw.NewUserApi()
	newUser := sw.User{
		Id:         1000,
		FirstName:  "gopher20",
		LastName:   "lang20",
		Username:   "gopher",
		Password:   "lang",
		Email:      "[email protected]",
		Phone:      "5101112222",
		UserStatus: 1}

	apiResponse, err := s.UpdateUser("gopher", newUser)

	if err != nil {
		t.Errorf("Error while deleting user by id")
		t.Log(err)
	}
	if apiResponse.Response.StatusCode != 200 {
		t.Log(apiResponse.Response)
	}

	//verify changings are correct
	resp, apiResponse, err := s.GetUserByName("gopher")
	if err != nil {
		t.Errorf("Error while getting user by id")
		t.Log(err)
	} else {
		assert.Equal(resp.Id, int64(1000), "User id should be equal")
		assert.Equal(resp.FirstName, "gopher20", "User name should be gopher")
		assert.Equal(resp.Password, "lang", "User name should be the same")
	}
}
开发者ID:Roustalski,项目名称:swagger-codegen,代码行数:34,代码来源:user_api_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang assert.EqualError函数代码示例发布时间:2022-05-28
下一篇:
Golang assert.Empty函数代码示例发布时间: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