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

Commit

Permalink
add happy path test + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan-at-work committed May 25, 2017
1 parent ff64da3 commit a0db261
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions internal/gps/_testdata/badrepo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Test Data

This directory contains artifacts that represent malformed repo archives. Its purpose is to ensure `dep` can recover from such corrupted repositories in specific test scenarios.

- `corrupt_dot_git_directory.tar`: is a repo with a corrupt `.git` directory. Dep can put a directory in such malformed state when a user hits `Ctrl+C` in the middle of a `dep init` process or others. `TestNewCtxRepoRecovery` uses this file to ensure recovery.
2 changes: 1 addition & 1 deletion internal/gps/vcs_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func newCtxRepo(s vcs.Type, ustr, path string) (r ctxRepo, err error) {
// then the local repo is in an incorrect state. Remove and
// treat it as a new not-yet-cloned repo.

// TODO(marwan-at-work): pass a logger here to warn/give progress of the above comment.
// TODO(marwan-at-work): warn/give progress of the above comment.
os.RemoveAll(path)
r, err = getVCSRepo(s, ustr, path)
}
Expand Down
26 changes: 23 additions & 3 deletions internal/gps/vcs_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,30 @@ func TestErrs(t *testing.T) {
}
}

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

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

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

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

tempDir, err := ioutil.TempDir("", "go-ctx-repo-recovery-test")
if err != nil {
t.Fatal(err)
}
Expand All @@ -71,7 +91,7 @@ func TestNewCtxRepo(t *testing.T) {
t.Fatal(err)
}

src := filepath.Join(cwd, "_testdata", "src", "corrupt", "corrupt_dot_git_directory.tar")
src := filepath.Join(cwd, "_testdata", "badrepo", "corrupt_dot_git_directory.tar")
f, err := os.Open(src)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit a0db261

Please sign in to comment.