-
Notifications
You must be signed in to change notification settings - Fork 4
/
god_test.go
53 lines (47 loc) · 1.32 KB
/
god_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
package main
import (
"strings"
"testing"
)
func TestExecCmd(t *testing.T) {
echoOutput := execCmd(false, "echo", "'test'")
if !strings.Contains(echoOutput, "test") {
t.Errorf("Expected 'test', got '%s'", echoOutput)
}
if retval := execCmd(true, "sh", "-c", "echo 'Current dir:' && pwd"); len(retval) > 0 {
t.Errorf("Error occurred while executing the command. (%s)", retval)
}
}
func TestSearchInSlice(t *testing.T) {
testSlice := []string{"k", "3", "9", ".", "x"}
query := "."
if !searchInSlice(testSlice, query) {
t.Errorf("Cannot find '%s' in slice.", query)
}
}
func TestGetShortcutSlice(t *testing.T) {
gitShortcuts := [][]string{
{"commit", "cm"},
{"push", "ps"}}
for i, sc := range getShortcutSlice(gitShortcuts, 0) {
if sc != gitShortcuts[i][0] {
t.Error("Cannot retrieve the correct element from slice.")
}
}
}
func TestPrepareCmds(t *testing.T) {
gitCmds := prepareCmds()
if len(gitCmds) < 5 {
t.Error("Unable to prepare shortened git commands.")
}
}
func TestBuildCmd(t *testing.T) {
testCmd := "st && cm -m 'test' && ll && rmt && RR test"
gitCmdCheck := []string{"status", "commit", "log", "remote -v", "rm -r"}
gitCmd := buildCmd(testCmd)
for _, cmd := range gitCmdCheck {
if !strings.Contains(gitCmd, cmd) {
t.Errorf("Building Git command failed. '%s' -> '%s'", gitCmd, cmd)
}
}
}