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
|
package command
import (
"os"
"testing"
"github.com/isacikgoz/gitbatch/internal/git"
)
func TestRun(t *testing.T) {
// Test must be run from git repo
t.Skip()
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Test Failed.")
}
var tests = []struct {
inp1 string
inp2 string
inp3 []string
}{
{wd, "git", []string{"status"}},
}
for _, test := range tests {
if output, err := Run(test.inp1, test.inp2, test.inp3); err != nil || len(output) <= 0 {
t.Errorf("Test Failed. {%s, %s, %s} inputted, output: %s", test.inp1, test.inp2, test.inp3, output)
}
}
}
func TestReturn(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Test Failed.")
}
var tests = []struct {
inp1 string
inp2 string
inp3 []string
expected int
}{
{wd, "foo", []string{}, -1},
}
for _, test := range tests {
if output, _ := Return(test.inp1, test.inp2, test.inp3); output != test.expected {
t.Errorf("Test Failed. {%s, %s, %s} inputted, output: %d, expected : %d", test.inp1, test.inp2, test.inp3, output, test.expected)
}
}
}
func TestTrimTrailingNewline(t *testing.T) {
var tests = []struct {
input string
expected string
}{
{"foo", "foo"},
{"foo\n", "foo"},
{"foo\r", "foo"},
}
for _, test := range tests {
if output := trimTrailingNewline(test.input); output != test.expected {
t.Errorf("Test Failed. %s inputted, output: %s, expected: %s", test.input, output, test.expected)
}
}
}
func testFile(testRepoDir, name string) (*git.File, error) {
_, err := os.Create(testRepoDir + string(os.PathSeparator) + name)
if err != nil {
return nil, err
}
f := &git.File{
Name: name,
AbsPath: testRepoDir + string(os.PathSeparator) + name,
X: git.StatusUntracked,
Y: git.StatusUntracked,
}
return f, nil
}
|