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