From c0cae140f12bc978e0a6a87171e9d545406f804e Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 25 Jun 2024 14:50:56 +0200 Subject: [PATCH] test(postgres): finished test migrations to generic orm base Signed-off-by: SoXX --- pkg/database/postgres_test.go | 55 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/pkg/database/postgres_test.go b/pkg/database/postgres_test.go index d14a354..f4cd28f 100644 --- a/pkg/database/postgres_test.go +++ b/pkg/database/postgres_test.go @@ -3,10 +3,11 @@ package database import ( "context" "fmt" + "testing" + "git.dragse.it/anthrove/otter-space-sdk/internal/postgres" "git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/test" - "testing" ) func TestNewPostgresqlConnection(t *testing.T) { @@ -96,7 +97,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) { // Setup Test source := &models.Source{ - BaseModel: models.BaseModel{ID: fmt.Sprintf("%025s", "1")}, + BaseModel: models.BaseModel[models.AnthroveSourceID]{ID: models.AnthroveSourceID(fmt.Sprintf("%025s", "1"))}, DisplayName: "e621", Domain: "e621.net", Icon: "icon.e621.net", @@ -124,7 +125,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "1", - sourceID: models.AnthroveSourceID(source.ID), + sourceID: source.ID, accountId: "e1", accountUsername: "marius", }, @@ -135,7 +136,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "2", - sourceID: models.AnthroveSourceID(source.ID), + sourceID: source.ID, accountId: "e1", accountUsername: "marius", }, @@ -146,7 +147,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "", - sourceID: models.AnthroveSourceID(source.ID), + sourceID: source.ID, accountId: "e1", accountUsername: "marius", }, @@ -168,7 +169,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "1", - sourceID: models.AnthroveSourceID(source.ID), + sourceID: source.ID, accountId: "", accountUsername: "marius", }, @@ -179,7 +180,7 @@ func Test_postgresqlConnection_CreateUserWithRelationToSource(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "1", - sourceID: models.AnthroveSourceID(source.ID), + sourceID: source.ID, accountId: "aa", accountUsername: "", }, @@ -280,8 +281,8 @@ func Test_postgresqlConnection_CreatePost(t *testing.T) { // Setup Tests validPost := &models.Post{ - BaseModel: models.BaseModel{ - ID: fmt.Sprintf("%025s", "1"), + BaseModel: models.BaseModel[models.AnthrovePostID]{ + ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")), }, Rating: "safe", } @@ -342,8 +343,8 @@ func Test_postgresqlConnection_CreateTagAndReferenceToPost(t *testing.T) { // Setup Test post := &models.Post{ - BaseModel: models.BaseModel{ - ID: fmt.Sprintf("%025s", "1"), + BaseModel: models.BaseModel[models.AnthrovePostID]{ + ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")), }, Rating: "safe", } @@ -373,7 +374,7 @@ func Test_postgresqlConnection_CreateTagAndReferenceToPost(t *testing.T) { name: "Test 1: Valid PostID and Tag", args: args{ ctx: ctx, - anthrovePostID: models.AnthrovePostID(post.ID), + anthrovePostID: post.ID, anthroveTag: tag, }, wantErr: false, @@ -382,7 +383,7 @@ func Test_postgresqlConnection_CreateTagAndReferenceToPost(t *testing.T) { name: "Test 2: Valid PostID and no Tag", args: args{ ctx: ctx, - anthrovePostID: models.AnthrovePostID(post.ID), + anthrovePostID: post.ID, anthroveTag: nil, }, wantErr: true, @@ -430,8 +431,8 @@ func Test_postgresqlConnection_CreateReferenceBetweenPostAndSource(t *testing.T) // Setup Test post := &models.Post{ - BaseModel: models.BaseModel{ - ID: fmt.Sprintf("%025s", "1"), + BaseModel: models.BaseModel[models.AnthrovePostID]{ + ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")), }, Rating: "safe", } @@ -466,7 +467,7 @@ func Test_postgresqlConnection_CreateReferenceBetweenPostAndSource(t *testing.T) name: "Test 1: Valid AnthrovePostID and anthroveSourceDomain", args: args{ ctx: ctx, - anthrovePostID: models.AnthrovePostID(post.ID), + anthrovePostID: post.ID, sourceDomain: "e621.net", }, wantErr: false, @@ -527,8 +528,8 @@ func Test_postgresqlConnection_CreateReferenceBetweenUserAndPost(t *testing.T) { } post := &models.Post{ - BaseModel: models.BaseModel{ - ID: fmt.Sprintf("%025s", "1"), + BaseModel: models.BaseModel[models.AnthrovePostID]{ + ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")), }, Rating: "safe", } @@ -554,7 +555,7 @@ func Test_postgresqlConnection_CreateReferenceBetweenUserAndPost(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "1", - anthrovePostID: models.AnthrovePostID(post.ID), + anthrovePostID: post.ID, }, wantErr: false, }, @@ -615,8 +616,8 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) { } post := &models.Post{ - BaseModel: models.BaseModel{ - ID: fmt.Sprintf("%025s", "1"), + BaseModel: models.BaseModel[models.AnthrovePostID]{ + ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")), }, Rating: "safe", } @@ -626,7 +627,7 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) { t.Fatal(err) } - err = postgres.CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", models.AnthrovePostID(post.ID)) + err = postgres.CreateReferenceBetweenUserAndPost(ctx, gormDB, "1", post.ID) if err != nil { t.Fatal(err) } @@ -648,7 +649,7 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "1", - anthrovePostID: models.AnthrovePostID(post.ID), + anthrovePostID: post.ID, }, want: true, wantErr: false, @@ -668,7 +669,7 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) { args: args{ ctx: ctx, anthroveUserID: "123", - anthrovePostID: models.AnthrovePostID(post.ID), + anthrovePostID: post.ID, }, want: false, wantErr: false, @@ -714,8 +715,8 @@ func Test_postgresqlConnection_GetPostByAnthroveID(t *testing.T) { // Setup Tests post := &models.Post{ - BaseModel: models.BaseModel{ - ID: fmt.Sprintf("%025s", "1"), + BaseModel: models.BaseModel[models.AnthrovePostID]{ + ID: models.AnthrovePostID(fmt.Sprintf("%025s", "1")), }, Rating: "safe", } @@ -740,7 +741,7 @@ func Test_postgresqlConnection_GetPostByAnthroveID(t *testing.T) { name: "Test 1: Valid anthrovePostID", args: args{ ctx: ctx, - anthrovePost: models.AnthrovePostID(post.ID), + anthrovePost: post.ID, }, want: post, wantErr: false,