Gary Burd | 5401ad2 | 2013-09-04 09:01:31 -0700 | [diff] [blame] | 1 | // Copyright 2013 The Go Authors. All rights reserved. |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style |
| 4 | // license that can be found in the LICENSE file or at |
| 5 | // https://developers.google.com/open-source/licenses/bsd. |
| 6 | |
| 7 | package gosrc |
| 8 | |
| 9 | import ( |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | var goodImportPaths = []string{ |
| 14 | "github.com/user/repo", |
| 15 | "github.com/user/repo/src/pkg/compress/somethingelse", |
| 16 | "github.com/user/repo/src/compress/gzip", |
| 17 | "github.com/user/repo/src/pkg", |
| 18 | "camlistore.org/r/p/camlistore", |
| 19 | "example.com/foo.git", |
| 20 | "launchpad.net/~user/foo/trunk", |
| 21 | "launchpad.net/~user/+junk/version", |
Gary Burd | 465d52d | 2015-01-20 08:27:03 -0800 | [diff] [blame] | 22 | "github.com/user/repo/_ok/x", |
Dmitri Shuralyov | e33e218 | 2015-12-28 22:02:59 -0800 | [diff] [blame] | 23 | "exampleproject.com", |
Dmitri Shuralyov | cdd60fa | 2017-04-25 15:23:47 -0400 | [diff] [blame] | 24 | "exampleproject.com/unicode/испытание", |
Gary Burd | 5401ad2 | 2013-09-04 09:01:31 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | var badImportPaths = []string{ |
| 28 | "foobar", |
| 29 | "foo.", |
| 30 | ".bar", |
| 31 | "favicon.ico", |
Gary Burd | 5401ad2 | 2013-09-04 09:01:31 -0700 | [diff] [blame] | 32 | "github.com/user/repo/.ignore/x", |
| 33 | } |
| 34 | |
| 35 | func TestIsValidRemotePath(t *testing.T) { |
| 36 | for _, importPath := range goodImportPaths { |
| 37 | if !IsValidRemotePath(importPath) { |
| 38 | t.Errorf("isBadImportPath(%q) -> true, want false", importPath) |
| 39 | } |
Mihai Borobocea | b853db4 | 2015-10-20 06:06:56 +0300 | [diff] [blame] | 40 | |
| 41 | for _, s := range services { |
| 42 | if _, err := s.match(importPath); err != nil { |
| 43 | t.Errorf("match(%#v) → error %v", importPath, err) |
| 44 | break |
| 45 | } |
| 46 | } |
Gary Burd | 5401ad2 | 2013-09-04 09:01:31 -0700 | [diff] [blame] | 47 | } |
Mihai Borobocea | b853db4 | 2015-10-20 06:06:56 +0300 | [diff] [blame] | 48 | |
Gary Burd | 5401ad2 | 2013-09-04 09:01:31 -0700 | [diff] [blame] | 49 | for _, importPath := range badImportPaths { |
| 50 | if IsValidRemotePath(importPath) { |
| 51 | t.Errorf("isBadImportPath(%q) -> false, want true", importPath) |
| 52 | } |
| 53 | } |
| 54 | } |