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
91c524c7
Commit
91c524c7
authored
Mar 24, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More environment testing
parent
215dba3d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
4 deletions
+49
-4
Makefile
Makefile
+3
-0
packer/environment.go
packer/environment.go
+1
-1
packer/environment_test.go
packer/environment_test.go
+42
-0
packer/ui_test.go
packer/ui_test.go
+2
-2
packer/version.go
packer/version.go
+1
-1
No files found.
Makefile
View file @
91c524c7
...
...
@@ -3,6 +3,9 @@ all:
go get
-d
./...
go build
-a
-o
bin/packer
format
:
go
fmt
./...
test
:
go
test
./...
...
...
packer/environment.go
View file @
91c524c7
...
...
@@ -30,7 +30,7 @@ func NewEnvironment() *Environment {
env
:=
&
Environment
{}
env
.
command
=
make
(
map
[
string
]
Command
)
env
.
command
[
"version"
]
=
new
(
versionCommand
)
env
.
ui
=
&
ReaderWriterUi
{
os
.
Stdin
,
os
.
Stdout
}
env
.
ui
=
&
ReaderWriterUi
{
os
.
Stdin
,
os
.
Stdout
}
return
env
}
...
...
packer/environment_test.go
View file @
91c524c7
package
packer
import
(
"cgl.tideland.biz/asserts"
"os"
"testing"
)
func
TestEnvironment_DefaultCli_Empty
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
NewEnvironment
()
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{}),
1
,
"CLI with no args"
)
}
func
TestEnvironment_DefaultCli_Version
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
NewEnvironment
()
// Test the basic version options
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"version"
}),
0
,
"version should work"
)
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"--version"
}),
0
,
"--version should work"
)
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"-v"
}),
0
,
"-v should work"
)
// Test the --version and -v can appear anywhere
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"bad"
,
"-v"
}),
0
,
"-v should work anywhere"
)
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"bad"
,
"--version"
}),
0
,
"--version should work anywhere"
)
// Test that "version" can't appear anywhere
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"bad"
,
"version"
}),
1
,
"version should NOT work anywhere"
)
}
func
TestEnvironment_DefaultUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
NewEnvironment
()
assert
.
NotNil
(
defaultEnv
.
Ui
(),
"default UI should not be nil"
)
rwUi
,
ok
:=
defaultEnv
.
Ui
()
.
(
*
ReaderWriterUi
)
assert
.
True
(
ok
,
"default UI should be ReaderWriterUi"
)
assert
.
Equal
(
rwUi
.
Writer
,
os
.
Stdout
,
"default UI should go to stdout"
)
assert
.
Equal
(
rwUi
.
Reader
,
os
.
Stdin
,
"default UI should read from stdin"
)
}
packer/ui_test.go
View file @
91c524c7
...
...
@@ -2,12 +2,12 @@ package packer
import
(
"bytes"
"testing"
"cgl.tideland.biz/asserts"
"testing"
)
// Our test Ui that just writes to bytes.Buffers.
var
bufferUi
=
&
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
)
}
var
bufferUi
=
&
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
)
}
func
TestReaderWriterUi_Say
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
packer/version.go
View file @
91c524c7
...
...
@@ -6,7 +6,7 @@ const Version = "0.1.0.dev"
type
versionCommand
byte
// Implement the Command interface by simply showing the version
func
(
versionCommand
)
Run
(
env
*
Environment
,
args
[]
string
)
int
{
func
(
versionCommand
)
Run
(
env
*
Environment
,
args
[]
string
)
int
{
env
.
Ui
()
.
Say
(
"Packer v%v
\n
"
,
Version
)
return
0
}
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