當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assertion.Equal函數代碼示例

本文整理匯總了Golang中github.com/Jxck/assertion.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestStringLiteralDecode

func TestStringLiteralDecode(t *testing.T) {
	// D.2.1.  Literal Header Field with Indexing
	var indexing Indexing = WITH
	var name, value string = "custom-key", "custom-header"
	buf := []byte{
		0x40, 0x0a,
		0x63, 0x75,
		0x73, 0x74,
		0x6f, 0x6d,
		0x2d, 0x6b,
		0x65, 0x79,
		0x0d, 0x63,
		0x75, 0x73,
		0x74, 0x6f,
		0x6d, 0x2d,
		0x68, 0x65,
		0x61, 0x64,
		0x65, 0x72,
	}

	sw := swrap.New(buf)
	decoded := DecodeHeader(&sw)
	frame, ok := decoded.(*StringLiteral)
	assert.Equal(t, ok, true)
	expected := NewStringLiteral(indexing, name, value)

	assert.Equal(t, frame, expected)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:28,代碼來源:decoder_test.go

示例2: TestSettingsCase

func TestSettingsCase(t *testing.T) {
	var c TestCase
	framecase := []byte(`{
    "error": null,
    "wire": "00000C040000000000000100002000000300001388",
    "frame": {
      "length": 12,
      "frame_payload": {
        "settings": [
          [
            1,
            8192
          ],
          [
            3,
            5000
          ]
        ],
        "padding_length": null,
        "padding": null
      },
      "flags": 0,
      "stream_identifier": 0,
      "type": 4
    },
    "draft": 14,
    "description": "noraml rst stream frame"
  }`)

	err := json.Unmarshal(framecase, &c)
	if err != nil {
		t.Fatal(err)
	}

	// trace data
	wire := c.Wire
	flags := Flag(c.Frame.Flags)
	streamId := c.Frame.StreamId

	settings := map[SettingsID]int32{
		1: 8192,
		3: 5000,
	}

	// compare struct
	expected := NewSettingsFrame(flags, streamId, settings)
	actual, err := ReadFrame(hexToBuffer(wire))
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, actual, expected)

	// compare wire
	buf := bytes.NewBuffer(make([]byte, 0))
	expected.Write(buf)
	hexdump := strings.ToUpper(hex.EncodeToString(buf.Bytes()))
	assert.Equal(t, wire, hexdump)
}
開發者ID:mashuai,項目名稱:http2,代碼行數:58,代碼來源:frame_test.go

示例3: TestHeadersPriorityCase

func TestHeadersPriorityCase(t *testing.T) {
	var c TestCase
	var p HeadersPriorityPayload
	framecase := []byte(`{
    "error": null,
    "wire": "000023012800000003108000001409746869732069732064756D6D79546869732069732070616464696E672E",
    "frame": {
      "length": 35,
      "frame_payload": {
        "priority": {
          "stream_dependency": 20,
          "weight": 10,
          "exclusive": true
        },
        "header_block_fragment": "this is dummy",
        "padding_length": 16,
        "padding": "This is padding."
      },
      "flags": 40,
      "stream_identifier": 3,
      "type": 1
    },
    "draft": 14,
    "description": "noraml headers frame including priority"
  }`)

	// ignore error
	json.Unmarshal(framecase, &c)
	json.Unmarshal(c.Frame.Payload, &p)

	// trace data
	wire := c.Wire
	flags := Flag(c.Frame.Flags)
	streamId := c.Frame.StreamId
	hb := []byte(p.HeaderBlockFragment)
	padding := []byte(p.Padding)
	dependencyTree := &DependencyTree{
		Exclusive:        p.Priority.Exclusive,
		StreamDependency: p.Priority.StreamDependency,
		Weight:           p.Priority.Weight,
	}

	// compare struct
	expected := NewHeadersFrame(flags, streamId, dependencyTree, hb, padding)
	actual, err := ReadFrame(hexToBuffer(wire))
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, actual, expected)

	// compare wire
	buf := bytes.NewBuffer(make([]byte, 0))
	expected.Write(buf)
	hexdump := strings.ToUpper(hex.EncodeToString(buf.Bytes()))
	assert.Equal(t, wire, hexdump)
}
開發者ID:mashuai,項目名稱:http2,代碼行數:56,代碼來源:frame_test.go

示例4: TestIndexedHeaderDecode

func TestIndexedHeaderDecode(t *testing.T) {
	// D.2.4.  Indexed Header Field
	var index uint32 = 2
	buf := []byte{0x82}

	sw := swrap.New(buf)
	decoded := DecodeHeader(&sw)
	frame, ok := decoded.(*IndexedHeader)
	assert.Equal(t, ok, true)
	assert.Equal(t, frame.Index, index)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:11,代碼來源:decoder_test.go

示例5: TestNewIndexedLiteral

func TestNewIndexedLiteral(t *testing.T) {
	var indexing Indexing = WITH
	var index uint32 = 10
	var value string = "var"
	var frame *IndexedLiteral = NewIndexedLiteral(indexing, index, value)

	assert.Equal(t, frame.Indexing, indexing)
	assert.Equal(t, frame.Index, index)
	assert.Equal(t, frame.ValueLength, uint32(len(value)))
	assert.Equal(t, frame.ValueString, value)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:11,代碼來源:type_test.go

示例6: TestNewStringLiteral

func TestNewStringLiteral(t *testing.T) {
	var indexing Indexing = WITH
	var name string = "foo"
	var value string = "var"
	var frame *StringLiteral = NewStringLiteral(indexing, name, value)

	assert.Equal(t, frame.Indexing, indexing)
	assert.Equal(t, frame.NameLength, uint32(len(name)))
	assert.Equal(t, frame.NameString, name)
	assert.Equal(t, frame.ValueLength, uint32(len(value)))
	assert.Equal(t, frame.ValueString, value)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:12,代碼來源:type_test.go

示例7: TestPushPromiseCase

// PUSH_PROMISE Frame
func TestPushPromiseCase(t *testing.T) {
	var c TestCase
	var p PushPromisePayload
	framecase := []byte(`{
    "error": null,
    "wire": "000018050800000009060000000B746869732069732064756D6D79486F77647921",
    "frame": {
      "length": 24,
      "frame_payload": {
        "header_block_fragment": "this is dummy",
        "padding_length": 6,
        "promised_stream_id": 11,
        "padding": "Howdy!"
      },
      "flags": 8,
      "stream_identifier": 9,
      "type": 5
    },
    "draft": 14,
    "description": "noraml push promise frame"
  }`)

	// ignore error
	json.Unmarshal(framecase, &c)
	json.Unmarshal(c.Frame.Payload, &p)

	// trace data
	wire := c.Wire
	flags := Flag(c.Frame.Flags)
	streamId := c.Frame.StreamId
	promisedStreamId := p.PromisedStreamID
	headerBlockFragment := []byte(p.HeaderBlockFragment)
	padding := []byte(p.Padding)

	// compare struct
	expected := NewPushPromiseFrame(flags, streamId, promisedStreamId, headerBlockFragment, padding)
	actual, err := ReadFrame(hexToBuffer(wire))
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, actual, expected)

	// compare wire
	buf := bytes.NewBuffer(make([]byte, 0))
	expected.Write(buf)
	hexdump := strings.ToUpper(hex.EncodeToString(buf.Bytes()))
	assert.Equal(t, wire, hexdump)
}
開發者ID:mashuai,項目名稱:http2,代碼行數:49,代碼來源:frame_test.go

示例8: TestDynamicTableSizeLen

func TestDynamicTableSizeLen(t *testing.T) {
	ht := DynamicTable{
		DEFAULT_HEADER_TABLE_SIZE,
		[]*HeaderField{
			NewHeaderField("1234", "1234"),
			NewHeaderField("1234", "1234"),
			NewHeaderField("1234", "1234"),
			NewHeaderField("1234", "1234"),
			NewHeaderField("1234", "1234"),
		},
	}

	var actual uint32 = 200
	assert.Equal(t, ht.Size(), actual)
	assert.Equal(t, ht.Len(), 5)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:16,代碼來源:dynamic_table_test.go

示例9: TestStringLiteralEncode

func TestStringLiteralEncode(t *testing.T) {
	// D.2.1.  Literal Header Field with Indexing
	var indexing Indexing = WITH
	var name, value string = "custom-key", "custom-header"
	buf := []byte{
		0x40, 0x0a,
		0x63, 0x75,
		0x73, 0x74,
		0x6f, 0x6d,
		0x2d, 0x6b,
		0x65, 0x79,
		0x0d, 0x63,
		0x75, 0x73,
		0x74, 0x6f,
		0x6d, 0x2d,
		0x68, 0x65,
		0x61, 0x64,
		0x65, 0x72,
	}

	frame := NewStringLiteral(indexing, name, value)
	actual := frame.Encode()

	assert.Equal(t, actual.Bytes(), buf)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:25,代碼來源:encoder_test.go

示例10: TestGoAwayCase

func TestGoAwayCase(t *testing.T) {
	var c TestCase
	var p GoAwayPayload
	framecase := []byte(`{
    "error": null,
    "wire": "0000170700000000000000001E00000009687061636B2069732062726F6B656E",
    "frame": {
      "length": 23,
      "frame_payload": {
        "error_code": 9,
        "additional_debug_data": "hpack is broken",
        "padding_length": null,
        "last_stream_id": 30,
        "padding": null
      },
      "flags": 0,
      "stream_identifier": 0,
      "type": 7
    },
    "draft": 14,
    "description": "normal goaway frame"
  }`)

	json.Unmarshal(framecase, &c)
	json.Unmarshal(c.Frame.Payload, &p)

	// trace data
	wire := c.Wire
	streamId := c.Frame.StreamId
	lastStreamId := p.LastStreamID
	errorCode := p.ErrorCode
	additional := []byte(p.AdditionalDebugData)

	// compare struct
	expected := NewGoAwayFrame(streamId, lastStreamId, errorCode, additional)
	actual, err := ReadFrame(hexToBuffer(wire))
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, actual, expected)

	// compare wire
	buf := bytes.NewBuffer(make([]byte, 0))
	expected.Write(buf)
	hexdump := strings.ToUpper(hex.EncodeToString(buf.Bytes()))
	assert.Equal(t, wire, hexdump)
}
開發者ID:mashuai,項目名稱:http2,代碼行數:47,代碼來源:frame_test.go

示例11: TestDataCase

func TestDataCase(t *testing.T) {
	var c TestCase
	var p DataPayload
	framecase := []byte(`{
    "error": null,
    "wire": "0000140008000000020648656C6C6F2C20776F726C6421486F77647921",
    "frame": {
      "length": 20,
      "frame_payload": {
        "data": "Hello, world!",
        "padding_length": 6,
        "padding": "Howdy!"
      },
      "flags": 8,
      "stream_identifier": 2,
      "type": 0
    },
    "draft": 14,
    "description": "noraml data frame"
  }`)

	// ignore error
	json.Unmarshal(framecase, &c)
	json.Unmarshal(c.Frame.Payload, &p)

	// trace data
	wire := c.Wire
	flags := Flag(c.Frame.Flags)
	streamId := c.Frame.StreamId
	data := []byte(p.Data)
	padding := []byte(p.Padding)

	// compare struct
	expected := NewDataFrame(flags, streamId, data, padding)
	actual, err := ReadFrame(hexToBuffer(wire))
	if err != nil {
		t.Fatal(err)
	}
	_ = actual
	assert.Equal(t, actual, expected)

	// compare wire
	buf := bytes.NewBuffer(make([]byte, 0))
	expected.Write(buf)
	hexdump := strings.ToUpper(hex.EncodeToString(buf.Bytes()))
	assert.Equal(t, wire, hexdump)
}
開發者ID:mashuai,項目名稱:http2,代碼行數:47,代碼來源:frame_test.go

示例12: TestNewIndexedHeader

func TestNewIndexedHeader(t *testing.T) {
	var index uint32 = 10
	var frame *IndexedHeader
	frame = NewIndexedHeader(index)

	actual, expected := frame.Index, index
	assert.Equal(t, actual, expected)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:8,代碼來源:type_test.go

示例13: TestHeadersCase

func TestHeadersCase(t *testing.T) {
	var c TestCase
	var p HeadersPayload
	framecase := []byte(`{
    "error": null,
    "wire": "00000D010000000001746869732069732064756D6D79",
    "frame": {
      "length": 13,
      "frame_payload": {
        "priority": null,
        "header_block_fragment": "this is dummy",
        "padding_length": null,
        "padding": null
      },
      "flags": 0,
      "stream_identifier": 1,
      "type": 1
    },
    "draft": 14,
    "description": "noraml headers frame"
  }`)

	// ignore error
	json.Unmarshal(framecase, &c)
	json.Unmarshal(c.Frame.Payload, &p)

	// trace data
	wire := c.Wire
	flags := Flag(c.Frame.Flags)
	streamId := c.Frame.StreamId
	headerBlockFragment := []byte(p.HeaderBlockFragment)

	// compare struct
	expected := NewHeadersFrame(flags, streamId, nil, headerBlockFragment, nil)
	actual, err := ReadFrame(hexToBuffer(wire))
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, actual, expected)

	// compare wire
	buf := bytes.NewBuffer(make([]byte, 0))
	expected.Write(buf)
	hexdump := strings.ToUpper(hex.EncodeToString(buf.Bytes()))
	assert.Equal(t, wire, hexdump)
}
開發者ID:mashuai,項目名稱:http2,代碼行數:46,代碼來源:frame_test.go

示例14: TestDecode

func TestDecode(t *testing.T) {
	for _, tc := range testCase {
		expected := tc.str
		code := toHexBytes(tc.hex)
		actual := string(Decode(code))
		assert.Equal(t, actual, expected)
	}
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:8,代碼來源:huffman_test.go

示例15: TestEmit

func TestEmit(t *testing.T) {
	hl := NewHeaderList()
	hf1 := NewHeaderField("key1", "value1")
	hf2 := NewHeaderField("key2", "value2")
	hl.Emit(hf1)
	hl.Emit(hf2)
	assert.Equal(t, hl.Len(), 2)
}
開發者ID:Jxck,項目名稱:hpack,代碼行數:8,代碼來源:header_list_test.go


注:本文中的github.com/Jxck/assertion.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。