OSDN Git Service

new repo
[bytom/vapor.git] / vendor / google.golang.org / grpc / resolver_conn_wrapper_test.go
1 /*
2  *
3  * Copyright 2017 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 grpc
20
21 import (
22         "testing"
23
24         "google.golang.org/grpc/resolver"
25 )
26
27 func TestParseTarget(t *testing.T) {
28         for _, test := range []resolver.Target{
29                 {"", "", ""},
30                 {"a", "", ""},
31                 {"", "a", ""},
32                 {"", "", "a"},
33                 {"a", "b", ""},
34                 {"a", "", "b"},
35                 {"", "a", "b"},
36                 {"a", "b", "c"},
37                 {"dns", "", "google.com"},
38                 {"dns", "a.server.com", "google.com"},
39                 {"dns", "a.server.com", "google.com/?a=b"},
40                 {"", "", "/unix/socket/address"},
41         } {
42                 str := test.Scheme + "://" + test.Authority + "/" + test.Endpoint
43                 got := parseTarget(str)
44                 if got != test {
45                         t.Errorf("parseTarget(%q) = %+v, want %+v", str, got, test)
46                 }
47         }
48 }
49
50 func TestParseTargetString(t *testing.T) {
51         for _, test := range []struct {
52                 targetStr string
53                 want      resolver.Target
54         }{
55                 {"", resolver.Target{"", "", ""}},
56                 {"://", resolver.Target{"", "", ""}},
57                 {":///", resolver.Target{"", "", ""}},
58                 {"a:///", resolver.Target{"a", "", ""}},
59                 {"://a/", resolver.Target{"", "a", ""}},
60                 {":///a", resolver.Target{"", "", "a"}},
61                 {"a://b/", resolver.Target{"a", "b", ""}},
62                 {"a:///b", resolver.Target{"a", "", "b"}},
63                 {"://a/b", resolver.Target{"", "a", "b"}},
64                 {"a://b/c", resolver.Target{"a", "b", "c"}},
65                 {"dns:///google.com", resolver.Target{"dns", "", "google.com"}},
66                 {"dns://a.server.com/google.com", resolver.Target{"dns", "a.server.com", "google.com"}},
67                 {"dns://a.server.com/google.com/?a=b", resolver.Target{"dns", "a.server.com", "google.com/?a=b"}},
68
69                 {"/", resolver.Target{"", "", "/"}},
70                 {"google.com", resolver.Target{"", "", "google.com"}},
71                 {"google.com/?a=b", resolver.Target{"", "", "google.com/?a=b"}},
72                 {"/unix/socket/address", resolver.Target{"", "", "/unix/socket/address"}},
73         } {
74                 got := parseTarget(test.targetStr)
75                 if got != test.want {
76                         t.Errorf("parseTarget(%q) = %+v, want %+v", test.targetStr, got, test.want)
77                 }
78         }
79 }