Skip to content

Commit

Permalink
refactor(internal/testutil): Move AssertEqual function to `middlewa…
Browse files Browse the repository at this point in the history
…re/echo/echo_test.go`
  • Loading branch information
bartventer committed May 23, 2024
1 parent b0682b8 commit 465d3bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
11 changes: 0 additions & 11 deletions internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"reflect"
"strings"
"testing"

"gorm.io/driver/postgres"
"gorm.io/gorm"
Expand Down Expand Up @@ -83,13 +82,3 @@ func DeepEqual[T any](expected, actual T, message ...interface{}) (bool, string)
}
return true, ""
}

// AssertEqual compares two values and logs an error if they are not equal.
func AssertEqual[T any](t *testing.T, expected, actual T, message ...interface{}) bool {
t.Helper()
equal, msg := DeepEqual(expected, actual, message...)
if !equal {
t.Errorf(msg)
}
return equal
}
20 changes: 14 additions & 6 deletions middleware/echo/echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ import (
"github.com/labstack/echo/v4"
)

// assertEqual compares two values and logs an error if they are not equal.
func assertEqual[T any](t *testing.T, expected, actual T, message ...interface{}) bool {
t.Helper()
equal, msg := testutil.DeepEqual(expected, actual, message...)
if !equal {
t.Errorf(msg)
}
return equal
}

func ExampleWithTenant() {
e := echo.New()

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

if tt.wantErr {
he := handler(c).(*echo.HTTPError)
testutil.AssertEqual(t, http.StatusInternalServerError, he.Code)
testutil.AssertEqual(t, "forced error", he.Message)
assertEqual(t, http.StatusInternalServerError, he.Code)
assertEqual(t, "forced error", he.Message)
return
}

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

// testutil.AssertEqual(t, http.StatusOK, rec.Code)
testutil.AssertEqual(t, http.StatusOK, rec.Code)
// testutil.AssertEqual(t, tt.want, rec.Body.String())
testutil.AssertEqual(t, tt.want, rec.Body.String())
assertEqual(t, http.StatusOK, rec.Code)
assertEqual(t, tt.want, rec.Body.String())
})
}
}

0 comments on commit 465d3bc

Please sign in to comment.