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
9289df6d
Commit
9289df6d
authored
Jul 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/plugin: connect stdin to parent stdin
parent
ce584930
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
0 deletions
+64
-0
packer/plugin/client.go
packer/plugin/client.go
+1
-0
packer/plugin/client_test.go
packer/plugin/client_test.go
+49
-0
packer/plugin/plugin_test.go
packer/plugin/plugin_test.go
+14
-0
No files found.
packer/plugin/client.go
View file @
9289df6d
...
...
@@ -216,6 +216,7 @@ func (c *Client) Start() (address string, err error) {
cmd
:=
c
.
config
.
Cmd
cmd
.
Env
=
append
(
cmd
.
Env
,
os
.
Environ
()
...
)
cmd
.
Env
=
append
(
cmd
.
Env
,
env
...
)
cmd
.
Stdin
=
os
.
Stdin
cmd
.
Stderr
=
stderr
cmd
.
Stdout
=
stdout
...
...
packer/plugin/client_test.go
View file @
9289df6d
package
plugin
import
(
"io/ioutil"
"os"
"testing"
"time"
)
...
...
@@ -47,3 +49,50 @@ func TestClient_Start_Timeout(t *testing.T) {
t
.
Fatal
(
"err should not be nil"
)
}
}
func
TestClient_Stdin
(
t
*
testing
.
T
)
{
// Overwrite stdin for this test with a temporary file
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
os
.
Remove
(
tf
.
Name
())
defer
tf
.
Close
()
if
_
,
err
=
tf
.
WriteString
(
"hello"
);
err
!=
nil
{
t
.
Fatalf
(
"error: %s"
,
err
)
}
if
err
=
tf
.
Sync
();
err
!=
nil
{
t
.
Fatalf
(
"error: %s"
,
err
)
}
if
_
,
err
=
tf
.
Seek
(
0
,
0
);
err
!=
nil
{
t
.
Fatalf
(
"error: %s"
,
err
)
}
oldStdin
:=
os
.
Stdin
defer
func
()
{
os
.
Stdin
=
oldStdin
}()
os
.
Stdin
=
tf
process
:=
helperProcess
(
"stdin"
)
c
:=
NewClient
(
&
ClientConfig
{
Cmd
:
process
})
defer
c
.
Kill
()
_
,
err
=
c
.
Start
()
if
err
!=
nil
{
t
.
Fatalf
(
"error: %s"
,
err
)
}
for
{
if
c
.
Exited
()
{
break
}
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
if
!
process
.
ProcessState
.
Success
()
{
t
.
Fatal
(
"process didn't exit cleanly"
)
}
}
packer/plugin/plugin_test.go
View file @
9289df6d
...
...
@@ -2,6 +2,7 @@ package plugin
import
(
"fmt"
"log"
"os"
"os/exec"
"testing"
...
...
@@ -65,6 +66,19 @@ func TestHelperProcess(*testing.T) {
ServeProvisioner
(
new
(
helperProvisioner
))
case
"start-timeout"
:
time
.
Sleep
(
1
*
time
.
Minute
)
os
.
Exit
(
1
)
case
"stdin"
:
fmt
.
Println
(
":1234"
)
data
:=
make
([]
byte
,
5
)
if
_
,
err
:=
os
.
Stdin
.
Read
(
data
);
err
!=
nil
{
log
.
Printf
(
"stdin read error: %s"
,
err
)
os
.
Exit
(
100
)
}
if
string
(
data
)
==
"hello"
{
os
.
Exit
(
0
)
}
os
.
Exit
(
1
)
default
:
fmt
.
Fprintf
(
os
.
Stderr
,
"Unknown command: %q
\n
"
,
cmd
)
...
...
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