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
0d33f9ae
Commit
0d33f9ae
authored
Jul 11, 2013
by
James Van Dyke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic test file for provisioner-chef-solo.
parent
355fdeca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
52 deletions
+121
-52
provisioner/chef-solo/provisioner.go
provisioner/chef-solo/provisioner.go
+53
-52
provisioner/chef-solo/provisioner_test.go
provisioner/chef-solo/provisioner_test.go
+68
-0
No files found.
provisioner/chef-solo/provisioner.go
View file @
0d33f9ae
...
@@ -5,6 +5,7 @@ package chefSolo
...
@@ -5,6 +5,7 @@ package chefSolo
import
(
import
(
"bufio"
"bufio"
"bytes"
"bytes"
"encoding/json"
"fmt"
"fmt"
"github.com/mitchellh/iochan"
"github.com/mitchellh/iochan"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/mapstructure"
...
@@ -13,16 +14,15 @@ import (
...
@@ -13,16 +14,15 @@ import (
"io/ioutil"
"io/ioutil"
"log"
"log"
"os"
"os"
"path/filepath"
"strings"
"strings"
"text/template"
"text/template"
"path/filepath"
"encoding/json"
)
)
const
RemoteStagingPath
=
"/tmp/provision/chef-solo"
const
RemoteStagingPath
=
"/tmp/provision/chef-solo"
const
RemoteFileCachePath
=
"/tmp/provision/chef-solo"
const
RemoteFileCachePath
=
"/tmp/provision/chef-solo"
const
RemoteCookbookPath
=
"/tmp/provision/chef-solo/cookbooks"
const
RemoteCookbookPath
=
"/tmp/provision/chef-solo/cookbooks"
const
DefaultCookbookPath
=
"cookbooks"
const
DefaultCookbook
s
Path
=
"cookbooks"
var
Ui
packer
.
Ui
var
Ui
packer
.
Ui
...
@@ -67,7 +67,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
...
@@ -67,7 +67,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
}
if
p
.
config
.
CookbooksPaths
==
nil
{
if
p
.
config
.
CookbooksPaths
==
nil
{
p
.
config
.
CookbooksPaths
=
make
([]
string
,
0
)
p
.
config
.
CookbooksPaths
=
[]
string
{
DefaultCookbooksPath
}
}
}
if
p
.
config
.
Recipes
==
nil
{
if
p
.
config
.
Recipes
==
nil
{
...
@@ -154,7 +155,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
...
@@ -154,7 +155,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
}
func
UploadLocalDirectory
(
localDir
string
,
comm
packer
.
Communicator
)
(
err
error
)
{
func
UploadLocalDirectory
(
localDir
string
,
comm
packer
.
Communicator
)
(
err
error
)
{
visitPath
:=
func
(
path
string
,
f
os
.
FileInfo
,
err
error
)
(
err2
error
)
{
visitPath
:=
func
(
path
string
,
f
os
.
FileInfo
,
err
error
)
(
err2
error
)
{
var
remotePath
=
RemoteCookbookPath
+
"/"
+
path
var
remotePath
=
RemoteCookbookPath
+
"/"
+
path
if
f
.
IsDir
()
{
if
f
.
IsDir
()
{
// Make remote directory
// Make remote directory
...
@@ -219,7 +220,7 @@ func CreateSoloRb(cookbooksPaths []string, comm packer.Communicator) (str string
...
@@ -219,7 +220,7 @@ func CreateSoloRb(cookbooksPaths []string, comm packer.Communicator) (str string
writer
:=
bufio
.
NewWriter
(
tf
)
writer
:=
bufio
.
NewWriter
(
tf
)
// Messy, messy...
// Messy, messy...
cbPathsCat
:=
"
\"
"
+
RemoteCookbookPath
+
"/"
+
strings
.
Join
(
cookbooksPaths
,
"
\"
,
\"
"
+
RemoteCookbookPath
+
"/"
)
+
"
\"
"
cbPathsCat
:=
"
\"
"
+
RemoteCookbookPath
+
"/"
+
strings
.
Join
(
cookbooksPaths
,
"
\"
,
\"
"
+
RemoteCookbookPath
+
"/"
)
+
"
\"
"
contents
:=
"file_cache_path
\"
"
+
RemoteFileCachePath
+
"
\"\n
cookbook_path ["
+
cbPathsCat
+
"]
\n
"
contents
:=
"file_cache_path
\"
"
+
RemoteFileCachePath
+
"
\"\n
cookbook_path ["
+
cbPathsCat
+
"]
\n
"
if
_
,
err
:=
writer
.
WriteString
(
contents
);
err
!=
nil
{
if
_
,
err
:=
writer
.
WriteString
(
contents
);
err
!=
nil
{
...
@@ -252,7 +253,7 @@ func CreateAttributesJson(jsonAttrs map[string]interface{}, recipes []string, co
...
@@ -252,7 +253,7 @@ func CreateAttributesJson(jsonAttrs map[string]interface{}, recipes []string, co
var
formattedRecipes
[]
string
var
formattedRecipes
[]
string
for
_
,
value
:=
range
recipes
{
for
_
,
value
:=
range
recipes
{
formattedRecipes
=
append
(
formattedRecipes
,
"recipe["
+
value
+
"]"
)
formattedRecipes
=
append
(
formattedRecipes
,
"recipe["
+
value
+
"]"
)
}
}
// Add Recipes to JSON
// Add Recipes to JSON
...
...
provisioner/chef-solo/provisioner_test.go
0 → 100644
View file @
0d33f9ae
package
chefSolo
import
(
"github.com/mitchellh/packer/packer"
"io/ioutil"
"os"
"testing"
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
// "inline": []interface{}{"foo", "bar"},
}
}
func
TestProvisioner_Impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
Provisioner
{}
if
_
,
ok
:=
raw
.
(
packer
.
Provisioner
);
!
ok
{
t
.
Fatalf
(
"must be a Provisioner"
)
}
}
// Cookbook paths
//////////////////
func
TestProvisionerPrepare_DefaultCookbookPathIsUsed
(
t
*
testing
.
T
)
{
var
p
Provisioner
config
:=
testConfig
()
err
:=
p
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Errorf
(
"expected error to be thrown for unavailable cookbook path"
)
}
if
len
(
p
.
config
.
CookbooksPaths
)
!=
1
||
p
.
config
.
CookbooksPaths
[
0
]
!=
DefaultCookbooksPath
{
t
.
Errorf
(
"unexpected default cookbook path: %s"
,
p
.
config
.
CookbooksPaths
)
}
}
func
TestProvisionerPrepare_GivenCookbookPathsAreAddedToConfig
(
t
*
testing
.
T
)
{
var
p
Provisioner
path1
,
err
:=
ioutil
.
TempDir
(
""
,
"cookbooks_one"
)
if
err
!=
nil
{
t
.
Errorf
(
"err: %s"
,
err
)
}
path2
,
err
:=
ioutil
.
TempDir
(
""
,
"cookbooks_two"
)
if
err
!=
nil
{
t
.
Errorf
(
"err: %s"
,
err
)
}
defer
os
.
Remove
(
path1
)
defer
os
.
Remove
(
path2
)
config
:=
testConfig
()
config
[
"cookbooks_paths"
]
=
[]
string
{
path1
,
path2
}
err
=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Errorf
(
"err: %s"
,
err
)
}
if
len
(
p
.
config
.
CookbooksPaths
)
!=
2
||
p
.
config
.
CookbooksPaths
[
0
]
!=
path1
||
p
.
config
.
CookbooksPaths
[
1
]
!=
path2
{
t
.
Errorf
(
"unexpected default cookbook path: %s"
,
p
.
config
.
CookbooksPaths
)
}
}
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