| 1 |
package otbuiltin |
| 2 |
|
| 3 |
import ( |
| 4 |
"io/ioutil" |
| 5 |
"os" |
| 6 |
"path" |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/14rcole/gopopulate" |
| 10 |
) |
| 11 |
|
| 12 |
func TestLogSuccess(t *testing.T) { |
| 13 |
// Make a base directory in which all of our test data resides |
| 14 |
baseDir, err := ioutil.TempDir("", "otbuiltin-test-") |
| 15 |
if err != nil { |
| 16 |
t.Fatalf("%s", err) |
| 17 |
} |
| 18 |
defer os.RemoveAll(baseDir) |
| 19 |
|
| 20 |
// Make a directory in which the repo should exist |
| 21 |
repoDir := path.Join(baseDir, "repo") |
| 22 |
if err := os.Mkdir(repoDir, 0777); err != nil { |
| 23 |
t.Fatalf("%s", err) |
| 24 |
} |
| 25 |
|
| 26 |
// Initialize the repo |
| 27 |
inited, err := Init(repoDir, NewInitOptions()) |
| 28 |
if !inited || err != nil { |
| 29 |
t.Fatal("Cannot test commit: failed to initialize repo") |
| 30 |
} |
| 31 |
|
| 32 |
// Make a new directory full of random data to commit |
| 33 |
commitDir := path.Join(baseDir, "commit1") |
| 34 |
if err := os.Mkdir(commitDir, 0777); err != nil { |
| 35 |
t.Fatalf("%s", err) |
| 36 |
} |
| 37 |
if err := gopopulate.PopulateDir(commitDir, "rd", 4, 4); err != nil { |
| 38 |
t.Fatalf("%s", err) |
| 39 |
} |
| 40 |
|
| 41 |
// Test commit |
| 42 |
repo, err := OpenRepo(repoDir) |
| 43 |
if err != nil { |
| 44 |
t.Fatalf("%s", err) |
| 45 |
} |
| 46 |
|
| 47 |
opts := NewCommitOptions() |
| 48 |
branch := "test-branch" |
| 49 |
_, err = repo.PrepareTransaction() |
| 50 |
if err != nil { |
| 51 |
t.Fatalf("%s", err) |
| 52 |
} |
| 53 |
|
| 54 |
if _, err := repo.Commit(commitDir, branch, opts); err != nil { |
| 55 |
t.Fatalf("%s", err) |
| 56 |
} |
| 57 |
|
| 58 |
if _, err = repo.CommitTransaction(); err != nil { |
| 59 |
t.Fatalf("%s", err) |
| 60 |
} |
| 61 |
|
| 62 |
// Add more files to the commit dir and return |
| 63 |
if err := gopopulate.PopulateDir(commitDir, "rd", 4, 4); err != nil { |
| 64 |
t.Fatalf("%s", err) |
| 65 |
} |
| 66 |
|
| 67 |
// Get the logs for the branch |
| 68 |
logOpts := NewLogOptions() |
| 69 |
entries, err := Log(repoDir, branch, logOpts) |
| 70 |
if err != nil { |
| 71 |
t.Fatalf("%s", err) |
| 72 |
} |
| 73 |
|
| 74 |
if len(entries) <= 0 { |
| 75 |
t.Fatal("got no entries") |
| 76 |
} |
| 77 |
} |