Debian Codegraph @

internal/command/cmd_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 wd, err := os.Getwd()
12 if err != nil {
13 t.Fatalf("Test Failed.")
14 }
15 var tests = []struct {
16 inp1 string
17 inp2 string
18 inp3 []string
19 }{
20 {wd, "git", []string{"status"}},
21 }
22 for _, test := range tests {
23 if output, err := Run(test.inp1, test.inp2, test.inp3); err != nil || len(output) <= 0 {
24 t.Errorf("Test Failed. {%s, %s, %s} inputted, output: %s", test.inp1, test.inp2, test.inp3, output)
25 }
26 }
27 }
28
29 func TestReturn(t *testing.T) {
30 wd, err := os.Getwd()
31 if err != nil {
32 t.Fatalf("Test Failed.")
33 }
34 var tests = []struct {
35 inp1 string
36 inp2 string
37 inp3 []string
38 expected int
39 }{
40 {wd, "foo", []string{}, -1},
41 }
42 for _, test := range tests {
43 if output, _ := Return(test.inp1, test.inp2, test.inp3); output != test.expected {
44 t.Errorf("Test Failed. {%s, %s, %s} inputted, output: %d, expected : %d", test.inp1, test.inp2, test.inp3, output, test.expected)
45 }
46 }
47 }
48
49 func TestTrimTrailingNewline(t *testing.T) {
50 var tests = []struct {
51 input string
52 expected string
53 }{
54 {"foo", "foo"},
55 {"foo\n", "foo"},
56 {"foo\r", "foo"},
57 }
58 for _, test := range tests {
59 if output := trimTrailingNewline(test.input); output != test.expected {
60 t.Errorf("Test Failed. %s inputted, output: %s, expected: %s", test.input, output, test.expected)
61 }
62 }
63 }
64
65 func testFile(testRepoDir, name string) (*git.File, error) {
66 _, err := os.Create(testRepoDir + string(os.PathSeparator) + name)
67 if err != nil {
68 return nil, err
69 }
70 f := &git.File{
71 Name: name,
72 AbsPath: testRepoDir + string(os.PathSeparator) + name,
73 X: git.StatusUntracked,
74 Y: git.StatusUntracked,
75 }
76 return f, nil
77 }