github.com/confluentinc/confluent-kafka-go@v1.9.2/kafka/header_test.go (about)

     1  /**
     2   * Copyright 2016 Confluent Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   * http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package kafka
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  // TestHeader tests the Header type
    24  func TestHeader(t *testing.T) {
    25  
    26  	hdr := Header{"MyHdr1", []byte("a string")}
    27  	if hdr.String() != "MyHdr1=\"a string\"" {
    28  		t.Errorf("Unexpected: %s", hdr.String())
    29  	}
    30  
    31  	hdr = Header{"MyHdr2", []byte("a longer string that will be truncated right here <-- so you wont see this part.")}
    32  	if hdr.String() != "MyHdr2=\"a longer string that will be truncated right here \"(30 more bytes)" {
    33  		t.Errorf("Unexpected: %s", hdr.String())
    34  	}
    35  
    36  	hdr = Header{"MyHdr3", []byte{1, 2, 3, 4}}
    37  	if hdr.String() != "MyHdr3=\"\\x01\\x02\\x03\\x04\"" {
    38  		t.Errorf("Unexpected: %s", hdr.String())
    39  	}
    40  
    41  }