-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jovandeginste/add-cmd-tests
Add tests to test the cli
- Loading branch information
Showing
3 changed files
with
125 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/jovandeginste/payme/payment" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHelpCommand(t *testing.T) { | ||
q := qrParams{ | ||
Payment: payment.New(), | ||
} | ||
|
||
cmdRoot, err := newCommand(&q) | ||
assert.NoError(t, err) | ||
|
||
actualOut := new(bytes.Buffer) | ||
actualErr := new(bytes.Buffer) | ||
|
||
cmdRoot.SetOut(actualOut) | ||
cmdRoot.SetErr(actualErr) | ||
cmdRoot.SetArgs([]string{"help"}) | ||
|
||
_, err = cmdRoot.ExecuteC() | ||
|
||
assert.NoError(t, err) | ||
assert.Contains(t, actualOut.String(), "Generate SEPA payment QR code") | ||
assert.Empty(t, actualErr.String()) | ||
} | ||
|
||
func TestCompletionHelp(t *testing.T) { | ||
q := qrParams{ | ||
Payment: payment.New(), | ||
} | ||
|
||
cmdRoot, err := newCommand(&q) | ||
assert.NoError(t, err) | ||
|
||
actualOut := new(bytes.Buffer) | ||
actualErr := new(bytes.Buffer) | ||
|
||
cmdRoot.SetOut(actualOut) | ||
cmdRoot.SetErr(actualErr) | ||
cmdRoot.SetArgs([]string{"completion", "--help"}) | ||
|
||
_, err = cmdRoot.ExecuteC() | ||
|
||
assert.NoError(t, err) | ||
assert.Contains(t, actualOut.String(), "payme completion [bash|zsh|fish|powershell]") | ||
assert.Empty(t, actualErr.String()) | ||
} | ||
|
||
func TestCompletionShells(t *testing.T) { | ||
q := qrParams{ | ||
Payment: payment.New(), | ||
} | ||
|
||
cmdRoot, err := newCommand(&q) | ||
assert.NoError(t, err) | ||
|
||
for _, shell := range []string{"bash", "zsh", "fish", "powershell"} { | ||
actualOut := new(bytes.Buffer) | ||
actualErr := new(bytes.Buffer) | ||
|
||
cmdRoot.SetOut(actualOut) | ||
cmdRoot.SetErr(actualErr) | ||
cmdRoot.SetArgs([]string{"completion", shell}) | ||
|
||
_, err = cmdRoot.ExecuteC() | ||
|
||
assert.NoError(t, err) | ||
assert.Contains(t, actualOut.String(), shell+" completion for payme") | ||
assert.Empty(t, actualErr.String()) | ||
} | ||
} | ||
|
||
func TestVersionCommand(t *testing.T) { | ||
q := qrParams{ | ||
Payment: payment.New(), | ||
} | ||
|
||
cmdRoot, err := newCommand(&q) | ||
assert.NoError(t, err) | ||
|
||
actualOut := new(bytes.Buffer) | ||
actualErr := new(bytes.Buffer) | ||
|
||
cmdRoot.SetOut(actualOut) | ||
cmdRoot.SetErr(actualErr) | ||
cmdRoot.SetArgs([]string{"--version"}) | ||
|
||
_, err = cmdRoot.ExecuteC() | ||
|
||
assert.NoError(t, err) | ||
assert.Contains(t, actualOut.String(), "payme version local (local), built manually") | ||
assert.Empty(t, actualErr.String()) | ||
} |
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