Compare commits

...

4 Commits

Author SHA1 Message Date
1540e5bbce Fix : error assignment in CreateKnownSources test case
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 3m3s
Gitea Build Check / Build (push) Successful in 3m6s
Signed-off-by: SoXX <soxx@anthrove.art>
2025-01-21 15:47:05 +01:00
9669ed293d feat: Add CreateKnownSources function and test implementation
Some checks failed
Gitea Build Check / Build (pull_request) Failing after 2m54s
Signed-off-by: SoXX <soxx@anthrove.art>
2025-01-21 15:25:36 +01:00
d52b8f7f81 feat: Add new columns "enabled" and "meta" to "Source" table with defaults
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 3m14s
Signed-off-by: SoXX <soxx@anthrove.art>
2025-01-21 15:10:48 +01:00
baa49d0a81 feat: Add migration to change 'name' column type to TEXT in 'Pool' table
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 4m9s
Signed-off-by: SoXX <soxx@anthrove.art>
2025-01-21 15:03:07 +01:00
4 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,5 @@
-- +migrate Up
ALTER TABLE "Pool"
ALTER
COLUMN name TYPE TEXT;

View File

@ -0,0 +1,5 @@
-- +migrate Up
ALTER TABLE "Source"
ADD COLUMN enabled BOOL DEFAULT FALSE,
ADD COLUMN meta JSON DEFAULT '{}';

View File

@ -245,3 +245,37 @@ func DeleteSource(ctx context.Context, id models.SourceID) error {
utils.HandleEvent(span, localLogger, "Source deleted successfully")
return nil
}
func CreateKnownSources(ctx context.Context) ([]models.Source, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateKnownSources")
defer span.End()
if client == nil {
return nil, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DatabaseIsNotConnected})
}
sources := []models.Source{
{
DisplayName: "e621",
Domain: "e621.net",
Icon: "https://e621.net/safari-pinned-tab.svg",
},
{
DisplayName: "Fur Affinity",
Domain: "furaffinity.net",
Icon: "https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png",
},
}
result := client.WithContext(ctx).Model(models.Source{}).CreateInBatches(sources, len(sources))
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return nil, utils.HandleError(ctx, span, localLogger, &otterError.Database{Reason: otterError.DuplicateKey})
}
return nil, utils.HandleError(ctx, span, localLogger, result.Error)
}
utils.HandleEvent(span, localLogger, "Batch posts created successfully")
return sources, nil
}

View File

@ -537,6 +537,34 @@ func TestDeleteSource(t *testing.T) {
}
}
func TestCreateKnownSources(t *testing.T) {
// Setup trow away container
ctx := context.Background()
container, gormDB, err := test.StartPostgresContainer(ctx)
if err != nil {
logger.Fatalf("Could not start PostgreSQL container: %v", err)
}
client = gormDB
// Setup open telemetry
tracer = otel.Tracer(tracingName)
hook := otellogrus.NewHook(tracingName)
logger.AddHook(hook)
defer container.Terminate(ctx)
// -- -- Tests
t.Run("CreateKnownSources", func(t *testing.T) {
_, err := CreateKnownSources(ctx)
if err != nil {
t.Errorf("DeleteSource() error = %v", err)
}
})
}
func checkSourceID(got models.Source, want models.Source) bool {
if got.ID != want.ID {
return false