BREAKING CHANGE: V2 of thr SDK #12

Merged
fenpaws merged 124 commits from develop/postgresql into main 2024-07-01 20:46:28 +00:00
3 changed files with 156 additions and 2 deletions
Showing only changes of commit 26178eb64d - Show all commits

View File

@ -3,6 +3,7 @@ package postgres
import (
"context"
"fmt"
"reflect"
"testing"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
@ -344,3 +345,80 @@ func TestCreateTagAlias(t *testing.T) {
})
}
}
func TestGetAllTagAlias(t *testing.T) {
// Setup trow away container
ctx := context.Background()
container, gormDB, err := test.StartPostgresContainer(ctx)
if err != nil {
t.Fatalf("Could not start PostgreSQL container: %v", err)
}
defer container.Terminate(ctx)
// Setup Test
validTagID := models.AnthroveTagID("toothless")
validTagAliases := []models.AnthroveTagAliasName{"httyd", "dragon", "scaly"}
validTag := &models.Tag{
Name: string(validTagID),
Type: models.Character,
}
expectedResult := []models.TagAlias{
{
Name: string(validTagAliases[0]),
TagID: string(validTagID),
},
{
Name: string(validTagAliases[1]),
TagID: string(validTagID),
},
{
Name: string(validTagAliases[2]),
TagID: string(validTagID),
},
}
err = CreateTag(ctx, gormDB, validTag)
if err != nil {
t.Fatal(err)
}
for _, tagAliasName := range validTagAliases {
err = CreateTagAlias(ctx, gormDB, tagAliasName, validTagID)
}
// Test
type args struct {
ctx context.Context
db *gorm.DB
}
tests := []struct {
name string
args args
want []models.TagAlias
wantErr bool
}{
{
name: "Test 1: Get Data",
args: args{
ctx: ctx,
db: gormDB,
},
want: expectedResult,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetAllTagAlias(tt.args.ctx, tt.args.db)
if (err != nil) != tt.wantErr {
t.Errorf("GetAllTagAlias() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAllTagAlias() got = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -170,8 +170,7 @@ func (p *postgresqlConnection) CreateTagAlias(ctx context.Context, tagAliasName
}
func (p *postgresqlConnection) GetAllTagAlias(ctx context.Context) ([]models.TagAlias, error) {
//TODO implement me
panic("implement me")
return postgres.GetAllTagAlias(ctx, p.db)
}
func (p *postgresqlConnection) GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error) {

View File

@ -2116,3 +2116,80 @@ func Test_postgresqlConnection_CreateTagAlias(t *testing.T) {
})
}
}
func Test_postgresqlConnection_GetAllTagAlias(t *testing.T) {
// Setup trow away container
ctx := context.Background()
container, gormDB, err := test.StartPostgresContainer(ctx)
if err != nil {
t.Fatalf("Could not start PostgreSQL container: %v", err)
}
defer container.Terminate(ctx)
// Setup Test
validTagID := models.AnthroveTagID("toothless")
validTagAliases := []models.AnthroveTagAliasName{"httyd", "dragon", "scaly"}
validTag := &models.Tag{
Name: string(validTagID),
Type: models.Character,
}
expectedResult := []models.TagAlias{
{
Name: string(validTagAliases[0]),
TagID: string(validTagID),
},
{
Name: string(validTagAliases[1]),
TagID: string(validTagID),
},
{
Name: string(validTagAliases[2]),
TagID: string(validTagID),
},
}
err = postgres.CreateTag(ctx, gormDB, validTag)
if err != nil {
t.Fatal(err)
}
for _, tagAliasName := range validTagAliases {
err = postgres.CreateTagAlias(ctx, gormDB, tagAliasName, validTagID)
}
// Test
type args struct {
ctx context.Context
}
tests := []struct {
name string
args args
want []models.TagAlias
wantErr bool
}{
{
name: "Test 1: Get Data",
args: args{ctx: ctx},
want: expectedResult,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &postgresqlConnection{
db: gormDB,
debug: true,
}
got, err := p.GetAllTagAlias(tt.args.ctx)
if (err != nil) != tt.wantErr {
t.Errorf("GetAllTagAlias() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAllTagAlias() got = %v, want %v", got, tt.want)
}
})
}
}