Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
add newCtxRepo test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed May 24, 2017
1 parent 7854ebf commit 616dc66
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
Empty file.
6 changes: 6 additions & 0 deletions internal/gps/_testdata/src/corrupt/git/info/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Empty file.
Empty file.
Empty file.
Empty file.
46 changes: 45 additions & 1 deletion internal/gps/vcs_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"

"github.com/Masterminds/vcs"
"github.com/golang/dep/internal/gps/internal/fs"
)

// original implementation of these test files come from
// https://github.com/Masterminds/vcs test files

const gitRemoteTestRepo = "https://github.com/Masterminds/VCSTestRepo"

func TestErrs(t *testing.T) {
err := newVcsLocalErrorOr("", context.Canceled, "")
if err != context.Canceled {
Expand Down Expand Up @@ -46,6 +50,46 @@ func TestErrs(t *testing.T) {
}
}

func TestNewCtxRepo(t *testing.T) {
t.Parallel()

tempDir, err := ioutil.TempDir("", "go-ctx-repo-test")
if err != nil {
t.Fatal(err)
}
defer func() {
err = os.RemoveAll(tempDir)
if err != nil {
t.Error(err)
}
}()
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}

src := filepath.Join(cwd, "_testdata", "src", "corrupt", "git")
dest := filepath.Join(tempDir, ".git")
err = fs.CopyDir(src, dest)
if err != nil {
t.Fatal(err)
}

_, err = getVCSRepo(vcs.Git, gitRemoteTestRepo, tempDir)
if err != nil {
if _, ok := err.(*vcs.LocalError); !ok {
t.Fatalf("expected a local error but got: %v\n", err)
}
} else {
t.Fatal("expected getVCSRepo to fail when pointing to a corrupt local path. It is possible that vcs.GitNewRepo updated to gracefully handle this test scenario. Check the return of vcs.GitNewRepo.")
}

_, err = newCtxRepo(vcs.Git, gitRemoteTestRepo, tempDir)
if err != nil {
t.Fatal(err)
}
}

func testSvnRepo(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -219,7 +263,7 @@ func testGitRepo(t *testing.T) {
}
}()

rep, err := vcs.NewGitRepo("https://github.com/Masterminds/VCSTestRepo", tempDir+"/VCSTestRepo")
rep, err := vcs.NewGitRepo(gitRemoteTestRepo, tempDir+"/VCSTestRepo")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 616dc66

Please sign in to comment.