| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package main |
| 6 |
| 7 import ( |
| 8 "net/url" |
| 9 "testing" |
| 10 |
| 11 . "github.com/luci/luci-go/common/testing/assertions" |
| 12 . "github.com/smartystreets/goconvey/convey" |
| 13 ) |
| 14 |
| 15 func TestMain(t *testing.T) { |
| 16 t.Parallel() |
| 17 |
| 18 Convey("parseServer", t, func() { |
| 19 test := func(host string, expectedErr interface{}, expectedURL *
url.URL) { |
| 20 Convey(host, func() { |
| 21 u, err := parseServer(host) |
| 22 So(err, ShouldErrLike, expectedErr) |
| 23 So(u, ShouldResembleV, expectedURL) |
| 24 }) |
| 25 } |
| 26 |
| 27 test("", "unspecified", nil) |
| 28 |
| 29 // Localhost is http, everything else is https. |
| 30 test("localhost", nil, &url.URL{ |
| 31 Scheme: "http", |
| 32 Host: "localhost", |
| 33 }) |
| 34 test("localhost:8080", nil, &url.URL{ |
| 35 Scheme: "http", |
| 36 Host: "localhost:8080", |
| 37 }) |
| 38 test("127.0.0.1", nil, &url.URL{ |
| 39 Scheme: "http", |
| 40 Host: "127.0.0.1", |
| 41 }) |
| 42 test("127.0.0.1:8080", nil, &url.URL{ |
| 43 Scheme: "http", |
| 44 Host: "127.0.0.1:8080", |
| 45 }) |
| 46 test("example.com", nil, &url.URL{ |
| 47 Scheme: "https", |
| 48 Host: "example.com", |
| 49 }) |
| 50 test("example.com:8080", nil, &url.URL{ |
| 51 Scheme: "https", |
| 52 Host: "example.com:8080", |
| 53 }) |
| 54 |
| 55 // Short syntax for localhost. |
| 56 test(":", nil, &url.URL{ |
| 57 Scheme: "http", |
| 58 Host: "localhost:", |
| 59 }) |
| 60 test(":8080", nil, &url.URL{ |
| 61 Scheme: "http", |
| 62 Host: "localhost:8080", |
| 63 }) |
| 64 |
| 65 // No explicit scheme. |
| 66 test("http://example.com", "must not have scheme", nil) |
| 67 test("https://example.com", "must not have scheme", nil) |
| 68 test("ftp://example.com", "must not have scheme", nil) |
| 69 |
| 70 // Extra URL components. |
| 71 test("example.com/a", "must not have query, path or fragment", n
il) |
| 72 test("example.com?a", "must not have query, path or fragment", n
il) |
| 73 test("example.com#a", "must not have query, path or fragment", n
il) |
| 74 }) |
| 75 } |
| OLD | NEW |