-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_smoke_test.go
102 lines (81 loc) · 2.67 KB
/
main_smoke_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
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"testing"
)
var testFolderName = ".test_bin"
var binaryName = "hookboy"
func getOsDependentCommandPath() string {
var os = runtime.GOOS
switch os {
case "windows":
return fmt.Sprintf("%s/%s.exe", testFolderName, binaryName)
case "linux":
return fmt.Sprintf("%s/%s", testFolderName, binaryName)
default:
var panicMessage = fmt.Sprintf("Operating system of '%s' not supported for acceptance tests!", os)
panic(panicMessage)
}
}
func TestMain(m *testing.M) {
os.Mkdir(testFolderName, 0755)
var commandToRun = exec.Command("go", "build", "-o", testFolderName)
var runError = commandToRun.Run()
if runError != nil {
var panicMessage = fmt.Sprintf("Failed to prepare for tests!")
panic(panicMessage)
}
var exitCode = m.Run()
// TODO: Why does commenting out the following cause this test to successfully get past windows firewall?
// var removeError = os.RemoveAll(testFolderName)
// if removeError != nil {
// var panicMessage = fmt.Sprintf("Failed to remove test folder: '%s'", testFolderName)
// panic(panicMessage)
// }
os.Exit(exitCode)
}
func TestCliSaysHello(t *testing.T) {
var flagToTest = "hello"
var output, err = exec.Command(getOsDependentCommandPath(), flagToTest).Output()
if err != nil {
t.Errorf("Command failed to run: '%s'", err)
return
}
var expectedOutput = "Hello! Hookboy hopes that you are enjoying the better Git Hooks experience!"
var actualOutput = string(output)
if actualOutput != expectedOutput {
t.Errorf("Output incorrect! Expected '%s', received '%s'", expectedOutput, actualOutput)
}
}
var configSourceResult = `| Configuration Source
|--> Source: .hookboy.yml
|--> Description: Hookboy will look for configuration in a yaml file named .hookboy`
func TestHookboyConfigSourceFunctions(t *testing.T) {
var flagToTest = []string{"config", "source"}
var output, err = exec.Command(getOsDependentCommandPath(), flagToTest...).Output()
if err != nil {
t.Errorf("Command failed to run: '%s'", err)
return
}
var expectedOutput = configSourceResult
var actualOutput = string(output)
if actualOutput != expectedOutput {
t.Errorf("Output incorrect! Expected\n'%s'\nreceived\n'%s'", expectedOutput, actualOutput)
}
}
func TestHookboyInstallFunction(t *testing.T) {
var flagToTest = []string{"install"}
var output, err = exec.Command(getOsDependentCommandPath(), flagToTest...).Output()
if err != nil {
t.Errorf("Command failed to run: '%s'", err)
return
}
var expectedOutput = "Hooks installed!"
var actualOutput = string(output)
if actualOutput != expectedOutput {
t.Errorf("Output incorrect! Expected\n'%s'\nreceived\n'%s'", expectedOutput, actualOutput)
}
}