Skip to content

Commit 7d4ba3e

Browse files
committed
replace testify with standard lib to resolve unknown panic errors
References: * stretchr/testify#316 * stretchr/testify#119
1 parent 8233efa commit 7d4ba3e

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ windows: create_bin_dir
3737
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINDIR}/${BINARY}-windows-${GOARCH}.exe .
3838

3939
test: getdep
40-
echo Performing a go test
41-
go test ./... -v -failfast
40+
rm -f ~/.gitlabctl.yaml
41+
go test -v ./... -failfast
4242

4343
coverage: getdep
44-
echo Performing test with coverage
45-
go test ./... -v -failfast -coverprofile=coverage.txt -covermode=atomic
44+
go test -v ./... -failfast -coverprofile=coverage.txt -covermode=atomic
4645

4746
getdep:
4847
go get -v ./...

cmd/desc_branch_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ package cmd
2222

2323
import (
2424
"testing"
25-
26-
"github.com/stretchr/testify/require"
2725
)
2826

2927
func TestDescBranchCmd(t *testing.T) {
@@ -34,17 +32,17 @@ func TestDescBranchCmd(t *testing.T) {
3432
expect testResult
3533
}{
3634
{
37-
name: "describe project with id 11 master branch",
35+
name: "describe project master branch",
3836
flagsMap: map[string]string{
39-
"project": "11",
37+
"project": "Group2/project12",
4038
},
4139
args: []string{"master"},
4240
expect: pass,
4341
},
4442
{
4543
name: "describing a non existent branch fails",
4644
flagsMap: map[string]string{
47-
"project": "11",
45+
"project": "4",
4846
},
4947
args: []string{"release-99"},
5048
expect: fail,
@@ -60,10 +58,9 @@ func TestDescBranchCmd(t *testing.T) {
6058
args: tc.args,
6159
}
6260
stdout, execResult := execT.executeCommand()
63-
require.Equal(t, tc.expect, execResult,
64-
printFlagsTable(tc.flagsMap, stdout))
61+
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
6562
if tc.expect == pass {
66-
require.Contains(t, stdout, tc.args[0], stdout)
63+
assertStringContains(t, stdout, tc.args[0])
6764
}
6865
})
6966
}

cmd/helpers_for_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"io"
2727
"log"
2828
"os"
29+
"strings"
2930
"testing"
3031

3132
"github.com/olekukonko/tablewriter"
@@ -198,3 +199,16 @@ func printFlagsTable(flagsMap map[string]string, c string) string {
198199
table.Render()
199200
return buff.String()
200201
}
202+
203+
func assertEqualResult(t *testing.T, got, want testResult, msg string) {
204+
if got != want {
205+
t.Fatalf("got test result %s, want %s: \n%s",
206+
got, want, msg)
207+
}
208+
}
209+
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)
213+
}
214+
}

cmd/new_branch_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ package cmd
2323
import (
2424
"fmt"
2525
"testing"
26-
27-
"github.com/stretchr/testify/require"
2826
)
2927

3028
func TestNewBranch(t *testing.T) {
@@ -60,10 +58,9 @@ func TestNewBranch(t *testing.T) {
6058
}
6159
stdout, execResult := execT.executeCommand()
6260
fmt.Println(stdout)
63-
require.Equal(t, tc.expect, execResult,
64-
printFlagsTable(tc.flagsMap, stdout))
61+
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
6562
if tc.expect == pass {
66-
require.Contains(t, stdout, tc.args[0], stdout)
63+
assertStringContains(t, stdout, tc.args[0])
6764
if err := deleteBranch(tc.flagsMap["project"], tc.args[0]); err != nil {
6865
tInfo(err)
6966
}

cmd/new_user_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ package cmd
2222

2323
import (
2424
"testing"
25-
26-
"github.com/stretchr/testify/require"
2725
)
2826

2927
func TestNewUser(t *testing.T) {
@@ -62,7 +60,7 @@ func TestNewUser(t *testing.T) {
6260

6361
for _, tc := range tt {
6462
t.Run(tc.name, func(t *testing.T) {
65-
63+
// SETUP
6664
// Ensure that the user to be created is deleted
6765
if tc.expect == pass {
6866
if err := deleteUser(tc.args[0]); err != nil {
@@ -78,8 +76,10 @@ func TestNewUser(t *testing.T) {
7876
}
7977

8078
stdout, execResult := execT.executeCommand()
81-
require.Equal(t, tc.expect, execResult,
82-
printFlagsTable(tc.flagsMap, stdout))
79+
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
80+
if tc.expect == pass {
81+
assertStringContains(t, stdout, tc.args[0])
82+
}
8383
})
8484
}
8585

0 commit comments

Comments
 (0)