3 * Copyright 2014 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 func TestPairsMD(t *testing.T) {
27 for _, test := range []struct {
34 {[]string{"k1", "v1", "k1", "v2"}, MD{"k1": []string{"v1", "v2"}}},
36 md := Pairs(test.kv...)
37 if !reflect.DeepEqual(md, test.md) {
38 t.Fatalf("Pairs(%v) = %v, want %v", test.kv, md, test.md)
43 func TestCopy(t *testing.T) {
44 const key, val = "key", "val"
45 orig := Pairs(key, val)
47 if !reflect.DeepEqual(orig, copy) {
48 t.Errorf("copied value not equal to the original, got %v, want %v", copy, orig)
51 if v := copy[key][0]; v != val {
52 t.Errorf("change in original should not affect copy, got %q, want %q", v, val)
56 func TestJoin(t *testing.T) {
57 for _, test := range []struct {
62 {[]MD{Pairs("foo", "bar")}, Pairs("foo", "bar")},
63 {[]MD{Pairs("foo", "bar"), Pairs("foo", "baz")}, Pairs("foo", "bar", "foo", "baz")},
64 {[]MD{Pairs("foo", "bar"), Pairs("foo", "baz"), Pairs("zip", "zap")}, Pairs("foo", "bar", "foo", "baz", "zip", "zap")},
66 md := Join(test.mds...)
67 if !reflect.DeepEqual(md, test.want) {
68 t.Errorf("context's metadata is %v, want %v", md, test.want)