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 350 additions and 4 deletions
Showing only changes of commit 702870db1e - Show all commits

View File

@ -422,3 +422,177 @@ func TestGetAllTagAlias(t *testing.T) {
}) })
} }
} }
func TestGetAllTagAliasByTag(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
tagID models.AnthroveTagID
}
tests := []struct {
name string
args args
want []models.TagAlias
wantErr bool
}{
{
name: "Test 1: Valid TagID",
args: args{
ctx: ctx,
db: gormDB,
tagID: validTagID,
},
want: expectedResult,
wantErr: false,
},
{
name: "Test 2: No TagID",
args: args{
ctx: ctx,
db: gormDB,
tagID: "",
},
want: nil,
wantErr: true,
},
{
name: "Test 3: Invalid TagID",
args: args{
ctx: ctx,
db: gormDB,
tagID: "adads",
},
want: []models.TagAlias{},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetAllTagAliasByTag(tt.args.ctx, tt.args.db, tt.args.tagID)
if (err != nil) != tt.wantErr {
t.Errorf("GetAllTagAliasByTag() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAllTagAliasByTag() got = %v, want %v", got, tt.want)
}
})
}
}
func TestDeleteTagAlias(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,
}
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
tagAliasName models.AnthroveTagAliasName
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Test 1: Valid AnthroveTagAliasName",
args: args{
ctx: ctx,
db: gormDB,
tagAliasName: validTagAliases[0],
},
wantErr: false,
},
{
name: "Test 2: Invalid AnthroveTagAliasName",
args: args{
ctx: ctx,
db: gormDB,
tagAliasName: "asdad",
},
wantErr: false,
},
{
name: "Test 3: No AnthroveTagAliasName",
args: args{
ctx: ctx,
db: gormDB,
tagAliasName: "",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := DeleteTagAlias(tt.args.ctx, tt.args.db, tt.args.tagAliasName); (err != nil) != tt.wantErr {
t.Errorf("DeleteTagAlias() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

View File

@ -174,13 +174,11 @@ func (p *postgresqlConnection) GetAllTagAlias(ctx context.Context) ([]models.Tag
} }
func (p *postgresqlConnection) GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error) { func (p *postgresqlConnection) GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error) {
//TODO implement me return postgres.GetAllTagAliasByTag(ctx, p.db, tagID)
panic("implement me")
} }
func (p *postgresqlConnection) DeleteTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName) error { func (p *postgresqlConnection) DeleteTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName) error {
//TODO implement me return postgres.DeleteTagAlias(ctx, p.db, tagAliasName)
panic("implement me")
} }
func (p *postgresqlConnection) CreateTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName, tagID models.AnthroveTagID) { func (p *postgresqlConnection) CreateTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName, tagID models.AnthroveTagID) {

View File

@ -2193,3 +2193,177 @@ func Test_postgresqlConnection_GetAllTagAlias(t *testing.T) {
}) })
} }
} }
func Test_postgresqlConnection_GetAllTagAliasByTag(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
tagID models.AnthroveTagID
}
tests := []struct {
name string
args args
want []models.TagAlias
wantErr bool
}{
{
name: "Test 1: Valid TagID",
args: args{
ctx: ctx,
tagID: validTagID,
},
want: expectedResult,
wantErr: false,
},
{
name: "Test 2: No TagID",
args: args{
ctx: ctx,
tagID: "",
},
want: nil,
wantErr: true,
},
{
name: "Test 3: Invalid TagID",
args: args{
ctx: ctx,
tagID: "adads",
},
want: []models.TagAlias{},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &postgresqlConnection{
db: gormDB,
debug: true,
}
got, err := p.GetAllTagAliasByTag(tt.args.ctx, tt.args.tagID)
if (err != nil) != tt.wantErr {
t.Errorf("GetAllTagAliasByTag() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAllTagAliasByTag() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_postgresqlConnection_DeleteTagAlias(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,
}
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
tagAliasName models.AnthroveTagAliasName
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "Test 1: Valid AnthroveTagAliasName",
args: args{
ctx: ctx,
tagAliasName: validTagAliases[0],
},
wantErr: false,
},
{
name: "Test 2: Invalid AnthroveTagAliasName",
args: args{
ctx: ctx,
tagAliasName: "asdad",
},
wantErr: false,
},
{
name: "Test 3: No AnthroveTagAliasName",
args: args{
ctx: ctx,
tagAliasName: "",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &postgresqlConnection{
db: gormDB,
debug: true,
}
if err := p.DeleteTagAlias(tt.args.ctx, tt.args.tagAliasName); (err != nil) != tt.wantErr {
t.Errorf("DeleteTagAlias() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}