Skip to content

Commit

Permalink
Make output format configurable (#11)
Browse files Browse the repository at this point in the history
* Add output-format option
  • Loading branch information
petemounce authored and fishnix committed Apr 16, 2018
1 parent 1f76056 commit 9ac10cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ There is an example packer build with goss tests in the `example/` directory.
"skipInstall": false,
"skip_ssl": false,
"use_sudo": false,
"format": "",
"goss_file": "",
"username": "",
"password": "",
Expand Down
33 changes: 31 additions & 2 deletions packer-provisioner-goss.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ type GossConfig struct {
// This defaults to remote_folder/goss
RemotePath string `mapstructure:"remote_path"`

// The format to use for test output
// Available: [documentation json json_oneline junit nagios nagios_verbose rspecish silent tap]
// Default: rspecish
Format string `mapstructure:"format"`

ctx interpolate.Context
}

var validFormats = []string{"documentation", "json", "json_oneline", "junit", "nagios", "nagios_verbose", "rspecish", "silent", "tap"}

// Provisioner implements a packer Provisioner
type Provisioner struct {
config GossConfig
Expand Down Expand Up @@ -111,6 +118,21 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}

var errs *packer.MultiError
if p.config.Format != "" {
valid := false
for _, candidate := range validFormats {
if p.config.Format == candidate {
valid = true
break
}
}
if !valid {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Invalid format choice %s. Valid options: %v",
p.config.Format, validFormats))
}
}

if len(p.config.Tests) == 0 {
errs = packer.MultiErrorAppend(errs,
errors.New("tests must be specified"))
Expand Down Expand Up @@ -213,8 +235,8 @@ func (p *Provisioner) runGoss(ui packer.Ui, comm packer.Communicator) error {
goss := fmt.Sprintf("%s", p.config.DownloadPath)
cmd := &packer.RemoteCmd{
Command: fmt.Sprintf(
"cd %s && %s %s %s %s validate",
p.config.RemotePath, p.enableSudo(), goss, p.config.GossFile, p.debug()),
"cd %s && %s %s %s %s validate %s",
p.config.RemotePath, p.enableSudo(), goss, p.config.GossFile, p.debug(), p.format()),
}
if err := cmd.StartWithUi(comm, ui); err != nil {
return err
Expand All @@ -234,6 +256,13 @@ func (p *Provisioner) debug() string {
return ""
}

func (p *Provisioner) format() string {
if p.config.Format != "" {
return fmt.Sprintf("-f %s", p.config.Format)
}
return ""
}

func (p *Provisioner) sslFlag(cmdType string) string {
if p.config.SkipSSLChk {
switch(cmdType) {
Expand Down

0 comments on commit 9ac10cc

Please sign in to comment.