Skip to content

Commit 465d3bc

Browse files
committed
refactor(internal/testutil): Move AssertEqual function to middleware/echo/echo_test.go
1 parent b0682b8 commit 465d3bc

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

internal/testutil/testutil.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77
"reflect"
88
"strings"
9-
"testing"
109

1110
"gorm.io/driver/postgres"
1211
"gorm.io/gorm"
@@ -83,13 +82,3 @@ func DeepEqual[T any](expected, actual T, message ...interface{}) (bool, string)
8382
}
8483
return true, ""
8584
}
86-
87-
// AssertEqual compares two values and logs an error if they are not equal.
88-
func AssertEqual[T any](t *testing.T, expected, actual T, message ...interface{}) bool {
89-
t.Helper()
90-
equal, msg := DeepEqual(expected, actual, message...)
91-
if !equal {
92-
t.Errorf(msg)
93-
}
94-
return equal
95-
}

middleware/echo/echo_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ import (
1212
"github.com/labstack/echo/v4"
1313
)
1414

15+
// assertEqual compares two values and logs an error if they are not equal.
16+
func assertEqual[T any](t *testing.T, expected, actual T, message ...interface{}) bool {
17+
t.Helper()
18+
equal, msg := testutil.DeepEqual(expected, actual, message...)
19+
if !equal {
20+
t.Errorf(msg)
21+
}
22+
return equal
23+
}
24+
1525
func ExampleWithTenant() {
1626
e := echo.New()
1727

@@ -133,8 +143,8 @@ func TestWithTenant(t *testing.T) {
133143

134144
if tt.wantErr {
135145
he := handler(c).(*echo.HTTPError)
136-
testutil.AssertEqual(t, http.StatusInternalServerError, he.Code)
137-
testutil.AssertEqual(t, "forced error", he.Message)
146+
assertEqual(t, http.StatusInternalServerError, he.Code)
147+
assertEqual(t, "forced error", he.Message)
138148
return
139149
}
140150

@@ -144,10 +154,8 @@ func TestWithTenant(t *testing.T) {
144154
return
145155
}
146156

147-
// testutil.AssertEqual(t, http.StatusOK, rec.Code)
148-
testutil.AssertEqual(t, http.StatusOK, rec.Code)
149-
// testutil.AssertEqual(t, tt.want, rec.Body.String())
150-
testutil.AssertEqual(t, tt.want, rec.Body.String())
157+
assertEqual(t, http.StatusOK, rec.Code)
158+
assertEqual(t, tt.want, rec.Body.String())
151159
})
152160
}
153161
}

0 commit comments

Comments
 (0)