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
94e1f830
Commit
94e1f830
authored
Jun 27, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a black-box acceptance test for -only and -except build flags
parent
eee06637
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
0 deletions
+154
-0
command/build_test.go
command/build_test.go
+132
-0
command/test-fixtures/build-only/template.json
command/test-fixtures/build-only/template.json
+22
-0
No files found.
command/build_test.go
0 → 100644
View file @
94e1f830
package
command
import
(
"bytes"
"os"
"path/filepath"
"testing"
"github.com/mitchellh/packer/builder/file"
"github.com/mitchellh/packer/packer"
)
func
TestBuildOnlyFileCommaFlags
(
t
*
testing
.
T
)
{
c
:=
&
BuildCommand
{
Meta
:
testMetaFile
(
t
),
}
args
:=
[]
string
{
"-only=chocolate,vanilla"
,
filepath
.
Join
(
testFixture
(
"build-only"
),
"template.json"
),
}
defer
cleanup
()
if
code
:=
c
.
Run
(
args
);
code
!=
0
{
fatalCommand
(
t
,
c
.
Meta
)
}
if
!
fileExists
(
"chocolate.txt"
)
{
t
.
Error
(
"Expected to find chocolate.txt"
)
}
if
!
fileExists
(
"vanilla.txt"
)
{
t
.
Error
(
"Expected to find vanilla.txt"
)
}
if
fileExists
(
"cherry.txt"
)
{
t
.
Error
(
"Expected NOT to find cherry.txt"
)
}
}
func
TestBuildOnlyFileMultipleFlags
(
t
*
testing
.
T
)
{
c
:=
&
BuildCommand
{
Meta
:
testMetaFile
(
t
),
}
args
:=
[]
string
{
"-only=chocolate"
,
"-only=cherry"
,
filepath
.
Join
(
testFixture
(
"build-only"
),
"template.json"
),
}
defer
cleanup
()
if
code
:=
c
.
Run
(
args
);
code
!=
0
{
fatalCommand
(
t
,
c
.
Meta
)
}
if
!
fileExists
(
"chocolate.txt"
)
{
t
.
Error
(
"Expected to find chocolate.txt"
)
}
if
fileExists
(
"vanilla.txt"
)
{
t
.
Error
(
"Expected NOT to find vanilla.txt"
)
}
if
!
fileExists
(
"cherry.txt"
)
{
t
.
Error
(
"Expected to find cherry.txt"
)
}
}
func
TestBuildExceptFileCommaFlags
(
t
*
testing
.
T
)
{
c
:=
&
BuildCommand
{
Meta
:
testMetaFile
(
t
),
}
args
:=
[]
string
{
"-except=chocolate"
,
filepath
.
Join
(
testFixture
(
"build-only"
),
"template.json"
),
}
defer
cleanup
()
if
code
:=
c
.
Run
(
args
);
code
!=
0
{
fatalCommand
(
t
,
c
.
Meta
)
}
if
fileExists
(
"chocolate.txt"
)
{
t
.
Error
(
"Expected NOT to find chocolate.txt"
)
}
if
!
fileExists
(
"vanilla.txt"
)
{
t
.
Error
(
"Expected to find vanilla.txt"
)
}
if
!
fileExists
(
"cherry.txt"
)
{
t
.
Error
(
"Expected to find cherry.txt"
)
}
}
// fileExists returns true if the filename is found
func
fileExists
(
filename
string
)
bool
{
if
_
,
err
:=
os
.
Stat
(
filename
);
err
==
nil
{
return
true
}
return
false
}
// testCoreConfigBuilder creates a packer CoreConfig that has a file builder
// available. This allows us to test a builder that writes files to disk.
func
testCoreConfigBuilder
(
t
*
testing
.
T
)
*
packer
.
CoreConfig
{
components
:=
packer
.
ComponentFinder
{
Builder
:
func
(
n
string
)
(
packer
.
Builder
,
error
)
{
return
&
file
.
Builder
{},
nil
},
}
return
&
packer
.
CoreConfig
{
Components
:
components
,
}
}
// testMetaFile creates a Meta object that includes a file builder
func
testMetaFile
(
t
*
testing
.
T
)
Meta
{
var
out
,
err
bytes
.
Buffer
return
Meta
{
CoreConfig
:
testCoreConfigBuilder
(
t
),
Ui
:
&
packer
.
BasicUi
{
Writer
:
&
out
,
ErrorWriter
:
&
err
,
},
}
}
func
cleanup
()
{
os
.
RemoveAll
(
"chocolate.txt"
)
os
.
RemoveAll
(
"vanilla.txt"
)
os
.
RemoveAll
(
"cherry.txt"
)
}
command/test-fixtures/build-only/template.json
0 → 100644
View file @
94e1f830
{
"builders"
:
[
{
"name"
:
"chocolate"
,
"type"
:
"file"
,
"content"
:
"chocolate"
,
"target"
:
"chocolate.txt"
},
{
"name"
:
"vanilla"
,
"type"
:
"file"
,
"content"
:
"vanilla"
,
"target"
:
"vanilla.txt"
},
{
"name"
:
"cherry"
,
"type"
:
"file"
,
"content"
:
"cherry"
,
"target"
:
"cherry.txt"
}
]
}
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