| 1 |
package command |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/isacikgoz/gitbatch/internal/git" |
| 8 |
) |
| 9 |
|
| 10 |
func TestRun(t *testing.T) { |
| •11 |
// Test must be run from git repo |
| 12 |
t.Skip() |
| 13 |
wd, err := os.Getwd() |
| 14 |
if err != nil { |
| 15 |
t.Fatalf("Test Failed.") |
| 16 |
} |
| 17 |
var tests = []struct { |
| 18 |
inp1 string |
| 19 |
inp2 string |
| 20 |
inp3 []string |
| 21 |
}{ |
| 22 |
{wd, "git", []string{"status"}}, |
| 23 |
} |
| 24 |
for _, test := range tests { |
| 25 |
if output, err := Run(test.inp1, test.inp2, test.inp3); err != nil || len(output) <= 0 { |
| 26 |
t.Errorf("Test Failed. {%s, %s, %s} inputted, output: %s", test.inp1, test.inp2, test.inp3, output) |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func TestReturn(t *testing.T) { |
| 32 |
wd, err := os.Getwd() |
| 33 |
if err != nil { |
| 34 |
t.Fatalf("Test Failed.") |
| 35 |
} |
| 36 |
var tests = []struct { |
| 37 |
inp1 string |
| 38 |
inp2 string |
| 39 |
inp3 []string |
| 40 |
expected int |
| 41 |
}{ |
| 42 |
{wd, "foo", []string{}, -1}, |
| 43 |
} |
| 44 |
for _, test := range tests { |
| 45 |
if output, _ := Return(test.inp1, test.inp2, test.inp3); output != test.expected { |
| 46 |
t.Errorf("Test Failed. {%s, %s, %s} inputted, output: %d, expected : %d", test.inp1, test.inp2, test.inp3, output, test.expected) |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
func TestTrimTrailingNewline(t *testing.T) { |
| 52 |
var tests = []struct { |
| 53 |
input string |
| 54 |
expected string |
| 55 |
}{ |
| 56 |
{"foo", "foo"}, |
| 57 |
{"foo\n", "foo"}, |
| 58 |
{"foo\r", "foo"}, |
| 59 |
} |
| 60 |
for _, test := range tests { |
| 61 |
if output := trimTrailingNewline(test.input); output != test.expected { |
| 62 |
t.Errorf("Test Failed. %s inputted, output: %s, expected: %s", test.input, output, test.expected) |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
func testFile(testRepoDir, name string) (*git.File, error) { |
| 68 |
_, err := os.Create(testRepoDir + string(os.PathSeparator) + name) |
| 69 |
if err != nil { |
| 70 |
return nil, err |
| 71 |
} |
| 72 |
f := &git.File{ |
| 73 |
Name: name, |
| 74 |
AbsPath: testRepoDir + string(os.PathSeparator) + name, |
| 75 |
X: git.StatusUntracked, |
| 76 |
Y: git.StatusUntracked, |
| 77 |
} |
| 78 |
return f, nil |
| 79 |
} |