Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
f579ff05
Commit
f579ff05
authored
Apr 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial work on Build
parent
05e254a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
3 deletions
+79
-3
packer/build.go
packer/build.go
+12
-1
packer/build_test.go
packer/build_test.go
+59
-0
packer/ui_test.go
packer/ui_test.go
+8
-2
No files found.
packer/build.go
View file @
f579ff05
...
...
@@ -20,7 +20,7 @@ type Build struct {
// Run is where the actual build should take place. It takes a Build and a Ui.
type
Builder
interface
{
Prepare
(
config
interface
{})
Run
(
build
Build
,
ui
Ui
)
Run
(
build
*
Build
,
ui
Ui
)
}
// This factory is responsible for returning Builders for the given name.
...
...
@@ -38,3 +38,14 @@ type NilBuilderFactory byte
func
(
NilBuilderFactory
)
CreateBuilder
(
name
string
)
Builder
{
return
nil
}
// Prepare prepares the build by doing some initialization for the builder
// and any hooks. This _must_ be called prior to Run.
func
(
b
*
Build
)
Prepare
(
config
interface
{})
{
b
.
builder
.
Prepare
(
config
)
}
// Runs the actual build. Prepare must be called prior to running this.
func
(
b
*
Build
)
Run
(
ui
Ui
)
{
b
.
builder
.
Run
(
b
,
ui
)
}
packer/build_test.go
0 → 100644
View file @
f579ff05
package
packer
import
(
"cgl.tideland.biz/asserts"
"testing"
)
type
TestBuilder
struct
{
prepareCalled
bool
prepareConfig
interface
{}
runCalled
bool
runBuild
*
Build
runUi
Ui
}
func
(
tb
*
TestBuilder
)
Prepare
(
config
interface
{})
{
tb
.
prepareCalled
=
true
tb
.
prepareConfig
=
config
}
func
(
tb
*
TestBuilder
)
Run
(
b
*
Build
,
ui
Ui
)
{
tb
.
runCalled
=
true
tb
.
runBuild
=
b
tb
.
runUi
=
ui
}
func
testBuild
()
*
Build
{
return
&
Build
{
name
:
"test"
,
builder
:
&
TestBuilder
{},
}
}
func
TestBuild_Prepare
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
build
:=
testBuild
()
build
.
Prepare
(
42
)
builder
:=
build
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
42
,
"prepare config should be 42"
)
}
func
TestBuild_Run
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
ui
:=
testUi
()
build
:=
testBuild
()
build
.
Run
(
ui
)
builder
:=
build
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
assert
.
Equal
(
builder
.
runBuild
,
build
,
"run should be called with build"
)
assert
.
Equal
(
builder
.
runUi
,
ui
,
"run should be called with ui"
)
}
packer/ui_test.go
View file @
f579ff05
...
...
@@ -6,12 +6,18 @@ import (
"testing"
)
// Our test Ui that just writes to bytes.Buffers.
var
bufferUi
=
&
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
)}
func
testUi
()
*
ReaderWriterUi
{
return
&
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
),
}
}
func
TestReaderWriterUi_Say
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
bufferUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo"
,
"basic output"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment