github.com/golang/dep@v0.5.4/gps/vcs_version_test.go (about)

     1  // Copyright 2017 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 gps
     6  
     7  import (
     8  	"path/filepath"
     9  	"testing"
    10  
    11  	"github.com/golang/dep/internal/test"
    12  )
    13  
    14  func TestVCSVersion(t *testing.T) {
    15  	if testing.Short() {
    16  		t.Skip("Skipping slow test in short mode")
    17  	}
    18  
    19  	h := test.NewHelper(t)
    20  	defer h.Cleanup()
    21  	requiresBins(t, "git")
    22  
    23  	h.TempDir("src")
    24  	gopath := h.Path(".")
    25  	h.Setenv("GOPATH", gopath)
    26  
    27  	importPaths := map[string]struct {
    28  		rev      Version
    29  		checkout bool
    30  	}{
    31  		"github.com/pkg/errors": {
    32  			rev:      NewVersion("v0.8.0").Pair("645ef00459ed84a119197bfb8d8205042c6df63d"), // semver
    33  			checkout: true,
    34  		},
    35  		"github.com/sirupsen/logrus": {
    36  			rev:      Revision("42b84f9ec624953ecbf81a94feccb3f5935c5edf"), // random sha
    37  			checkout: true,
    38  		},
    39  		"github.com/rsc/go-get-default-branch": {
    40  			rev: NewBranch("another-branch").Pair("8e6902fdd0361e8fa30226b350e62973e3625ed5"),
    41  		},
    42  	}
    43  
    44  	// checkout the specified revisions
    45  	for ip, info := range importPaths {
    46  		h.RunGo("get", ip)
    47  		repoDir := h.Path("src/" + ip)
    48  		if info.checkout {
    49  			h.RunGit(repoDir, "checkout", info.rev.String())
    50  		}
    51  		abs := filepath.FromSlash(filepath.Join(gopath, "src", ip))
    52  		got, err := VCSVersion(abs)
    53  		h.Must(err)
    54  
    55  		if got != info.rev {
    56  			t.Fatalf("expected %q, got %q", got.String(), info.rev.String())
    57  		}
    58  	}
    59  }