forked from puppetlabs-toy-chest/pct
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
805 additions
and
808 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.