github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/cmd/go/vcs_test.go (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"runtime"
     9  	"testing"
    10  )
    11  
    12  // Test that RepoRootForImportPath creates the correct RepoRoot for a given importPath.
    13  // TODO(cmang): Add tests for SVN and BZR.
    14  func TestRepoRootForImportPath(t *testing.T) {
    15  	if testing.Short() {
    16  		t.Skip("skipping test to avoid external network")
    17  	}
    18  	switch runtime.GOOS {
    19  	case "nacl", "android":
    20  		t.Skipf("no networking available on %s", runtime.GOOS)
    21  	}
    22  	tests := []struct {
    23  		path string
    24  		want *repoRoot
    25  	}{
    26  		{
    27  			"code.google.com/p/go",
    28  			&repoRoot{
    29  				vcs:  vcsHg,
    30  				repo: "https://code.google.com/p/go",
    31  			},
    32  		},
    33  		/*{
    34  		        "code.google.com/r/go",
    35  		        &repoRoot{
    36  		                vcs:  vcsHg,
    37  		                repo: "https://code.google.com/r/go",
    38  		        },
    39  		},*/
    40  		{
    41  			"github.com/golang/groupcache",
    42  			&repoRoot{
    43  				vcs:  vcsGit,
    44  				repo: "https://github.com/golang/groupcache",
    45  			},
    46  		},
    47  		// IBM DevOps Services tests
    48  		{
    49  			"hub.jazz.net/git/user1/pkgname",
    50  			&repoRoot{
    51  				vcs:  vcsGit,
    52  				repo: "https://hub.jazz.net/git/user1/pkgname",
    53  			},
    54  		},
    55  		{
    56  			"hub.jazz.net/git/user1/pkgname/submodule/submodule/submodule",
    57  			&repoRoot{
    58  				vcs:  vcsGit,
    59  				repo: "https://hub.jazz.net/git/user1/pkgname",
    60  			},
    61  		},
    62  		{
    63  			"hub.jazz.net",
    64  			nil,
    65  		},
    66  		{
    67  			"hub2.jazz.net",
    68  			nil,
    69  		},
    70  		{
    71  			"hub.jazz.net/someotherprefix",
    72  			nil,
    73  		},
    74  		{
    75  			"hub.jazz.net/someotherprefix/user1/pkgname",
    76  			nil,
    77  		},
    78  		// Spaces are not valid in user names or package names
    79  		{
    80  			"hub.jazz.net/git/User 1/pkgname",
    81  			nil,
    82  		},
    83  		{
    84  			"hub.jazz.net/git/user1/pkg name",
    85  			nil,
    86  		},
    87  		// Dots are not valid in user names
    88  		{
    89  			"hub.jazz.net/git/user.1/pkgname",
    90  			nil,
    91  		},
    92  		{
    93  			"hub.jazz.net/git/user/pkg.name",
    94  			&repoRoot{
    95  				vcs:  vcsGit,
    96  				repo: "https://hub.jazz.net/git/user/pkg.name",
    97  			},
    98  		},
    99  		// User names cannot have uppercase letters
   100  		{
   101  			"hub.jazz.net/git/USER/pkgname",
   102  			nil,
   103  		},
   104  	}
   105  
   106  	for _, test := range tests {
   107  		got, err := repoRootForImportPath(test.path)
   108  		want := test.want
   109  
   110  		if want == nil {
   111  			if err == nil {
   112  				t.Errorf("RepoRootForImport(%q): Error expected but not received", test.path)
   113  			}
   114  			continue
   115  		}
   116  		if err != nil {
   117  			t.Errorf("RepoRootForImport(%q): %v", test.path, err)
   118  			continue
   119  		}
   120  		if got.vcs.name != want.vcs.name || got.repo != want.repo {
   121  			t.Errorf("RepoRootForImport(%q) = VCS(%s) Repo(%s), want VCS(%s) Repo(%s)", test.path, got.vcs, got.repo, want.vcs, want.repo)
   122  		}
   123  	}
   124  }