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
1837c718
Commit
1837c718
authored
Nov 26, 2014
by
James Massara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for prevent_sudo
parent
a5ca2e5a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
provisioner/chef-client/provisioner_test.go
provisioner/chef-client/provisioner_test.go
+54
-0
No files found.
provisioner/chef-client/provisioner_test.go
View file @
1837c718
package
chefclient
package
chefclient
import
(
import
(
"bytes"
"io/ioutil"
"io/ioutil"
"os"
"os"
"strings"
"testing"
"testing"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
...
@@ -135,3 +137,55 @@ func TestProvisionerPrepare_serverUrl(t *testing.T) {
...
@@ -135,3 +137,55 @@ func TestProvisionerPrepare_serverUrl(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
}
}
func
TestProvisioner_createDir
(
t
*
testing
.
T
)
{
p1
:=
&
Provisioner
{
config
:
Config
{
PreventSudo
:
true
}}
p2
:=
&
Provisioner
{
config
:
Config
{
PreventSudo
:
false
}}
comm
:=
&
packer
.
MockCommunicator
{}
ui
:=
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
}
if
err
:=
p1
.
createDir
(
ui
,
comm
,
"/tmp/foo"
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatalf
(
"createDir should not use sudo, got:
\"
%s
\"
"
,
comm
.
StartCmd
.
Command
)
}
if
err
:=
p2
.
createDir
(
ui
,
comm
,
"/tmp/foo"
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatalf
(
"createDir should use sudo, got:
\"
%s
\"
"
,
comm
.
StartCmd
.
Command
)
}
}
func
TestProvisioner_removeDir
(
t
*
testing
.
T
)
{
p1
:=
&
Provisioner
{
config
:
Config
{
PreventSudo
:
true
}}
p2
:=
&
Provisioner
{
config
:
Config
{
PreventSudo
:
false
}}
comm
:=
&
packer
.
MockCommunicator
{}
ui
:=
&
packer
.
BasicUi
{
Reader
:
new
(
bytes
.
Buffer
),
Writer
:
new
(
bytes
.
Buffer
),
}
if
err
:=
p1
.
removeDir
(
ui
,
comm
,
"/tmp/foo"
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatalf
(
"removeDir should not use sudo, got:
\"
%s
\"
"
,
comm
.
StartCmd
.
Command
)
}
if
err
:=
p2
.
removeDir
(
ui
,
comm
,
"/tmp/foo"
);
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatalf
(
"removeDir should use sudo, got:
\"
%s
\"
"
,
comm
.
StartCmd
.
Command
)
}
}
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