-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test unit table simple for command root, version 🚨
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package root | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/LerianStudio/midaz/components/mdz/pkg/factory" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewCmdRoot(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
version string | ||
expectedOut string | ||
expectedErr string | ||
expectedHelp string | ||
}{ | ||
{ | ||
name: "Standard output", | ||
version: "1.0.0", | ||
expectedOut: "1.0.0", | ||
}, | ||
{ | ||
name: "Version empty", | ||
version: "", | ||
expectedOut: "", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
outBuf := new(bytes.Buffer) | ||
errBuf := new(bytes.Buffer) | ||
f := &factory.Factory{ | ||
CLIVersion: tt.version, | ||
IOStreams: &iostreams.IOStreams{ | ||
Out: outBuf, | ||
Err: errBuf, | ||
}, | ||
} | ||
|
||
cmd := NewCmdRoot(f) | ||
cmd.SetArgs([]string{"--help"}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package version | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/LerianStudio/midaz/components/mdz/pkg/factory" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" | ||
"github.com/fatih/color" | ||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFactoryVersionRunE(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
version string | ||
expected string | ||
}{ | ||
{ | ||
name: "Standard version output", | ||
version: "1.0.0", | ||
expected: color.New(color.Bold).Sprint("1.0.0") + "\n", | ||
}, | ||
{ | ||
name: "Empty version", | ||
version: "", | ||
expected: color.New(color.Bold).Sprint("") + "\n", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
f := &factory.Factory{ | ||
CLIVersion: tt.version, | ||
IOStreams: &iostreams.IOStreams{ | ||
Out: new(bytes.Buffer), | ||
}, | ||
} | ||
|
||
fVersion := &factoryVersion{ | ||
factory: f, | ||
} | ||
cmd := &cobra.Command{ | ||
RunE: fVersion.runE, | ||
} | ||
|
||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
|
||
output := f.IOStreams.Out.(*bytes.Buffer).String() | ||
assert.Equal(t, tt.expected, output) | ||
}) | ||
} | ||
} |