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