3 * Copyright 2017 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.
24 "google.golang.org/grpc/resolver"
27 func TestParseTarget(t *testing.T) {
28 for _, test := range []resolver.Target{
37 {"dns", "", "google.com"},
38 {"dns", "a.server.com", "google.com"},
39 {"dns", "a.server.com", "google.com/?a=b"},
40 {"", "", "/unix/socket/address"},
42 str := test.Scheme + "://" + test.Authority + "/" + test.Endpoint
43 got := parseTarget(str)
45 t.Errorf("parseTarget(%q) = %+v, want %+v", str, got, test)
50 func TestParseTargetString(t *testing.T) {
51 for _, test := range []struct {
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"}},
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"}},
74 got := parseTarget(test.targetStr)
76 t.Errorf("parseTarget(%q) = %+v, want %+v", test.targetStr, got, test.want)