From ea9b1152372f29adfa725914b3e4276577089179 Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 16 Jul 2024 11:17:14 +0200 Subject: [PATCH] test: fixed tests Signed-off-by: SoXX --- internal/postgres/user_test.go | 19 ++++++++++++++++++- pkg/database/postgres_test.go | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/internal/postgres/user_test.go b/internal/postgres/user_test.go index a57eb10..006dc9c 100644 --- a/internal/postgres/user_test.go +++ b/internal/postgres/user_test.go @@ -573,13 +573,30 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) { t.Errorf("GetAllUserFavoritesWithPagination() error = %v, wantErr %v", err, tt.wantErr) return } - if !reflect.DeepEqual(got, tt.want) { + if !checkFavoritePosts(got, tt.want) { t.Errorf("GetAllUserFavoritesWithPagination() got = %v, want %v", got, tt.want) } }) } } +func checkFavoritePosts(got *models.FavoriteList, want *models.FavoriteList) bool { + if got == nil && want == nil { + return true + } else if got == nil || want == nil { + return false + } + + for i, post := range got.Posts { + if post.ID == want.Posts[i].ID { + } else { + return false + } + } + + return true +} + func TestGetUserFavoritesCount(t *testing.T) { // Setup trow away container ctx := context.Background() diff --git a/pkg/database/postgres_test.go b/pkg/database/postgres_test.go index b29dba0..9de1078 100644 --- a/pkg/database/postgres_test.go +++ b/pkg/database/postgres_test.go @@ -1556,7 +1556,7 @@ func Test_postgresqlConnection_GetUserFavoriteWithPagination(t *testing.T) { t.Errorf("GetAllUserFavoritesWithPagination() error = %v, wantErr %v", err, tt.wantErr) return } - if !reflect.DeepEqual(got, tt.want) { + if !checkFavoritePosts(got, tt.want) { t.Errorf("GetAllUserFavoritesWithPagination() got = %v, want %v", got, tt.want) } }) @@ -3654,3 +3654,20 @@ func Test_postgresqlConnection_CreatePostInBatch(t *testing.T) { }) } } + +func checkFavoritePosts(got *models.FavoriteList, want *models.FavoriteList) bool { + if got == nil && want == nil { + return true + } else if got == nil || want == nil { + return false + } + + for i, post := range got.Posts { + if post.ID == want.Posts[i].ID { + } else { + return false + } + } + + return true +}