-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
63 lines (48 loc) · 1.07 KB
/
main_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
package main
import (
"bytes"
"fmt"
"os"
"os/exec"
"testing"
"github.com/phayes/hookserve/hookserve"
)
func init() {
os.Setenv("PUSH_PORT", "8578")
os.Setenv("PUSH_HTTP_PATH", "/push")
os.Setenv("PUSH_PROJECT_DIR", ".")
}
type TestRunner struct {
output *bytes.Buffer
}
func (r TestRunner) Run(cmd *exec.Cmd) error {
fmt.Fprintf(r.output, "%s", cmd.Args)
return nil
}
func TestPull(t *testing.T) {
var out bytes.Buffer
executer := TestRunner{&out}
pull(hookserve.Event{}, executer)
if out.String() != "[git pull]" {
t.Errorf("Expected %q got %q", "[git pull]", out.String())
}
}
func TestBuild(t *testing.T) {
var out bytes.Buffer
executer := TestRunner{&out}
build(executer)
if out.String() != "[hugo]" {
t.Errorf("Expected %q got %q", "[hugo]", out.String())
}
}
func TestRun(t *testing.T) {
var out bytes.Buffer
executer := cliRunner{&out}
cliCmd := exec.Command("echo", "go rules")
var out2 bytes.Buffer
cliCmd.Stdout = &out2
executer.Run(cliCmd)
if out2.String() != "go rules\n" {
t.Errorf("Expected %q got %q", "go rules", out2.String())
}
}