Skip to content

Commit

Permalink
Merge pull request #2 from caarlos0/mybuild
Browse files Browse the repository at this point in the history
feat: support multiple gossfiles
  • Loading branch information
caarlos0 authored Dec 6, 2018
2 parents 373fd48 + 912a0b3 commit 309198c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ There is an example packer build with goss tests in the `example/` directory.
"skip_ssl": false,
"use_sudo": false,
"format": "",
"goss_file": "",
"vars_file": "",
"username": "",
"password": "",
Expand Down
5 changes: 2 additions & 3 deletions example/packer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"type": "goss",
"tests": [
"goss/goss.yaml"
],
"goss_file": "goss.yaml"
]
},{
"type": "shell",
"scripts": [
Expand All @@ -64,4 +63,4 @@
"type": "vagrant"
}
]
}
}
24 changes: 10 additions & 14 deletions packer-provisioner-goss.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type GossConfig struct {
// skip ssl check flag
SkipSSLChk bool `mapstructure:"skip_ssl"`

// The --gossfile flag
GossFile string `mapstructure:"goss_file"`

// The --vars flag
// Optional file containing variables, used within GOSS templating.
// Must be one of the files contained in the Tests array.
Expand Down Expand Up @@ -123,10 +120,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.Tests = make([]string, 0)
}

if p.config.GossFile != "" {
p.config.GossFile = fmt.Sprintf("--gossfile %s", p.config.GossFile)
}

var errs *packer.MultiError
if p.config.Format != "" {
valid := false
Expand Down Expand Up @@ -216,9 +209,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
}

ui.Say("Running goss tests...")
if err := p.runGoss(ui, comm); err != nil {
return fmt.Errorf("Error running Goss: %s", err)
for _, file := range p.config.Tests {
file := filepath.Base(file)
ui.Say(fmt.Sprintf("Running goss tests (%s)...", file))
if err := p.runGoss(ui, comm, file); err != nil {
return fmt.Errorf("Error running Goss: %s", err)
}
}

return nil
Expand All @@ -231,7 +227,7 @@ func (p *Provisioner) Cancel() {

// installGoss downloads the Goss binary on the remote host
func (p *Provisioner) installGoss(ui packer.Ui, comm packer.Communicator) error {
ui.Message(fmt.Sprintf("Installing Goss from, %s", p.config.URL))
ui.Message(fmt.Sprintf("Installing Goss from %s", p.config.URL))

cmd := &packer.RemoteCmd{
// Fallback on wget if curl failed for any reason (such as not being installed)
Expand All @@ -255,11 +251,11 @@ func (p *Provisioner) installGoss(ui packer.Ui, comm packer.Communicator) error
}

// runGoss runs the Goss tests
func (p *Provisioner) runGoss(ui packer.Ui, comm packer.Communicator) error {
func (p *Provisioner) runGoss(ui packer.Ui, comm packer.Communicator, file string) error {
cmd := &packer.RemoteCmd{
Command: fmt.Sprintf(
"cd %s && %s %s %s %s %s validate --retry-timeout %s --sleep %s %s",
p.config.RemotePath, p.enableSudo(), p.config.DownloadPath, p.config.GossFile,
"cd %s && %s %s --gossfile %s %s %s validate --retry-timeout %s --sleep %s %s",
p.config.RemotePath, p.enableSudo(), p.config.DownloadPath, file,
p.vars(), p.debug(), p.retryTimeout(), p.sleep(), p.format(),
),
}
Expand Down

0 comments on commit 309198c

Please sign in to comment.