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
49e29d5a
Commit
49e29d5a
authored
May 26, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/testing: delete artifacts
parent
0e1fd516
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
helper/builder/testing/testing.go
helper/builder/testing/testing.go
+20
-9
No files found.
helper/builder/testing/testing.go
View file @
49e29d5a
...
...
@@ -2,6 +2,7 @@ package testing
import
(
"fmt"
"io/ioutil"
"log"
"os"
"strings"
...
...
@@ -27,8 +28,7 @@ type TestCase struct {
// as the "test" builder in the template.
Builder
packer
.
Builder
// Template is a path to a text template. We use a text file
// so we can use the entire machinery to test this builder.
// Template is the template contents to use.
Template
string
// Check is called after this step is executed in order to test that
...
...
@@ -90,8 +90,8 @@ func Test(t TestT, c TestCase) {
}
// Parse the template
log
.
Printf
(
"[DEBUG] Parsing template
: %s"
,
c
.
Template
)
tpl
,
err
:=
template
.
Parse
File
(
c
.
Template
)
log
.
Printf
(
"[DEBUG] Parsing template
..."
)
tpl
,
err
:=
template
.
Parse
(
strings
.
NewReader
(
c
.
Template
)
)
if
err
!=
nil
{
t
.
Fatal
(
fmt
.
Sprintf
(
"Failed to parse template: %s"
,
err
))
return
...
...
@@ -138,18 +138,19 @@ func Test(t TestT, c TestCase) {
return
}
// Run it!
// Run it! We use a temporary directory for caching and discard
// any UI output. We discard since it shows up in logs anyways.
log
.
Printf
(
"[DEBUG] Running 'test' build"
)
cache
:=
&
packer
.
FileCache
{
CacheDir
:
os
.
TempDir
()}
ui
:=
&
packer
.
BasicUi
{
Reader
:
os
.
Stdin
,
Writer
:
os
.
Stdout
,
ErrorWriter
:
os
.
Stdout
,
Writer
:
ioutil
.
Discard
,
ErrorWriter
:
ioutil
.
Discard
,
}
artifacts
,
err
:=
build
.
Run
(
ui
,
cache
)
if
err
!=
nil
{
t
.
Fatal
(
fmt
.
Sprintf
(
"Run error:
\n\n
%s"
,
err
))
return
goto
TEARDOWN
}
// Check function
...
...
@@ -157,7 +158,17 @@ func Test(t TestT, c TestCase) {
log
.
Printf
(
"[DEBUG] Running check function"
)
if
err
:=
c
.
Check
(
artifacts
);
err
!=
nil
{
t
.
Fatal
(
fmt
.
Sprintf
(
"Check error:
\n\n
%s"
,
err
))
return
goto
TEARDOWN
}
}
TEARDOWN
:
// Delete all artifacts
for
_
,
a
:=
range
artifacts
{
if
err
:=
a
.
Destroy
();
err
!=
nil
{
t
.
Error
(
fmt
.
Sprintf
(
"!!! ERROR REMOVING ARTIFACT '%s': %s !!!"
,
a
.
String
(),
err
))
}
}
...
...
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