diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-09-11 09:16:39 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-09-11 09:16:39 +0200 |
| commit | 5eda8d6935d6d2b0db9bf3264832e575701696ff (patch) | |
| tree | 6d655f8461136d2250ca010bc310fb673231530f /status_test.go | |
| parent | c68241c3f0de4dd4d5756a1171e4e2c16e97c4e8 (diff) | |
| parent | d4734a41d5647a929c6dbbafbbec369002600de8 (diff) | |
Merge pull request #109 from roguePanda/git_status
Address issue #108
Diffstat (limited to 'status_test.go')
| -rw-r--r-- | status_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/status_test.go b/status_test.go new file mode 100644 index 0000000..4be4824 --- /dev/null +++ b/status_test.go @@ -0,0 +1,58 @@ +package git + +import ( + "io/ioutil" + "os" + "path" + "testing" +) + +func TestStatusFile(t *testing.T) { + repo := createTestRepo(t) + defer repo.Free() + defer os.RemoveAll(repo.Workdir()) + + err := ioutil.WriteFile(path.Join(path.Dir(repo.Workdir()), "hello.txt"), []byte("Hello, World"), 0644) + checkFatal(t, err) + + status, err := repo.StatusFile("hello.txt") + checkFatal(t, err) + + if status != StatusWtNew { + t.Fatal("Incorrect status flags: ", status) + } +} + +func TestStatusList(t *testing.T) { + repo := createTestRepo(t) + // This commits the test repo README, so it doesn't show up in the status list and there's a head to compare to + seedTestRepo(t, repo) + defer repo.Free() + defer os.RemoveAll(repo.Workdir()) + + err := ioutil.WriteFile(path.Join(path.Dir(repo.Workdir()), "hello.txt"), []byte("Hello, World"), 0644) + checkFatal(t, err) + + opts := &StatusOptions{} + opts.Show = StatusShowIndexAndWorkdir + opts.Flags = StatusOptIncludeUntracked | StatusOptRenamesHeadToIndex | StatusOptSortCaseSensitively + + statusList, err := repo.StatusList(opts) + checkFatal(t, err) + + entryCount, err := statusList.EntryCount() + checkFatal(t, err) + + if entryCount != 1 { + t.Fatal("Incorrect number of status entries: ", entryCount) + } + + entry, err := statusList.ByIndex(0) + checkFatal(t, err) + if entry.Status != StatusWtNew { + t.Fatal("Incorrect status flags: ", entry.Status) + } + if entry.IndexToWorkdir.NewFile.Path != "hello.txt" { + t.Fatal("Incorrect entry path: ", entry.IndexToWorkdir.NewFile.Path) + } +} |
