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
e2e4c9f6
Commit
e2e4c9f6
authored
Feb 21, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: errors go to stderr [GH-868]
parent
1c655365
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
13 deletions
+35
-13
packer/environment.go
packer/environment.go
+1
-0
packer/environment_test.go
packer/environment_test.go
+1
-0
packer/ui.go
packer/ui.go
+7
-1
packer/ui_test.go
packer/ui_test.go
+26
-12
No files found.
packer/environment.go
View file @
e2e4c9f6
...
...
@@ -83,6 +83,7 @@ func DefaultEnvironmentConfig() *EnvironmentConfig {
config
.
Ui
=
&
BasicUi
{
Reader
:
os
.
Stdin
,
Writer
:
os
.
Stdout
,
ErrorWriter
:
os
.
Stderr
,
}
return
config
...
...
packer/environment_test.go
View file @
e2e4c9f6
...
...
@@ -32,6 +32,7 @@ func testEnvironment() Environment {
config
.
Ui
=
&
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
ErrorWriter
:
new
(
bytes
.
Buffer
),
}
env
,
err
:=
NewEnvironment
(
config
)
...
...
packer/ui.go
View file @
e2e4c9f6
...
...
@@ -61,6 +61,7 @@ type TargettedUi struct {
type
BasicUi
struct
{
Reader
io
.
Reader
Writer
io
.
Writer
ErrorWriter
io
.
Writer
l
sync
.
Mutex
interrupted
bool
}
...
...
@@ -235,8 +236,13 @@ func (rw *BasicUi) Error(message string) {
rw
.
l
.
Lock
()
defer
rw
.
l
.
Unlock
()
writer
:=
rw
.
ErrorWriter
if
writer
==
nil
{
writer
=
rw
.
Writer
}
log
.
Printf
(
"ui error: %s"
,
message
)
_
,
err
:=
fmt
.
Fprint
(
rw
.
W
riter
,
message
+
"
\n
"
)
_
,
err
:=
fmt
.
Fprint
(
w
riter
,
message
+
"
\n
"
)
if
err
!=
nil
{
log
.
Printf
(
"[ERR] Failed to write to UI: %s"
,
err
)
}
...
...
packer/ui_test.go
View file @
e2e4c9f6
...
...
@@ -7,10 +7,27 @@ import (
"testing"
)
// This reads the output from the bytes.Buffer in our test object
// and then resets the buffer.
func
readWriter
(
ui
*
BasicUi
)
(
result
string
)
{
buffer
:=
ui
.
Writer
.
(
*
bytes
.
Buffer
)
result
=
buffer
.
String
()
buffer
.
Reset
()
return
}
func
readErrorWriter
(
ui
*
BasicUi
)
(
result
string
)
{
buffer
:=
ui
.
ErrorWriter
.
(
*
bytes
.
Buffer
)
result
=
buffer
.
String
()
buffer
.
Reset
()
return
}
func
testUi
()
*
BasicUi
{
return
&
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
ErrorWriter
:
new
(
bytes
.
Buffer
),
}
}
...
...
@@ -32,6 +49,11 @@ func TestColoredUi(t *testing.T) {
ui
.
Error
(
"foo"
)
result
=
readWriter
(
bufferUi
)
if
result
!=
""
{
t
.
Fatalf
(
"invalid output: %s"
,
result
)
}
result
=
readErrorWriter
(
bufferUi
)
if
result
!=
"
\0
33[1;31mfoo
\0
33[0m
\n
"
{
t
.
Fatalf
(
"invalid output: %s"
,
result
)
}
...
...
@@ -59,7 +81,7 @@ func TestColoredUi_noColorEnv(t *testing.T) {
}
ui
.
Error
(
"foo"
)
result
=
readWriter
(
bufferUi
)
result
=
read
Error
Writer
(
bufferUi
)
if
result
!=
"foo
\n
"
{
t
.
Fatalf
(
"invalid output: %s"
,
result
)
}
...
...
@@ -88,7 +110,7 @@ func TestTargettedUi(t *testing.T) {
}
targettedUi
.
Error
(
"bar"
)
actual
=
readWriter
(
bufferUi
)
actual
=
read
Error
Writer
(
bufferUi
)
expected
=
"==> foo: bar
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
...
...
@@ -131,12 +153,13 @@ func TestBasicUi_Error(t *testing.T) {
var
actual
,
expected
string
bufferUi
.
Error
(
"foo"
)
actual
=
readWriter
(
bufferUi
)
actual
=
read
Error
Writer
(
bufferUi
)
expected
=
"foo
\n
"
if
actual
!=
expected
{
t
.
Fatalf
(
"bad: %#v"
,
actual
)
}
bufferUi
.
ErrorWriter
=
nil
bufferUi
.
Error
(
"5"
)
actual
=
readWriter
(
bufferUi
)
expected
=
"5
\n
"
...
...
@@ -214,12 +237,3 @@ func TestMachineReadableUi(t *testing.T) {
t
.
Fatalf
(
"bad: %#v"
,
data
)
}
}
// This reads the output from the bytes.Buffer in our test object
// and then resets the buffer.
func
readWriter
(
ui
*
BasicUi
)
(
result
string
)
{
buffer
:=
ui
.
Writer
.
(
*
bytes
.
Buffer
)
result
=
buffer
.
String
()
buffer
.
Reset
()
return
}
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