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
6d9265a2
Commit
6d9265a2
authored
Aug 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: add mock implementations and more template tests
parent
1e6f39c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
0 deletions
+106
-0
common/command/template_test.go
common/command/template_test.go
+37
-0
packer/artifact_mock.go
packer/artifact_mock.go
+33
-0
packer/builder_mock.go
packer/builder_mock.go
+36
-0
No files found.
common/command/template_test.go
View file @
6d9265a2
package
command
import
(
"github.com/mitchellh/packer/packer"
"testing"
)
func
testTemplate
()
(
*
packer
.
Template
,
*
packer
.
ComponentFinder
)
{
tplData
:=
`{
"builders": [
{
"type": "foo"
},
{
"type": "bar"
}
]
}`
tpl
,
err
:=
packer
.
ParseTemplate
([]
byte
(
tplData
))
if
err
!=
nil
{
panic
(
err
)
}
cf
:=
&
packer
.
ComponentFinder
{
Builder
:
func
(
string
)
(
packer
.
Builder
,
error
)
{
return
new
(
packer
.
MockBuilder
),
nil
},
}
return
tpl
,
cf
}
func
TestBuildOptionsBuilds
(
t
*
testing
.
T
)
{
opts
:=
new
(
BuildOptions
)
bs
,
err
:=
opts
.
Builds
(
testTemplate
())
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
len
(
bs
)
!=
2
{
t
.
Fatalf
(
"bad: %d"
,
len
(
bs
))
}
}
func
TestBuildOptionsValidate
(
t
*
testing
.
T
)
{
bf
:=
new
(
BuildOptions
)
...
...
packer/artifact_mock.go
0 → 100644
View file @
6d9265a2
package
packer
// MockArtifact is an implementation of Artifact that can be used for tests.
type
MockArtifact
struct
{
IdValue
string
DestroyCalled
bool
}
func
(
*
MockArtifact
)
BuilderId
()
string
{
return
"bid"
}
func
(
*
MockArtifact
)
Files
()
[]
string
{
return
[]
string
{
"a"
,
"b"
}
}
func
(
a
*
MockArtifact
)
Id
()
string
{
id
:=
a
.
IdValue
if
id
==
""
{
id
=
"id"
}
return
id
}
func
(
*
MockArtifact
)
String
()
string
{
return
"string"
}
func
(
a
*
MockArtifact
)
Destroy
()
error
{
a
.
DestroyCalled
=
true
return
nil
}
packer/builder_mock.go
0 → 100644
View file @
6d9265a2
package
packer
// MockBuilder is an implementation of Builder that can be used for tests.
// You can set some fake return values and you can keep track of what
// methods were called on the builder. It is fairly basic.
type
MockBuilder
struct
{
ArtifactId
string
PrepareCalled
bool
PrepareConfig
[]
interface
{}
RunCalled
bool
RunCache
Cache
RunHook
Hook
RunUi
Ui
CancelCalled
bool
}
func
(
tb
*
MockBuilder
)
Prepare
(
config
...
interface
{})
error
{
tb
.
PrepareCalled
=
true
tb
.
PrepareConfig
=
config
return
nil
}
func
(
tb
*
MockBuilder
)
Run
(
ui
Ui
,
h
Hook
,
c
Cache
)
(
Artifact
,
error
)
{
tb
.
RunCalled
=
true
tb
.
RunHook
=
h
tb
.
RunUi
=
ui
tb
.
RunCache
=
c
return
&
MockArtifact
{
IdValue
:
tb
.
ArtifactId
,
},
nil
}
func
(
tb
*
MockBuilder
)
Cancel
()
{
tb
.
CancelCalled
=
true
}
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