1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
package eventstream
import (
"reflect"
"testing"
"time"
)
func TestHeaders_Set(t *testing.T) {
expect := Headers{
{Name: "ABC", Value: StringValue("123")},
{Name: "EFG", Value: TimestampValue(time.Time{})},
}
var actual Headers
actual.Set("ABC", Int32Value(123))
actual.Set("ABC", StringValue("123")) // replace case
actual.Set("EFG", TimestampValue(time.Time{}))
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v headers, got %v", e, a)
}
}
func TestHeaders_Get(t *testing.T) {
headers := Headers{
{Name: "ABC", Value: StringValue("123")},
{Name: "EFG", Value: TimestampValue(time.Time{})},
}
cases := []struct {
Name string
Value Value
}{
{Name: "ABC", Value: StringValue("123")},
{Name: "EFG", Value: TimestampValue(time.Time{})},
{Name: "NotFound"},
}
for i, c := range cases {
actual := headers.Get(c.Name)
if e, a := c.Value, actual; !reflect.DeepEqual(e, a) {
t.Errorf("%d, expect %v value, got %v", i, e, a)
}
}
}
func TestHeaders_Del(t *testing.T) {
headers := Headers{
{Name: "ABC", Value: StringValue("123")},
{Name: "EFG", Value: TimestampValue(time.Time{})},
{Name: "HIJ", Value: StringValue("123")},
{Name: "KML", Value: TimestampValue(time.Time{})},
}
expectAfterDel := Headers{
{Name: "EFG", Value: TimestampValue(time.Time{})},
}
headers.Del("HIJ")
headers.Del("ABC")
headers.Del("KML")
if e, a := expectAfterDel, headers; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v headers, got %v", e, a)
}
}
|