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
386d72c3
Commit
386d72c3
authored
Oct 16, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: no more asserts lib
parent
19867b75
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
462 additions
and
267 deletions
+462
-267
packer/build_test.go
packer/build_test.go
+64
-33
packer/config_template_test.go
packer/config_template_test.go
+1
-1
packer/environment_test.go
packer/environment_test.go
+154
-97
packer/hook_test.go
packer/hook_test.go
+10
-12
packer/multi_error_test.go
packer/multi_error_test.go
+3
-4
packer/template_test.go
packer/template_test.go
+186
-105
packer/ui_test.go
packer/ui_test.go
+44
-15
No files found.
packer/build_test.go
View file @
386d72c3
package
packer
import
(
"cgl.tideland.biz/asserts"
"reflect"
"testing"
)
...
...
@@ -41,32 +40,43 @@ func testDefaultPackerConfig() map[string]interface{} {
}
}
func
TestBuild_Name
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
build
:=
testBuild
()
assert
.
Equal
(
build
.
Name
(),
"test"
,
"should have a name"
)
if
build
.
Name
()
!=
"test"
{
t
.
Fatalf
(
"bad: %s"
,
build
.
Name
())
}
}
func
TestBuild_Prepare
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
packerConfig
:=
testDefaultPackerConfig
()
build
:=
testBuild
()
builder
:=
build
.
builder
.
(
*
TestBuilder
)
build
.
Prepare
(
nil
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
[]
interface
{}{
42
,
packerConfig
},
"prepare config should be 42"
)
if
!
builder
.
prepareCalled
{
t
.
Fatal
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
builder
.
prepareConfig
,
[]
interface
{}{
42
,
packerConfig
})
{
t
.
Fatalf
(
"bad: %#v"
,
builder
.
prepareConfig
)
}
coreProv
:=
build
.
provisioners
[
0
]
prov
:=
coreProv
.
provisioner
.
(
*
MockProvisioner
)
assert
.
True
(
prov
.
PrepCalled
,
"prepare should be called"
)
assert
.
Equal
(
prov
.
PrepConfigs
,
[]
interface
{}{
42
,
packerConfig
},
"prepare should be called with proper config"
)
if
!
prov
.
PrepCalled
{
t
.
Fatal
(
"prep should be called"
)
}
if
!
reflect
.
DeepEqual
(
prov
.
PrepConfigs
,
[]
interface
{}{
42
,
packerConfig
})
{
t
.
Fatalf
(
"bad: %#v"
,
prov
.
PrepConfigs
)
}
corePP
:=
build
.
postProcessors
[
0
][
0
]
pp
:=
corePP
.
processor
.
(
*
TestPostProcessor
)
assert
.
True
(
pp
.
configCalled
,
"config should be called"
)
assert
.
Equal
(
pp
.
configVal
,
[]
interface
{}{
make
(
map
[
string
]
interface
{}),
packerConfig
},
"config should have right value"
)
if
!
pp
.
configCalled
{
t
.
Fatal
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
pp
.
configVal
,
[]
interface
{}{
make
(
map
[
string
]
interface
{}),
packerConfig
})
{
t
.
Fatalf
(
"bad: %#v"
,
pp
.
configVal
)
}
}
func
TestBuild_Prepare_Twice
(
t
*
testing
.
T
)
{
...
...
@@ -90,8 +100,6 @@ func TestBuild_Prepare_Twice(t *testing.T) {
}
func
TestBuild_Prepare_Debug
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
packerConfig
:=
testDefaultPackerConfig
()
packerConfig
[
DebugConfigKey
]
=
true
...
...
@@ -100,13 +108,21 @@ func TestBuild_Prepare_Debug(t *testing.T) {
build
.
SetDebug
(
true
)
build
.
Prepare
(
nil
)
assert
.
True
(
builder
.
prepareCalled
,
"prepare should be called"
)
assert
.
Equal
(
builder
.
prepareConfig
,
[]
interface
{}{
42
,
packerConfig
},
"prepare config should be 42"
)
if
!
builder
.
prepareCalled
{
t
.
Fatalf
(
"should be called"
)
}
if
!
reflect
.
DeepEqual
(
builder
.
prepareConfig
,
[]
interface
{}{
42
,
packerConfig
})
{
t
.
Fatalf
(
"bad: %#v"
,
builder
.
prepareConfig
)
}
coreProv
:=
build
.
provisioners
[
0
]
prov
:=
coreProv
.
provisioner
.
(
*
MockProvisioner
)
assert
.
True
(
prov
.
PrepCalled
,
"prepare should be called"
)
assert
.
Equal
(
prov
.
PrepConfigs
,
[]
interface
{}{
42
,
packerConfig
},
"prepare should be called with proper config"
)
if
!
prov
.
PrepCalled
{
t
.
Fatal
(
"prepare should be called"
)
}
if
!
reflect
.
DeepEqual
(
prov
.
PrepConfigs
,
[]
interface
{}{
42
,
packerConfig
})
{
t
.
Fatalf
(
"bad: %#v"
,
prov
.
PrepConfigs
)
}
}
func
TestBuildPrepare_variables_default
(
t
*
testing
.
T
)
{
...
...
@@ -186,37 +202,49 @@ func TestBuildPrepare_variablesRequired(t *testing.T) {
}
func
TestBuild_Run
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
cache
:=
&
TestCache
{}
ui
:=
testUi
()
build
:=
testBuild
()
build
.
Prepare
(
nil
)
artifacts
,
err
:=
build
.
Run
(
ui
,
cache
)
assert
.
Nil
(
err
,
"should not error"
)
assert
.
Equal
(
len
(
artifacts
),
2
,
"should have two artifacts"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
len
(
artifacts
)
!=
2
{
t
.
Fatalf
(
"bad: %#v"
,
artifacts
)
}
// Verify builder was run
builder
:=
build
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
runCalled
,
"run should be called"
)
if
!
builder
.
runCalled
{
t
.
Fatal
(
"should be called"
)
}
// Verify hooks are disapatchable
dispatchHook
:=
builder
.
runHook
dispatchHook
.
Run
(
"foo"
,
nil
,
nil
,
42
)
hook
:=
build
.
hooks
[
"foo"
][
0
]
.
(
*
MockHook
)
assert
.
True
(
hook
.
RunCalled
,
"run should be called"
)
assert
.
Equal
(
hook
.
RunData
,
42
,
"should have correct data"
)
if
!
hook
.
RunCalled
{
t
.
Fatal
(
"should be called"
)
}
if
hook
.
RunData
!=
42
{
t
.
Fatalf
(
"bad: %#v"
,
hook
.
RunData
)
}
// Verify provisioners run
dispatchHook
.
Run
(
HookProvision
,
nil
,
nil
,
42
)
prov
:=
build
.
provisioners
[
0
]
.
provisioner
.
(
*
MockProvisioner
)
assert
.
True
(
prov
.
ProvCalled
,
"provision should be called"
)
if
!
prov
.
ProvCalled
{
t
.
Fatal
(
"should be called"
)
}
// Verify post-processor was run
pp
:=
build
.
postProcessors
[
0
][
0
]
.
processor
.
(
*
TestPostProcessor
)
assert
.
True
(
pp
.
ppCalled
,
"post processor should be called"
)
if
!
pp
.
ppCalled
{
t
.
Fatal
(
"should be called"
)
}
}
func
TestBuild_Run_Artifacts
(
t
*
testing
.
T
)
{
...
...
@@ -356,23 +384,26 @@ func TestBuild_Run_Artifacts(t *testing.T) {
}
func
TestBuild_RunBeforePrepare
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defer
func
()
{
p
:=
recover
()
assert
.
NotNil
(
p
,
"should panic"
)
assert
.
Equal
(
p
.
(
string
),
"Prepare must be called first"
,
"right panic"
)
if
p
==
nil
{
t
.
Fatal
(
"should panic"
)
}
if
p
.
(
string
)
!=
"Prepare must be called first"
{
t
.
Fatalf
(
"bad: %s"
,
p
.
(
string
))
}
}()
testBuild
()
.
Run
(
testUi
(),
&
TestCache
{})
}
func
TestBuild_Cancel
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
build
:=
testBuild
()
build
.
Cancel
()
builder
:=
build
.
builder
.
(
*
TestBuilder
)
assert
.
True
(
builder
.
cancelCalled
,
"cancel should be called"
)
if
!
builder
.
cancelCalled
{
t
.
Fatal
(
"cancel should be called"
)
}
}
packer/config_template_test.go
View file @
386d72c3
...
...
@@ -80,7 +80,7 @@ func TestConfigTemplateProcess_uuid(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
len
(
result
)
!=
3
2
{
if
len
(
result
)
!=
3
6
{
t
.
Fatalf
(
"err: %s"
,
result
)
}
}
...
...
packer/environment_test.go
View file @
386d72c3
This diff is collapsed.
Click to expand it.
packer/hook_test.go
View file @
386d72c3
package
packer
import
(
"cgl.tideland.biz/asserts"
"sync"
"testing"
"time"
...
...
@@ -42,12 +41,7 @@ func (h *CancelHook) Cancel() {
}
func
TestDispatchHook_Implements
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
var
r
Hook
c
:=
&
DispatchHook
{}
assert
.
Implementor
(
c
,
&
r
,
"should be a Hook"
)
var
_
Hook
=
new
(
DispatchHook
)
}
func
TestDispatchHook_Run_NoHooks
(
t
*
testing
.
T
)
{
...
...
@@ -57,8 +51,6 @@ func TestDispatchHook_Run_NoHooks(t *testing.T) {
}
func
TestDispatchHook_Run
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
hook
:=
&
MockHook
{}
mapping
:=
make
(
map
[
string
][]
Hook
)
...
...
@@ -66,9 +58,15 @@ func TestDispatchHook_Run(t *testing.T) {
dh
:=
&
DispatchHook
{
Mapping
:
mapping
}
dh
.
Run
(
"foo"
,
nil
,
nil
,
42
)
assert
.
True
(
hook
.
RunCalled
,
"run should be called"
)
assert
.
Equal
(
hook
.
RunName
,
"foo"
,
"should be proper event"
)
assert
.
Equal
(
hook
.
RunData
,
42
,
"should be correct data"
)
if
!
hook
.
RunCalled
{
t
.
Fatal
(
"should be called"
)
}
if
hook
.
RunName
!=
"foo"
{
t
.
Fatalf
(
"bad: %s"
,
hook
.
RunName
)
}
if
hook
.
RunData
!=
42
{
t
.
Fatalf
(
"bad: %#v"
,
hook
.
RunData
)
}
}
func
TestDispatchHook_cancel
(
t
*
testing
.
T
)
{
...
...
packer/multi_error_test.go
View file @
386d72c3
package
packer
import
(
"cgl.tideland.biz/asserts"
"errors"
"testing"
)
...
...
@@ -15,8 +14,6 @@ func TestMultiError_Impl(t *testing.T) {
}
func
TestMultiErrorError
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
expected
:=
`2 error(s) occurred:
* foo
...
...
@@ -28,7 +25,9 @@ func TestMultiErrorError(t *testing.T) {
}
multi
:=
&
MultiError
{
errors
}
assert
.
Equal
(
multi
.
Error
(),
expected
,
"should have proper error"
)
if
multi
.
Error
()
!=
expected
{
t
.
Fatalf
(
"bad: %s"
,
multi
.
Error
())
}
}
func
TestMultiErrorAppend_MultiError
(
t
*
testing
.
T
)
{
...
...
packer/template_test.go
View file @
386d72c3
This diff is collapsed.
Click to expand it.
packer/ui_test.go
View file @
386d72c3
...
...
@@ -2,7 +2,6 @@ package packer
import
(
"bytes"
"cgl.tideland.biz/asserts"
"strings"
"testing"
)
...
...
@@ -38,25 +37,40 @@ func TestColoredUi(t *testing.T) {
}
func
TestTargettedUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
targettedUi
:=
&
TargettedUi
{
Target
:
"foo"
,
Ui
:
bufferUi
,
}
var
actual
,
expected
string
targettedUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"==> foo: foo
\n
"
,
"should have prefix"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"==> foo: foo
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
targettedUi
.
Message
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
" foo: foo
\n
"
,
"should have prefix"
)
actual
=
readWriter
(
bufferUi
)
expected
=
" foo: foo
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
targettedUi
.
Error
(
"bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"==> foo: bar
\n
"
,
"should have prefix"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"==> foo: bar
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
targettedUi
.
Say
(
"foo
\n
bar"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"==> foo: foo
\n
==> foo: bar
\n
"
,
"should multiline"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"==> foo: foo
\n
==> foo: bar
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
}
func
TestColoredUi_ImplUi
(
t
*
testing
.
T
)
{
...
...
@@ -84,27 +98,42 @@ func TestBasicUi_ImplUi(t *testing.T) {
}
func
TestBasicUi_Error
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
var
actual
,
expected
string
bufferUi
.
Error
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"foo
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
bufferUi
.
Error
(
"5"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"5
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
}
func
TestBasicUi_Say
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
var
actual
,
expected
string
bufferUi
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"foo
\n
"
,
"basic output"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"foo
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
bufferUi
.
Say
(
"5"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"5
\n
"
,
"formatting"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"5
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
}
func
TestMachineReadableUi_ImplUi
(
t
*
testing
.
T
)
{
...
...
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