This repository has been archived by the owner on Nov 8, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
builder_test.go
115 lines (106 loc) · 2.68 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
package bake_test
/*
import (
"reflect"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/flynn/bake"
)
// Ensure the builder can build a target in a project with no dependencies.
func TestBuilder_Build_NoDependencies(t *testing.T) {
// Create builder and mock exec call.
b := NewBuilder()
b.Importer.ImportFn = func(name string) (*bake.Package, error) {
if name != "myproj" {
t.Fatalf("unexpected name: %s", name)
}
return &bake.Package{
Name: "myproj",
Targets: []*bake.Target{
{
Command: "go build -o bin/foo .",
Outputs: []string{"bin/foo"},
},
},
}, nil
}
b.Execer.ExecFn = func(cmd string) bake.Command {
if cmd != "go build -o bin/foo ." {
t.Fatalf("unexpected command: %s", cmd)
}
return &Command{stdout: "OK"}
}
// Build target and verify output.
build := b.Build("myproj:bin/foo")
if !reflect.DeepEqual(build, &bake.Build{
Label: bake.Label{Package: "myproj", Target: "bin/foo"},
Outputs: []string{"bin/foo"},
}) {
t.Fatalf("unexpected build: %s", spew.Sdump(build))
}
}
// Ensure the builder can build a target in a project with with nested dependencies.
func TestBuilder_Build_WithDependencies(t *testing.T) {
// Create builder and mock exec call.
b := NewBuilder()
b.Importer.ImportFn = func(name string) (*bake.Package, error) {
switch name {
case "A":
return &bake.Package{
Name: "A",
Targets: []*bake.Target{
{
Command: "make",
Inputs: []string{"B:site.css"},
Outputs: []string{"main.exe"},
},
},
}, nil
case "B":
return &bake.Package{
Name: "B",
Targets: []*bake.Target{
{
Command: "lessc site.less site.css",
Outputs: []string{"site.css"},
},
},
}, nil
default:
t.Fatalf("unexpected import name: %q", name)
return nil, nil
}
}
b.Execer.ExecFn = func(cmd string) bake.Command { return &Command{} }
// Build target and verify output.
build := b.Build("A:main.exe")
if !reflect.DeepEqual(build, &bake.Build{
Label: bake.Label{Package: "A", Target: "main.exe"},
Outputs: []string{"main.exe"},
Dependencies: []*bake.Build{
{
Label: bake.Label{Package: "B", Target: "site.css"},
Outputs: []string{"site.css"},
},
},
}) {
t.Fatalf("unexpected build: %s", spew.Sdump(build))
}
}
// Builder represents a mockable test wrapper for bake.Builder.
type Builder struct {
*bake.Builder
Execer Execer
}
// NewBuilder returns a new instance of Builder.
func NewBuilder() *Builder {
b := &Builder{Builder: bake.NewBuilder()}
b.Builder.Importer = &b.Importer
b.Builder.Execer = &b.Execer
return b
}
// Close stops the builder and removes the underlying data.
func (b *Builder) Close() error {
return nil
}
*/