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
37bd1cd3
Commit
37bd1cd3
authored
Apr 15, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test setting the UI for tests
parent
4eb8ac80
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
11 deletions
+60
-11
packer.go
packer.go
+1
-1
packer/environment.go
packer/environment.go
+33
-4
packer/environment_test.go
packer/environment_test.go
+26
-6
No files found.
packer.go
View file @
37bd1cd3
...
...
@@ -7,6 +7,6 @@ import (
)
func
main
()
{
env
:=
packer
.
NewEnvironment
()
env
:=
packer
.
NewEnvironment
(
nil
)
os
.
Exit
(
env
.
Cli
(
os
.
Args
[
1
:
]))
}
packer/environment.go
View file @
37bd1cd3
...
...
@@ -39,14 +39,43 @@ type Environment struct {
ui
Ui
}
// This struct configures new environments.
type
EnvironmentConfig
struct
{
builder
map
[
string
]
Builder
command
map
[
string
]
Command
ui
Ui
}
// This creates a new environment
func
NewEnvironment
()
*
Environment
{
func
NewEnvironment
(
config
*
EnvironmentConfig
)
*
Environment
{
env
:=
&
Environment
{}
env
.
builder
=
make
(
map
[
string
]
Builder
)
env
.
command
=
make
(
map
[
string
]
Command
)
if
config
!=
nil
{
for
k
,
v
:=
range
config
.
builder
{
env
.
builder
[
k
]
=
v
}
for
k
,
v
:=
range
config
.
command
{
env
.
command
[
k
]
=
v
}
env
.
ui
=
config
.
ui
}
if
_
,
ok
:=
env
.
command
[
"build"
];
!
ok
{
env
.
command
[
"build"
]
=
new
(
buildCommand
)
}
if
_
,
ok
:=
env
.
command
[
"version"
];
!
ok
{
env
.
command
[
"version"
]
=
new
(
versionCommand
)
}
if
env
.
ui
==
nil
{
env
.
ui
=
&
ReaderWriterUi
{
os
.
Stdin
,
os
.
Stdout
}
}
return
env
}
...
...
packer/environment_test.go
View file @
37bd1cd3
package
packer
import
(
"bytes"
"cgl.tideland.biz/asserts"
"os"
"testing"
)
func
testEnvironment
()
*
Environment
{
return
NewEnvironment
()
config
:=
&
EnvironmentConfig
{}
config
.
ui
=
&
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
),
}
return
NewEnvironment
(
config
)
}
func
TestEnvironment_Cli_CallsRun
(
t
*
testing
.
T
)
{
...
...
@@ -20,7 +27,7 @@ func TestEnvironment_Cli_CallsRun(t *testing.T) {
func
TestEnvironment_DefaultCli_Empty
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
New
Environment
()
defaultEnv
:=
test
Environment
()
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{}),
1
,
"CLI with no args"
)
}
...
...
@@ -28,7 +35,7 @@ func TestEnvironment_DefaultCli_Empty(t *testing.T) {
func
TestEnvironment_DefaultCli_Help
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
New
Environment
()
defaultEnv
:=
test
Environment
()
// Test the basic version options
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"--help"
}),
1
,
"--help should print"
)
...
...
@@ -38,7 +45,7 @@ func TestEnvironment_DefaultCli_Help(t *testing.T) {
func
TestEnvironment_DefaultCli_Version
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
New
Environment
()
defaultEnv
:=
test
Environment
()
// Test the basic version options
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"version"
}),
0
,
"version should work"
)
...
...
@@ -56,7 +63,7 @@ func TestEnvironment_DefaultCli_Version(t *testing.T) {
func
TestEnvironment_DefaultUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
NewEnvironment
()
defaultEnv
:=
NewEnvironment
(
nil
)
assert
.
NotNil
(
defaultEnv
.
Ui
(),
"default UI should not be nil"
)
rwUi
,
ok
:=
defaultEnv
.
Ui
()
.
(
*
ReaderWriterUi
)
...
...
@@ -67,5 +74,18 @@ func TestEnvironment_DefaultUi(t *testing.T) {
func
TestEnvironment_PrintHelp
(
t
*
testing
.
T
)
{
// Just call the function and verify that no panics occur
NewEnvironment
()
.
PrintHelp
()
testEnvironment
()
.
PrintHelp
()
}
func
TestEnvironment_SettingUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
ui
:=
&
ReaderWriterUi
{
new
(
bytes
.
Buffer
),
new
(
bytes
.
Buffer
)}
config
:=
&
EnvironmentConfig
{}
config
.
ui
=
ui
env
:=
NewEnvironment
(
config
)
assert
.
Equal
(
env
.
Ui
(),
ui
,
"UIs should be equal"
)
}
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