Chromium Code Reviews| 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 | |
| 51 // Short syntax for localhost. | |
| 52 test(":", nil, &url.URL{ | |
| 53 Scheme: "http", | |
| 54 Host: "localhost:", | |
| 55 }) | |
| 56 test(":8080", nil, &url.URL{ | |
| 57 Scheme: "http", | |
| 58 Host: "localhost:8080", | |
| 59 }) | |
|
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.
| |
| 60 | |
| 61 // No explicit scheme. | |
| 62 test("http://example.com", "must not have scheme", nil) | |
| 63 test("https://example.com", "must not have scheme", nil) | |
| 64 test("ftp://example.com", "must not have scheme", nil) | |
| 65 | |
| 66 // Extra URL components. | |
| 67 test("example.com/a", "must not have query, path or fragment", n il) | |
| 68 test("example.com?a", "must not have query, path or fragment", n il) | |
| 69 test("example.com#a", "must not have query, path or fragment", n il) | |
| 70 }) | |
| 71 } | |
| OLD | NEW |