Skip to content

Commit

Permalink
(maint) Tidy up wth go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
da-ar committed Jun 4, 2021
1 parent 9c21ce7 commit 1f6d559
Show file tree
Hide file tree
Showing 19 changed files with 805 additions and 808 deletions.
35 changes: 17 additions & 18 deletions acceptance/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/stretchr/testify/assert"
)

var templatePath string;
var templatePath string

func TestMain(m *testing.M) {
log.Logger = zerolog.New(ioutil.Discard).With().Timestamp().Logger()
Expand All @@ -29,9 +29,9 @@ func TestPctNew(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new", "")
assert.Contains(t, stdout, "DISPLAYNAME" )
assert.Contains(t, stdout, "NAME" )
assert.Contains(t, stdout, "TYPE" )
assert.Contains(t, stdout, "DISPLAYNAME")
assert.Contains(t, stdout, "NAME")
assert.Contains(t, stdout, "TYPE")
assert.Equal(t, "", stderr)
assert.Equal(t, 0, exitCode)
}
Expand All @@ -40,19 +40,19 @@ func TestPctNewUnknownTag(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new --foo", "")
assert.Contains(t, stdout, "unknown flag: --foo", )
assert.Contains(t, stdout, "unknown flag: --foo")
assert.Equal(t, "exit status 1", stderr)
assert.Equal(t, 1, exitCode)
}

func TestPctNewTemplatePath(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new --templatepath " + templatePath, "")
assert.Contains(t, stdout, "DISPLAYNAME" )
assert.Contains(t, stdout, "NAME" )
assert.Contains(t, stdout, "TYPE" )
assert.Contains(t, stdout, "full-project" )
stdout, stderr, exitCode := testutils.RunPctCommand("new --templatepath "+templatePath, "")
assert.Contains(t, stdout, "DISPLAYNAME")
assert.Contains(t, stdout, "NAME")
assert.Contains(t, stdout, "TYPE")
assert.Contains(t, stdout, "full-project")
assert.Equal(t, "", stderr)
assert.Equal(t, 0, exitCode)
}
Expand All @@ -61,25 +61,24 @@ func TestPctNewUnknownTemplate(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new foo", "")
assert.Contains(t, stdout, "Error: Couldn't find an installed template that matches 'foo'" )
assert.Contains(t, stdout, "Error: Couldn't find an installed template that matches 'foo'")
assert.Equal(t, "exit status 1", stderr)
assert.Equal(t, 1, exitCode)
}

func TestPctNewKnownTemplate(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new full-project --templatepath " + templatePath, os.TempDir())
assert.Contains(t, stdout, "Deployed:" )
stdout, stderr, exitCode := testutils.RunPctCommand("new full-project --templatepath "+templatePath, os.TempDir())
assert.Contains(t, stdout, "Deployed:")
assert.Equal(t, "", stderr)
assert.Equal(t, 0, exitCode)
}


func TestPctNewInfo(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new --info full-project --templatepath " + templatePath, os.TempDir())
stdout, stderr, exitCode := testutils.RunPctCommand("new --info full-project --templatepath "+templatePath, os.TempDir())

expectedYaml := `puppet_module:
license: Apache-2.0
Expand All @@ -99,15 +98,15 @@ func TestPctNewInfo(t *testing.T) {
assert.Fail(t, "expected data is not YAML")
}

assert.Equal(t, output, expected )
assert.Equal(t, output, expected)
assert.Equal(t, "", stderr)
assert.Equal(t, 0, exitCode)
}

func TestPctNewInfoJson(t *testing.T) {
testutils.SkipAcceptanceTest(t)

stdout, stderr, exitCode := testutils.RunPctCommand("new --info full-project --format json --templatepath " + templatePath, os.TempDir())
stdout, stderr, exitCode := testutils.RunPctCommand("new --info full-project --format json --templatepath "+templatePath, os.TempDir())

expectedJson := `{
"puppet_module": {
Expand All @@ -130,7 +129,7 @@ func TestPctNewInfoJson(t *testing.T) {
assert.Fail(t, "expected data is not JSON")
}

assert.Equal(t, output, expected )
assert.Equal(t, output, expected)
assert.Equal(t, "", stderr)
assert.Equal(t, 0, exitCode)
}
2 changes: 1 addition & 1 deletion acceptance/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func RunPctCommand(cmdString string, wd string) (stdout string, stderr string, e
postfix = ".exe"
}

pctPath := fmt.Sprintf("../dist/pct_%s_%s/pct%s", runtime.GOOS, runtime.GOARCH, postfix)
pctPath := fmt.Sprintf("../dist/pct_%s_%s/pct%s", runtime.GOOS, runtime.GOARCH, postfix)
absPath, err := filepath.Abs(pctPath)

if err != nil {
Expand Down
112 changes: 56 additions & 56 deletions cmd/build/build_test.go
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
package build

import (
"bytes"
"io/ioutil"
"regexp"
"testing"
"bytes"
"io/ioutil"
"regexp"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/cobra"
)

func nullFunction(cmd *cobra.Command, args []string) error {
return nil
return nil
}

func TestCreatebuildCommand(t *testing.T) {
tests := []struct {
name string
args []string
returnCode int
out string
wantCmd *cobra.Command
wantErr bool
f func(cmd *cobra.Command, args []string) error
}{
{
name: "executes without error",
f: nullFunction,
out: "",
wantErr: false,
},
tests := []struct {
name string
args []string
returnCode int
out string
wantCmd *cobra.Command
wantErr bool
f func(cmd *cobra.Command, args []string) error
}{
{
name: "executes without error",
f: nullFunction,
out: "",
wantErr: false,
},
{
name: "executes without error for valid flag",
args: []string{"build"},
f: nullFunction,
out: "",
wantErr: false,
},
{
name: "executes with error for invalid flag",
args: []string{"--foo"},
f: nullFunction,
out: "unknown flag: --foo",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := CreateCommand()
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetErr(b)
cmd.SetArgs(tt.args)
cmd.RunE = tt.f
{
name: "executes with error for invalid flag",
args: []string{"--foo"},
f: nullFunction,
out: "unknown flag: --foo",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := CreateCommand()
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetErr(b)
cmd.SetArgs(tt.args)
cmd.RunE = tt.f

err := cmd.Execute()
if (err != nil) != tt.wantErr {
t.Errorf("executeTestUnit() error = %v, wantErr %v", err, tt.wantErr)
return
}
err := cmd.Execute()
if (err != nil) != tt.wantErr {
t.Errorf("executeTestUnit() error = %v, wantErr %v", err, tt.wantErr)
return
}

out, err := ioutil.ReadAll(b)
if err != nil {
t.Errorf("Failed to read stdout: %v", err)
return
}
out, err := ioutil.ReadAll(b)
if err != nil {
t.Errorf("Failed to read stdout: %v", err)
return
}

output := string(out)
r := regexp.MustCompile(tt.out)
if !r.MatchString(output) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
})
}
}
output := string(out)
r := regexp.MustCompile(tt.out)
if !r.MatchString(output) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
})
}
}
110 changes: 55 additions & 55 deletions cmd/bundle/bundle_test.go
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
package bundle

import (
"bytes"
"io/ioutil"
"regexp"
"testing"
"bytes"
"io/ioutil"
"regexp"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/cobra"
)

func nullFunction(cmd *cobra.Command, args []string) error {
return nil
return nil
}

func TestCreateCommand(t *testing.T) {
tests := []struct {
name string
args []string
returnCode int
out string
wantCmd *cobra.Command
wantErr bool
f func(cmd *cobra.Command, args []string) error
}{
{
name: "executes without error",
f: nullFunction,
out: "",
wantErr: false,
},
tests := []struct {
name string
args []string
returnCode int
out string
wantCmd *cobra.Command
wantErr bool
f func(cmd *cobra.Command, args []string) error
}{
{
name: "executes without error",
f: nullFunction,
out: "",
wantErr: false,
},
{
name: "executes without error for valid flag",
args: []string{"bundle"},
f: nullFunction,
out: "",
wantErr: false,
},
{
name: "executes with error for invalid flag",
args: []string{"--foo"},
f: nullFunction,
out: "unknown flag: --foo",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := CreateCommand()
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetErr(b)
cmd.SetArgs(tt.args)
cmd.RunE = tt.f
{
name: "executes with error for invalid flag",
args: []string{"--foo"},
f: nullFunction,
out: "unknown flag: --foo",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := CreateCommand()
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetErr(b)
cmd.SetArgs(tt.args)
cmd.RunE = tt.f

err := cmd.Execute()
if (err != nil) != tt.wantErr {
t.Errorf("executeTestUnit() error = %v, wantErr %v", err, tt.wantErr)
return
}
err := cmd.Execute()
if (err != nil) != tt.wantErr {
t.Errorf("executeTestUnit() error = %v, wantErr %v", err, tt.wantErr)
return
}

out, err := ioutil.ReadAll(b)
if err != nil {
t.Errorf("Failed to read stdout: %v", err)
return
}
out, err := ioutil.ReadAll(b)
if err != nil {
t.Errorf("Failed to read stdout: %v", err)
return
}

output := string(out)
r := regexp.MustCompile(tt.out)
if !r.MatchString(output) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
})
}
output := string(out)
r := regexp.MustCompile(tt.out)
if !r.MatchString(output) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
return
}
})
}
}
6 changes: 3 additions & 3 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

func CreateCompletionCommand() *cobra.Command {
tmp := &cobra.Command{
Use: "completion",
Short: "Generate shell completions for the chosen shell",
Long: `To load completions:
Use: "completion",
Short: "Generate shell completions for the chosen shell",
Long: `To load completions:
Bash:
Expand Down
Loading

0 comments on commit 1f6d559

Please sign in to comment.