Fix: image alias put query
Some checks failed
Some checks failed
This commit is contained in:
@@ -2,6 +2,7 @@ package implements
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.konchin.com/go2025/backend/models"
|
||||
"gitea.konchin.com/go2025/backend/tracing"
|
||||
@@ -184,6 +185,14 @@ func (self *BunDatabase) UpdateAliases(
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.NewSelect().
|
||||
Model(&aliases).
|
||||
Where("name IN (?)", bun.In(aliasNames)).
|
||||
Scan(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var rels []models.AliasImage
|
||||
for _, alias := range aliases {
|
||||
rels = append(rels, models.AliasImage{
|
||||
@@ -191,6 +200,9 @@ func (self *BunDatabase) UpdateAliases(
|
||||
ImageId: imageId,
|
||||
})
|
||||
}
|
||||
tracing.Logger.Ctx(ctx).
|
||||
Debug("wtf is happening",
|
||||
zap.String("rels", fmt.Sprintf("%+v", rels)))
|
||||
_, err = tx.NewInsert().
|
||||
Model(&rels).
|
||||
On(`CONFLICT ("alias_id", "image_id") DO NOTHING`).
|
||||
|
||||
@@ -11,15 +11,45 @@ type putImageAliasPayload struct {
|
||||
}
|
||||
|
||||
func Test_03_PutImageAliases(t *testing.T) {
|
||||
payload := putImageAliasPayload{
|
||||
Aliases: []string{"huh"},
|
||||
}
|
||||
resp, err := client.R().
|
||||
SetBody(payload).
|
||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
||||
image.Id))
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to put image alias")
|
||||
}
|
||||
t.Run("Put one alias", func(t *testing.T) {
|
||||
payload := putImageAliasPayload{
|
||||
Aliases: []string{"huh"},
|
||||
}
|
||||
resp, err := client.R().
|
||||
SetBody(payload).
|
||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
||||
image.Id))
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to put image alias")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Put many alias", func(t *testing.T) {
|
||||
payload := putImageAliasPayload{
|
||||
Aliases: []string{"huh", "testalias1", "testalias2"},
|
||||
}
|
||||
resp, err := client.R().
|
||||
SetBody(payload).
|
||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
||||
image.Id))
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to put image alias")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Remove alias", func(t *testing.T) {
|
||||
payload := putImageAliasPayload{
|
||||
Aliases: []string{"huh", "testalias1"},
|
||||
}
|
||||
resp, err := client.R().
|
||||
SetBody(payload).
|
||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
||||
image.Id))
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to put image alias")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import (
|
||||
)
|
||||
|
||||
func Test_07_DeleteAlias(t *testing.T) {
|
||||
deleteId := aliases[0].Id
|
||||
|
||||
resp, err := client.R().
|
||||
Delete(fmt.Sprintf("http://localhost:8080/api/alias/%d",
|
||||
aliases[0].Id))
|
||||
deleteId))
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("failed to delete alias")
|
||||
@@ -23,7 +25,10 @@ func Test_07_DeleteAlias(t *testing.T) {
|
||||
t.Fatal("failed to get aliases")
|
||||
}
|
||||
|
||||
if len(aliases) > 0 {
|
||||
t.Fatal("alias not deleted")
|
||||
for _, alias := range aliases {
|
||||
if alias.Id == deleteId {
|
||||
t.Logf("%+v", resp)
|
||||
t.Fatal("alias not deleted")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user