blob: faa51d45f320f9c05537ab6991fe67c55bfcb1fe [file] [log] [blame]
Gary Burd5401ad22013-09-04 09:01:31 -07001// 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
7package gosrc
8
9import (
10 "testing"
11)
12
13var 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 Burd465d52d2015-01-20 08:27:03 -080022 "github.com/user/repo/_ok/x",
Dmitri Shuralyove33e2182015-12-28 22:02:59 -080023 "exampleproject.com",
Dmitri Shuralyovcdd60fa2017-04-25 15:23:47 -040024 "exampleproject.com/unicode/испытание",
Gary Burd5401ad22013-09-04 09:01:31 -070025}
26
27var badImportPaths = []string{
28 "foobar",
29 "foo.",
30 ".bar",
31 "favicon.ico",
Gary Burd5401ad22013-09-04 09:01:31 -070032 "github.com/user/repo/.ignore/x",
33}
34
35func TestIsValidRemotePath(t *testing.T) {
36 for _, importPath := range goodImportPaths {
37 if !IsValidRemotePath(importPath) {
38 t.Errorf("isBadImportPath(%q) -> true, want false", importPath)
39 }
Mihai Boroboceab853db42015-10-20 06:06:56 +030040
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 Burd5401ad22013-09-04 09:01:31 -070047 }
Mihai Boroboceab853db42015-10-20 06:06:56 +030048
Gary Burd5401ad22013-09-04 09:01:31 -070049 for _, importPath := range badImportPaths {
50 if IsValidRemotePath(importPath) {
51 t.Errorf("isBadImportPath(%q) -> false, want true", importPath)
52 }
53 }
54}