Skip to content

Commit 67d4c83

Browse files
committed
add tOut. improve assert helpers functions
1 parent 5ee88fe commit 67d4c83

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

cmd/desc_branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestDescBranchCmd(t *testing.T) {
6060
stdout, execResult := execT.executeCommand()
6161
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
6262
if tc.expect == pass {
63-
assertStringContains(t, stdout, tc.args[0])
63+
assertOutContains(t, stdout, tc.args[0])
6464
}
6565
})
6666
}

cmd/helpers_for_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"strings"
3030
"testing"
3131

32+
"github.com/kyokomi/emoji"
3233
"github.com/olekukonko/tablewriter"
3334
"github.com/spf13/cobra"
3435
)
@@ -51,6 +52,10 @@ func tInfo(msg interface{}) {
5152
fmt.Println("--- INFO:", msg)
5253
}
5354

55+
func tOut(msg interface{}) {
56+
fmt.Println("--- OUTPUT:", msg)
57+
}
58+
5459
func unsetE(k ...string) {
5560
for _, v := range k {
5661
if err := os.Unsetenv(v); err != nil {
@@ -202,13 +207,20 @@ func printFlagsTable(flagsMap map[string]string, c string) string {
202207

203208
func assertEqualResult(t *testing.T, got, want testResult, msg string) {
204209
if got != want {
205-
t.Fatalf("got test result %s, want %s: \n%s",
206-
got, want, msg)
210+
t.Fatal(emoji.Sprintf(":x:got test result %s, want %s\n%s", got, want, msg))
211+
} else {
212+
tInfo(emoji.Sprint(":white_check_mark:test result assertion passed!"))
207213
}
208214
}
209215

210-
func assertStringContains(t *testing.T, s, contains string) {
211-
if !strings.Contains(s, contains) {
212-
t.Fatalf("expected to see %s in %s", contains, s)
216+
func assertOutContains(t *testing.T, s string, contains ...string) {
217+
for _, c := range contains {
218+
if !strings.Contains(s, c) {
219+
t.Fatal(
220+
emoji.Sprintf("\n:x:output is expected to contain '%s',"+
221+
"\ngot output: %s", c, s))
222+
} else {
223+
tInfo(emoji.Sprintf(":white_check_mark:output assertion passed! it contains: %s", c))
224+
}
213225
}
214226
}

cmd/new_branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestNewBranch(t *testing.T) {
6060
fmt.Println(stdout)
6161
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
6262
if tc.expect == pass {
63-
assertStringContains(t, stdout, tc.args[0])
63+
assertOutContains(t, stdout, tc.args[0])
6464
if err := deleteBranch(tc.flagsMap["project"], tc.args[0]); err != nil {
6565
tInfo(err)
6666
}

0 commit comments

Comments
 (0)