OSDN Git Service

new repo
[bytom/vapor.git] / vendor / google.golang.org / grpc / metadata / metadata_test.go
1 /*
2  *
3  * Copyright 2014 gRPC authors.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 package metadata
20
21 import (
22         "reflect"
23         "testing"
24 )
25
26 func TestPairsMD(t *testing.T) {
27         for _, test := range []struct {
28                 // input
29                 kv []string
30                 // output
31                 md MD
32         }{
33                 {[]string{}, MD{}},
34                 {[]string{"k1", "v1", "k1", "v2"}, MD{"k1": []string{"v1", "v2"}}},
35         } {
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)
39                 }
40         }
41 }
42
43 func TestCopy(t *testing.T) {
44         const key, val = "key", "val"
45         orig := Pairs(key, val)
46         copy := orig.Copy()
47         if !reflect.DeepEqual(orig, copy) {
48                 t.Errorf("copied value not equal to the original, got %v, want %v", copy, orig)
49         }
50         orig[key][0] = "foo"
51         if v := copy[key][0]; v != val {
52                 t.Errorf("change in original should not affect copy, got %q, want %q", v, val)
53         }
54 }
55
56 func TestJoin(t *testing.T) {
57         for _, test := range []struct {
58                 mds  []MD
59                 want MD
60         }{
61                 {[]MD{}, MD{}},
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")},
65         } {
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)
69                 }
70         }
71 }