/
index_test.go
93 lines (76 loc) · 2.09 KB
/
index_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"strconv"
"testing"
"time"
)
func TestToHistLine_NoExitStatus(t *testing.T) {
now := time.Now()
e := IndexEntry{}
e.Command = "git log --graph --abbrev-commit --decorate --date=relative --all"
e.Tags = []string{"git", "log", "graph"}
e.Directory = "/home/soren/src/project"
e.HasStatus = false
e.Host = "laptop"
e.Shell = "bash"
e.User = "soren"
e.Timestamp = now
expected := "U" + "" + now.Format(time.UnixDate) +
"sorenlaptopbash/home/soren/src/project" +
"git log --graph --abbrev-commit --decorate --date=relative --all" +
"[git log graph]"
result := toHistLine(e)
if result != expected {
t.Fail()
}
}
func TestToHistLine_WithExitStatus(t *testing.T) {
now := time.Now()
e := IndexEntry{}
e.Command = "git log --graph --abbrev-commit --decorate --date=relative --all"
e.Tags = []string{"git", "log", "graph"}
e.Directory = "/home/soren/src/project"
e.HasStatus = true
e.Status = 0
e.Host = "laptop"
e.Shell = "bash"
e.User = "soren"
e.Timestamp = now
expected := "U" + "" + now.Format(time.UnixDate) +
"sorenlaptopbash/home/soren/src/project" +
"git log --graph --abbrev-commit --decorate --date=relative --all" +
"[git log graph]0"
result := toHistLine(e)
if result != expected {
t.Fail()
}
}
func TestParseToInvocation(t *testing.T) {
ti := time.Time{}
sync := strconv.QuoteRune(Syncd)
sample := sync + "" + ti.Format(time.UnixDate) +
"sorenlaptopbash/home/soren/src/project" +
"git log --graph --abbrev-commit --decorate --date=relative --all" +
"[git log graph]0\n"
expect := IndexEntry{}
expect.User = "soren"
expect.Host = "laptop"
expect.Shell = "bash"
expect.Timestamp = ti
expect.Directory = "/home/soren/src/project"
expect.Command = "git log --graph --abbrev-commit --decorate --date=relative --all"
expect.Tags = []string{"git", "log", "graph"}
expect.Status = 0
expect.HasStatus = true
expect.IsSynced = true
res, err := parseToEntry(sample)
if err != nil {
t.Fail()
}
expectedStr := fmt.Sprint(expect)
resultStr := fmt.Sprint(res)
if expectedStr != resultStr {
t.Fail()
}
}