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
b3eacc5c
Commit
b3eacc5c
authored
Jul 13, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated test to verify expected behavior
parent
78174dae
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
13 deletions
+31
-13
command/command_test.go
command/command_test.go
+7
-0
command/test-fixtures/validate/template.json
command/test-fixtures/validate/template.json
+1
-1
command/validate_test.go
command/validate_test.go
+22
-10
packer/core.go
packer/core.go
+1
-2
No files found.
command/command_test.go
View file @
b3eacc5c
...
...
@@ -20,6 +20,13 @@ func fatalCommand(t *testing.T, m Meta) {
err
.
String
())
}
func
outputCommand
(
t
*
testing
.
T
,
m
Meta
)
(
string
,
string
)
{
ui
:=
m
.
Ui
.
(
*
packer
.
BasicUi
)
out
:=
ui
.
Writer
.
(
*
bytes
.
Buffer
)
err
:=
ui
.
ErrorWriter
.
(
*
bytes
.
Buffer
)
return
out
.
String
(),
err
.
String
()
}
func
testFixture
(
n
string
)
string
{
return
filepath
.
Join
(
fixturesDir
,
n
)
}
...
...
command/test-fixtures/validate/template.json
View file @
b3eacc5c
...
...
@@ -6,5 +6,5 @@
"content"
:
"chocolate"
}
],
"min_packer_version"
:
"
0.8
.0"
"min_packer_version"
:
"
101.0
.0"
}
command/validate_test.go
View file @
b3eacc5c
...
...
@@ -5,28 +5,40 @@ import (
"testing"
)
func
TestValidateCommand
(
t
*
testing
.
T
)
{
func
TestValidateCommand
OKVersion
(
t
*
testing
.
T
)
{
c
:=
&
ValidateCommand
{
Meta
:
testMetaFile
(
t
),
}
args
:=
[]
string
{
filepath
.
Join
(
testFixture
(
"validate"
),
"template.json"
),
}
defer
cleanup
()
// This should pass with a valid configuration version
c
.
CoreConfig
.
Version
=
"102.0.0"
if
code
:=
c
.
Run
(
args
);
code
!=
0
{
fatalCommand
(
t
,
c
.
Meta
)
}
}
if
!
fileExists
(
"chocolate.txt"
)
{
t
.
Error
(
"Expected to find chocolate.txt"
)
func
TestValidateCommandBadVersion
(
t
*
testing
.
T
)
{
c
:=
&
ValidateCommand
{
Meta
:
testMetaFile
(
t
),
}
if
!
fileExists
(
"vanilla.txt"
)
{
t
.
Error
(
"Expected to find vanilla.txt"
)
args
:=
[]
string
{
filepath
.
Join
(
testFixture
(
"validate"
),
"template.json"
),
}
if
fileExists
(
"cherry.txt"
)
{
t
.
Error
(
"Expected NOT to find cherry.txt"
)
// This should fail with an invalid configuration version
c
.
CoreConfig
.
Version
=
"100.0.0"
if
code
:=
c
.
Run
(
args
);
code
!=
1
{
t
.
Errorf
(
"Expected exit code 1"
)
}
stdout
,
stderr
:=
outputCommand
(
t
,
c
.
Meta
)
expected
:=
`Error initializing core: This template requires Packer version 101.0.0 or higher; using 100.0.0
`
if
stderr
!=
expected
{
t
.
Fatalf
(
"Expected:
\n
%s
\n
Found:
\n
%s
\n
"
,
expected
,
stderr
)
}
t
.
Log
(
stdout
)
}
packer/core.go
View file @
b3eacc5c
...
...
@@ -246,8 +246,7 @@ func (c *Core) validate() error {
if
versionActual
.
LessThan
(
versionMin
)
{
return
fmt
.
Errorf
(
"This template requires a minimum Packer version of %s,
\n
"
+
"but version %s is running."
,
"This template requires Packer version %s or higher; using %s"
,
versionMin
,
versionActual
)
}
...
...
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