| 1 |
package otbuiltin |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"testing" |
| 6 |
//"strconv" |
| 7 |
"fmt" |
| 8 |
"io/ioutil" |
| 9 |
"path" |
| 10 |
|
| 11 |
"github.com/14rcole/gopopulate" |
| 12 |
) |
| 13 |
|
| 14 |
func TestPruneNoPrunePass(t *testing.T) { |
| 15 |
// Make a base directory in which all of our test data resides |
| 16 |
baseDir, err := ioutil.TempDir("", "otbuiltin-test-") |
| 17 |
if err != nil { |
| 18 |
t.Errorf("%s", err) |
| 19 |
return |
| 20 |
} |
| 21 |
defer os.RemoveAll(baseDir) |
| 22 |
// Make a directory in which the repo should exist |
| 23 |
repoDir := path.Join(baseDir, "repo") |
| 24 |
err = os.Mkdir(repoDir, 0777) |
| 25 |
if err != nil { |
| 26 |
t.Errorf("%s", err) |
| 27 |
return |
| 28 |
} |
| 29 |
|
| 30 |
// Initialize the repo |
| 31 |
inited, err := Init(repoDir, NewInitOptions()) |
| 32 |
if !inited || err != nil { |
| 33 |
fmt.Println("Cannot test commit: failed to initialize repo") |
| 34 |
return |
| 35 |
} |
| 36 |
|
| 37 |
//Make a new directory full of random data to commit |
| 38 |
commitDir := path.Join(baseDir, "commit1") |
| 39 |
err = os.Mkdir(commitDir, 0777) |
| 40 |
if err != nil { |
| 41 |
t.Errorf("%s", err) |
| 42 |
return |
| 43 |
} |
| 44 |
err = gopopulate.PopulateDir(commitDir, "rd", 4, 4) |
| 45 |
if err != nil { |
| 46 |
t.Errorf("%s", err) |
| 47 |
return |
| 48 |
} |
| 49 |
|
| 50 |
//Test commit |
| 51 |
repo, err := OpenRepo(repoDir) |
| 52 |
if err != nil { |
| 53 |
t.Errorf("%s", err) |
| 54 |
} |
| 55 |
|
| 56 |
opts := NewCommitOptions() |
| 57 |
branch := "test-branch" |
| 58 |
_, err = repo.PrepareTransaction() |
| 59 |
if err != nil { |
| 60 |
t.Errorf("%s", err) |
| 61 |
} |
| 62 |
|
| 63 |
ret, err := repo.Commit(commitDir, branch, opts) |
| 64 |
if err != nil { |
| 65 |
t.Errorf("%s", err) |
| 66 |
} else { |
| 67 |
fmt.Println(ret) |
| 68 |
} |
| 69 |
|
| 70 |
_, err = repo.CommitTransaction() |
| 71 |
if err != nil { |
| 72 |
t.Errorf("%s", err) |
| 73 |
} |
| 74 |
|
| 75 |
// Now let's do some pruning! |
| 76 |
pruneOpts := NewPruneOptions() |
| 77 |
pruneOpts.NoPrune = true |
| 78 |
ret, err = Prune(repoDir, pruneOpts) |
| 79 |
if err != nil { |
| 80 |
t.Errorf("%s", err) |
| 81 |
} else { |
| 82 |
fmt.Println(ret) |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
func TestPruneNoPruneFail(t *testing.T) { |
| 87 |
} |
| 88 |
|
| 89 |
func TestPrunePass(t *testing.T) { |
| 90 |
} |
| 91 |
|
| 92 |
func TestPruneFail(t *testing.T) { |
| 93 |
} |