-
Notifications
You must be signed in to change notification settings - Fork 6
/
builder_test.go
63 lines (54 loc) · 1.52 KB
/
builder_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 gaper
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuilderSuccessBuild(t *testing.T) {
bArgs := []string{}
bin := resolveBinNameByOS("srv")
dir := filepath.Join("testdata", "server")
wd, err := os.Getwd()
if err != nil {
t.Fatalf("couldn't get current working directory: %v", err)
}
b := NewBuilder(dir, bin, wd, bArgs)
err = b.Build()
assert.Nil(t, err, "build error")
file, err := os.Open(filepath.Join(wd, bin))
if err != nil {
t.Fatalf("couldn't open open built binary: %v", err)
}
assert.NotNil(t, file, "binary not written properly")
}
func TestBuilderFailureBuild(t *testing.T) {
bArgs := []string{}
bin := "srv"
dir := filepath.Join("testdata", "build-failure")
wd, err := os.Getwd()
if err != nil {
t.Fatalf("couldn't get current working directory: %v", err)
}
b := NewBuilder(dir, bin, wd, bArgs)
err = b.Build()
assert.NotNil(t, err, "build error")
assert.Equal(t, err.Error(), "build failed with exit status 2\n"+
"# github.com/maxcnunes/gaper/testdata/build-failure\n"+
"./main.go:4:6: func main must have no arguments and no return values\n"+
"./main.go:5:1: missing return\n")
}
func TestBuilderDefaultBinName(t *testing.T) {
bin := ""
dir := filepath.Join("testdata", "server")
wd := "/src/projects/project-name"
b := NewBuilder(dir, bin, wd, nil)
assert.Equal(t, b.Binary(), resolveBinNameByOS("project-name"))
}
func resolveBinNameByOS(name string) string {
if runtime.GOOS == OSWindows {
name += ".exe"
}
return name
}