Chromium Code Reviews| Index: client/cmd/rpc/main_test.go |
| diff --git a/client/cmd/rpc/main_test.go b/client/cmd/rpc/main_test.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e5163f13a725e1659f7156da6f5e9bc18b7234cf |
| --- /dev/null |
| +++ b/client/cmd/rpc/main_test.go |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package main |
| + |
| +import ( |
| + "net/url" |
| + "testing" |
| + |
| + . "github.com/luci/luci-go/common/testing/assertions" |
| + . "github.com/smartystreets/goconvey/convey" |
| +) |
| + |
| +func TestMain(t *testing.T) { |
| + t.Parallel() |
| + |
| + Convey("parseServer", t, func() { |
| + test := func(host string, expectedErr interface{}, expectedURL *url.URL) { |
| + Convey(host, func() { |
| + u, err := parseServer(host) |
| + So(err, ShouldErrLike, expectedErr) |
| + So(u, ShouldResembleV, expectedURL) |
| + }) |
| + } |
| + |
| + test("", "unspecified", nil) |
| + |
| + // Localhost is http, everything else is https. |
| + test("localhost", nil, &url.URL{ |
| + Scheme: "http", |
| + Host: "localhost", |
| + }) |
| + test("localhost:8080", nil, &url.URL{ |
| + Scheme: "http", |
| + Host: "localhost:8080", |
| + }) |
| + test("127.0.0.1", nil, &url.URL{ |
| + Scheme: "http", |
| + Host: "127.0.0.1", |
| + }) |
| + test("127.0.0.1:8080", nil, &url.URL{ |
| + Scheme: "http", |
| + Host: "127.0.0.1:8080", |
| + }) |
| + test("example.com", nil, &url.URL{ |
| + Scheme: "https", |
| + Host: "example.com", |
| + }) |
| + |
| + // Short syntax for localhost. |
| + test(":", nil, &url.URL{ |
| + Scheme: "http", |
| + Host: "localhost:", |
| + }) |
| + test(":8080", nil, &url.URL{ |
| + Scheme: "http", |
| + Host: "localhost:8080", |
| + }) |
|
iannucci
2016/01/15 23:20:09
can we add a test for "example.com:8080" too?
nodir
2016/01/15 23:47:25
Done.
|
| + |
| + // No explicit scheme. |
| + test("http://example.com", "must not have scheme", nil) |
| + test("https://example.com", "must not have scheme", nil) |
| + test("ftp://example.com", "must not have scheme", nil) |
| + |
| + // Extra URL components. |
| + test("example.com/a", "must not have query, path or fragment", nil) |
| + test("example.com?a", "must not have query, path or fragment", nil) |
| + test("example.com#a", "must not have query, path or fragment", nil) |
| + }) |
| +} |