当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.Equal函数代码示例

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


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

示例1: TestPublishMessageDecode1

func TestPublishMessageDecode1(t *testing.T) {
	msgBytes := []byte{
		byte(PUBLISH<<4) | 2,
		23,
		0, // topic name MSB (0)
		7, // topic name LSB (7)
		's', 'u', 'r', 'g', 'e', 'm', 'q',
		0, // packet ID MSB (0)
		7, // packet ID LSB (7)
		's', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e',
	}

	src := bytes.NewBuffer(msgBytes)
	msg := NewPublishMessage()

	n, err := msg.Decode(src)
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, 7, msg.PacketId(), "Error decoding message.")

	assert.Equal(t, true, "surgemq", string(msg.Topic()), "Error deocding topic name.")

	assert.Equal(t, true, []byte{'s', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e'}, msg.Payload(), "Error deocding payload.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:26,代码来源:publish_test.go

示例2: TestPublishMessageFixedHeaderFields

func TestPublishMessageFixedHeaderFields(t *testing.T) {
	msg := NewPublishMessage()
	msg.flags = 11

	assert.True(t, true, msg.Dup(), "Incorrect DUP flag.")

	assert.True(t, true, msg.Retain(), "Incorrect RETAIN flag.")

	assert.Equal(t, true, 1, msg.QoS(), "Incorrect QoS.")

	msg.SetDup(false)
	assert.False(t, true, msg.Dup(), "Incorrect DUP flag.")

	msg.SetRetain(false)
	assert.False(t, true, msg.Retain(), "Incorrect RETAIN flag.")

	err := msg.SetQoS(2)
	assert.NoError(t, true, err, "Error setting QoS.")

	assert.Equal(t, true, 2, msg.QoS(), "Incorrect QoS.")

	err = msg.SetQoS(3)
	assert.Error(t, true, err)

	err = msg.SetQoS(0)
	assert.NoError(t, true, err, "Error setting QoS.")

	assert.Equal(t, true, 0, msg.QoS(), "Incorrect QoS.")

	msg.SetDup(true)
	assert.True(t, true, msg.Dup(), "Incorrect DUP flag.")

	msg.SetRetain(true)
	assert.True(t, true, msg.Retain(), "Incorrect RETAIN flag.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:35,代码来源:publish_test.go

示例3: TestSubackMessageEncode

func TestSubackMessageEncode(t *testing.T) {
	msgBytes := []byte{
		byte(SUBACK << 4),
		6,
		0,    // packet ID MSB (0)
		7,    // packet ID LSB (7)
		0,    // return code 1
		1,    // return code 2
		2,    // return code 3
		0x80, // return code 4
	}

	msg := NewSubackMessage()
	msg.SetPacketId(7)
	msg.AddReturnCode(0)
	msg.AddReturnCode(1)
	msg.AddReturnCode(2)
	msg.AddReturnCode(0x80)

	dst, n, err := msg.Encode()
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, msgBytes, dst.(*bytes.Buffer).Bytes(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:26,代码来源:suback_test.go

示例4: TestPublishMessageEncode

func TestPublishMessageEncode(t *testing.T) {
	msgBytes := []byte{
		byte(PUBLISH<<4) | 2,
		23,
		0, // topic name MSB (0)
		7, // topic name LSB (7)
		's', 'u', 'r', 'g', 'e', 'm', 'q',
		0, // packet ID MSB (0)
		7, // packet ID LSB (7)
		's', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e',
	}

	msg := NewPublishMessage()
	msg.SetTopic([]byte("surgemq"))
	msg.SetQoS(1)
	msg.SetPacketId(7)
	msg.SetPayload([]byte{'s', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e'})

	dst, n, err := msg.Encode()
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, msgBytes, dst.(*bytes.Buffer).Bytes(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:25,代码来源:publish_test.go

示例5: TestUnsubscribeMessageDecode

func TestUnsubscribeMessageDecode(t *testing.T) {
	msgBytes := []byte{
		byte(UNSUBSCRIBE<<4) | 2,
		33,
		0, // packet ID MSB (0)
		7, // packet ID LSB (7)
		0, // topic name MSB (0)
		7, // topic name LSB (7)
		's', 'u', 'r', 'g', 'e', 'm', 'q',
		0, // topic name MSB (0)
		8, // topic name LSB (8)
		'/', 'a', '/', 'b', '/', '#', '/', 'c',
		0,  // topic name MSB (0)
		10, // topic name LSB (10)
		'/', 'a', '/', 'b', '/', '#', '/', 'c', 'd', 'd',
	}

	src := bytes.NewBuffer(msgBytes)
	msg := NewUnsubscribeMessage()

	n, err := msg.Decode(src)
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, UNSUBSCRIBE, msg.Type(), "Error decoding message.")

	assert.Equal(t, true, 3, len(msg.Topics()), "Error decoding topics.")

	assert.True(t, true, msg.TopicExists([]byte("surgemq")), "Topic 'surgemq' should exist.")

	assert.True(t, true, msg.TopicExists([]byte("/a/b/#/c")), "Topic '/a/b/#/c' should exist.")

	assert.True(t, true, msg.TopicExists([]byte("/a/b/#/cdd")), "Topic '/a/b/#/c' should exist.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:35,代码来源:unsubscribe_test.go

示例6: TestSubscribeMessageEncode

func TestSubscribeMessageEncode(t *testing.T) {
	msgBytes := []byte{
		byte(SUBSCRIBE<<4) | 2,
		36,
		0, // packet ID MSB (0)
		7, // packet ID LSB (7)
		0, // topic name MSB (0)
		7, // topic name LSB (7)
		's', 'u', 'r', 'g', 'e', 'm', 'q',
		0, // QoS
		0, // topic name MSB (0)
		8, // topic name LSB (8)
		'/', 'a', '/', 'b', '/', '#', '/', 'c',
		1,  // QoS
		0,  // topic name MSB (0)
		10, // topic name LSB (10)
		'/', 'a', '/', 'b', '/', '#', '/', 'c', 'd', 'd',
		2, // QoS
	}

	msg := NewSubscribeMessage()
	msg.SetPacketId(7)
	msg.AddTopic([]byte("surgemq"), 0)
	msg.AddTopic([]byte("/a/b/#/c"), 1)
	msg.AddTopic([]byte("/a/b/#/cdd"), 2)

	dst, n, err := msg.Encode()
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, msgBytes, dst.(*bytes.Buffer).Bytes(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:33,代码来源:subscribe_test.go

示例7: TestConnackReturnCodes

func TestConnackReturnCodes(t *testing.T) {
	assert.Equal(t, false, ErrUnacceptableProtocolVersion, ConnackCode(1).Error(), "Incorrect ConnackCode error value.")

	assert.Equal(t, false, ErrIdentifierRejected, ConnackCode(2).Error(), "Incorrect ConnackCode error value.")

	assert.Equal(t, false, ErrServerUnavailable, ConnackCode(3).Error(), "Incorrect ConnackCode error value.")

	assert.Equal(t, false, ErrBadUsernameOrPassword, ConnackCode(4).Error(), "Incorrect ConnackCode error value.")

	assert.Equal(t, false, ErrNotAuthorized, ConnackCode(5).Error(), "Incorrect ConnackCode error value.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:11,代码来源:mqtt_test.go

示例8: TestSubackMessageFields

func TestSubackMessageFields(t *testing.T) {
	msg := NewSubackMessage()

	msg.SetPacketId(100)
	assert.Equal(t, true, 100, msg.PacketId(), "Error setting packet ID.")

	msg.AddReturnCode(1)
	assert.Equal(t, true, 1, len(msg.ReturnCodes()), "Error adding return code.")

	err := msg.AddReturnCode(0x90)
	assert.Error(t, true, err)
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:12,代码来源:suback_test.go

示例9: TestSubscribeMessageFields

func TestSubscribeMessageFields(t *testing.T) {
	msg := NewSubscribeMessage()

	msg.SetPacketId(100)
	assert.Equal(t, true, 100, msg.PacketId(), "Error setting packet ID.")

	msg.AddTopic([]byte("/a/b/#/c"), 1)
	assert.Equal(t, true, 1, len(msg.Topics()), "Error adding topic.")

	assert.False(t, true, msg.TopicExists([]byte("a/b")), "Topic should not exist.")

	msg.RemoveTopic([]byte("/a/b/#/c"))
	assert.False(t, true, msg.TopicExists([]byte("/a/b/#/c")), "Topic should not exist.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:14,代码来源:subscribe_test.go

示例10: TestPublishMessageFields

func TestPublishMessageFields(t *testing.T) {
	msg := NewPublishMessage()

	msg.SetTopic([]byte("coolstuff"))
	assert.Equal(t, true, "coolstuff", string(msg.Topic()), "Error setting message topic.")

	err := msg.SetTopic([]byte("coolstuff/#"))
	assert.Error(t, true, err)

	msg.SetPacketId(100)
	assert.Equal(t, true, 100, msg.PacketId(), "Error setting acket ID.")

	msg.SetPayload([]byte("this is a payload to be sent"))
	assert.Equal(t, true, []byte("this is a payload to be sent"), msg.Payload(), "Error setting payload.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:15,代码来源:publish_test.go

示例11: TestPingrespMessageEncode

func TestPingrespMessageEncode(t *testing.T) {
	msgBytes := []byte{
		byte(PINGRESP << 4),
		0,
	}

	msg := NewPingrespMessage()

	dst, n, err := msg.Encode()
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, msgBytes, dst.(*bytes.Buffer).Bytes(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:15,代码来源:ping_test.go

示例12: TestDisconnectMessageEncode

func TestDisconnectMessageEncode(t *testing.T) {
	msgBytes := []byte{
		byte(DISCONNECT << 4),
		0,
	}

	msg := NewDisconnectMessage()

	dst, n, err := msg.Encode()
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, msgBytes, dst.(*bytes.Buffer).Bytes(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:15,代码来源:disconnect_test.go

示例13: TestMessageHeaderDecode4

func TestMessageHeaderDecode4(t *testing.T) {
	headerBytes := []byte{0x62, 0xff, 0xff, 0xff, 0x7f}
	buf := bytes.NewBuffer(headerBytes)
	header := &fixedHeader{
		mtype: 6,
		flags: 2,
	}

	n, err := header.Decode(buf)
	assert.Equal(t, true, 5, n, "Incorrect bytes decoded")

	assert.Equal(t, true, maxRemainingLength, header.RemainingLength(), "Incorrect remaining length")

	assert.Error(t, true, err)
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:15,代码来源:header_test.go

示例14: TestDisconnectMessageDecode

func TestDisconnectMessageDecode(t *testing.T) {
	msgBytes := []byte{
		byte(DISCONNECT << 4),
		0,
	}

	src := bytes.NewBuffer(msgBytes)
	msg := NewDisconnectMessage()

	n, err := msg.Decode(src)
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, DISCONNECT, msg.Type(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:16,代码来源:disconnect_test.go

示例15: TestPingrespMessageDecode

func TestPingrespMessageDecode(t *testing.T) {
	msgBytes := []byte{
		byte(PINGRESP << 4),
		0,
	}

	src := bytes.NewBuffer(msgBytes)
	msg := NewPingrespMessage()

	n, err := msg.Decode(src)
	assert.NoError(t, true, err, "Error decoding message.")

	assert.Equal(t, true, len(msgBytes), n, "Error decoding message.")

	assert.Equal(t, true, PINGRESP, msg.Type(), "Error decoding message.")
}
开发者ID:charlesluo2014,项目名称:mqtt,代码行数:16,代码来源:ping_test.go


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