Skip to content

Commit

Permalink
replace testify with standard lib to resolve unknown panic errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bzon committed Jun 20, 2018
1 parent 36a0afa commit 948f7e6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ windows: create_bin_dir
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINDIR}/${BINARY}-windows-${GOARCH}.exe .

test: getdep
echo Performing a go test
go test ./... -v -failfast
rm -f ~/.gitlabctl.yaml
go test -v ./... -failfast

coverage: getdep
echo Performing test with coverage
go test ./... -v -failfast -coverprofile=coverage.txt -covermode=atomic
go test -v ./... -failfast -coverprofile=coverage.txt -covermode=atomic

getdep:
go get -v ./...
Expand Down
13 changes: 5 additions & 8 deletions cmd/desc_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package cmd

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestDescBranchCmd(t *testing.T) {
Expand All @@ -34,17 +32,17 @@ func TestDescBranchCmd(t *testing.T) {
expect testResult
}{
{
name: "describe project with id 11 master branch",
name: "describe project master branch",
flagsMap: map[string]string{
"project": "11",
"project": "Group2/project12",
},
args: []string{"master"},
expect: pass,
},
{
name: "describing a non existent branch fails",
flagsMap: map[string]string{
"project": "11",
"project": "4",
},
args: []string{"release-99"},
expect: fail,
Expand All @@ -60,10 +58,9 @@ func TestDescBranchCmd(t *testing.T) {
args: tc.args,
}
stdout, execResult := execT.executeCommand()
require.Equal(t, tc.expect, execResult,
printFlagsTable(tc.flagsMap, stdout))
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
if tc.expect == pass {
require.Contains(t, stdout, tc.args[0], stdout)
assertStringContains(t, stdout, tc.args[0])
}
})
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/helpers_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io"
"log"
"os"
"strings"
"testing"

"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -198,3 +199,16 @@ func printFlagsTable(flagsMap map[string]string, c string) string {
table.Render()
return buff.String()
}

func assertEqualResult(t *testing.T, got, want testResult, msg string) {
if got != want {
t.Fatalf("got test result %s, want %s: \n%s",
got, want, msg)
}
}

func assertStringContains(t *testing.T, s, contains string) {
if !strings.Contains(s, contains) {
t.Fatalf("expected to see %s in %s", contains, s)
}
}
7 changes: 2 additions & 5 deletions cmd/new_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ package cmd
import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestNewBranch(t *testing.T) {
Expand Down Expand Up @@ -60,10 +58,9 @@ func TestNewBranch(t *testing.T) {
}
stdout, execResult := execT.executeCommand()
fmt.Println(stdout)
require.Equal(t, tc.expect, execResult,
printFlagsTable(tc.flagsMap, stdout))
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
if tc.expect == pass {
require.Contains(t, stdout, tc.args[0], stdout)
assertStringContains(t, stdout, tc.args[0])
if err := deleteBranch(tc.flagsMap["project"], tc.args[0]); err != nil {
tInfo(err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/new_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package cmd

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestNewUser(t *testing.T) {
Expand Down Expand Up @@ -62,7 +60,7 @@ func TestNewUser(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {

// SETUP
// Ensure that the user to be created is deleted
if tc.expect == pass {
if err := deleteUser(tc.args[0]); err != nil {
Expand All @@ -78,8 +76,10 @@ func TestNewUser(t *testing.T) {
}

stdout, execResult := execT.executeCommand()
require.Equal(t, tc.expect, execResult,
printFlagsTable(tc.flagsMap, stdout))
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
if tc.expect == pass {
assertStringContains(t, stdout, tc.args[0])
}
})
}

Expand Down

0 comments on commit 948f7e6

Please sign in to comment.