Feat: auto delete alias when unused
Some checks failed
Some checks failed
This commit is contained in:
5
Makefile
5
Makefile
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: all swagger install postgres test test-ci mac \
|
.PHONY: all swagger install postgres test test-ci mac reset \
|
||||||
docker docker-quiet docker-clean
|
docker docker-quiet docker-clean
|
||||||
|
|
||||||
SWAG ?= go run github.com/swaggo/swag/cmd/swag@v1.16.4
|
SWAG ?= go run github.com/swaggo/swag/cmd/swag@v1.16.4
|
||||||
@@ -14,6 +14,9 @@ all: swagger docker-build-native docker
|
|||||||
|
|
||||||
mac: swagger docker-build-run docker
|
mac: swagger docker-build-run docker
|
||||||
|
|
||||||
|
reset:
|
||||||
|
$(COMPOSE) exec backend reset
|
||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
$(SWAG) fmt
|
$(SWAG) fmt
|
||||||
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
|
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ func (self *BunDatabase) UpdateAliases(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.NewDelete().
|
_, err = tx.NewDelete().
|
||||||
Model((*models.AliasImage)(nil)).
|
Model((*models.AliasImage)(nil)).
|
||||||
Where("image_id = ?", imageId).
|
Where("image_id = ?", imageId).
|
||||||
@@ -214,6 +215,14 @@ func (self *BunDatabase) UpdateAliases(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = tx.NewDelete().
|
||||||
|
Model((*models.Alias)(nil)).
|
||||||
|
Where("NOT EXISTS (?)", tx.NewSelect().
|
||||||
|
Model((*models.AliasImage)(nil)).
|
||||||
|
Where("alias.id = alias_image.alias_id").
|
||||||
|
Limit(1)).
|
||||||
|
Exec(ctx)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var client *resty.Client
|
|||||||
func Test_00_Healthz(t *testing.T) {
|
func Test_00_Healthz(t *testing.T) {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
Get("http://localhost:8080/healthz")
|
Get("/healthz")
|
||||||
if err == nil && resp.StatusCode() == http.StatusOK {
|
if err == nil && resp.StatusCode() == http.StatusOK {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -24,4 +24,5 @@ func Test_00_Healthz(t *testing.T) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
client = resty.New()
|
client = resty.New()
|
||||||
|
client.SetBaseURL("http://localhost:8080")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ func Test_03_PutImageAliases(t *testing.T) {
|
|||||||
}
|
}
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
SetBody(payload).
|
SetBody(payload).
|
||||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
Put(fmt.Sprintf("/api/image/%d/aliases", image.Id))
|
||||||
image.Id))
|
|
||||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||||
t.Logf("%+v", resp)
|
t.Logf("%+v", resp)
|
||||||
t.Fatal("failed to put image alias")
|
t.Fatal("failed to put image alias")
|
||||||
@@ -45,11 +44,24 @@ func Test_03_PutImageAliases(t *testing.T) {
|
|||||||
}
|
}
|
||||||
resp, err := client.R().
|
resp, err := client.R().
|
||||||
SetBody(payload).
|
SetBody(payload).
|
||||||
Put(fmt.Sprintf("http://localhost:8080/api/image/%d/aliases",
|
Put(fmt.Sprintf("/api/image/%d/aliases", image.Id))
|
||||||
image.Id))
|
|
||||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||||
t.Logf("%+v", resp)
|
t.Logf("%+v", resp)
|
||||||
t.Fatal("failed to put image alias")
|
t.Fatal("failed to put image alias")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp, err = client.R().
|
||||||
|
SetResult(&aliases).
|
||||||
|
Get("/api/aliases")
|
||||||
|
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||||
|
t.Logf("%+v", resp)
|
||||||
|
t.Fatal("failed to get aliases")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, alias := range aliases {
|
||||||
|
if alias.Name == "testalias2" {
|
||||||
|
t.Fatal("alias should be deleted")
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user