check / check (push) Waiting to run
Target.MaxRetries (max_retries) becomes Target.MaxAttempts (max_attempts), and the form field, parser and ceiling are renamed to match. The column is NOT NULL and a check constraint refuses a value below 1, so every target, whatever its type, is stored with at least 1. 1 is a single attempt with no circuit breaker; above 1 retries behind the breaker up to that many attempts. Both target forms refuse 0 and less; a blank field on the add target form gives 1, and on the edit form keeps the stored value. The target page shows the plain number, and the README's two paragraphs on 0 against 1 become one sentence. Model: opus-5-5
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package database_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/webhooker/internal/database"
|
|
"sneak.berlin/go/webhooker/internal/database/databasetest"
|
|
)
|
|
|
|
// TestEventDBCreateOmitsAssociations covers the connection-level
|
|
// guard directly: a Delivery carrying its Event and Target in
|
|
// memory, written through the manager's handle, must store only the
|
|
// delivery row.
|
|
func TestEventDBCreateOmitsAssociations(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
webhookID := uuid.New().String()
|
|
|
|
mgr := databasetest.NewWebhookDBManager(t, t.TempDir())
|
|
|
|
db, err := mgr.GetDB(webhookID)
|
|
require.NoError(t, err)
|
|
|
|
target := database.Target{
|
|
WebhookID: webhookID,
|
|
Name: "leaky-target",
|
|
Type: database.TargetTypeSlack,
|
|
Config: `{"webhookUrl":"https://hooks.example/secret"}`,
|
|
MaxAttempts: 1,
|
|
}
|
|
target.ID = uuid.New().String()
|
|
|
|
event := database.Event{
|
|
WebhookID: webhookID,
|
|
EntrypointID: uuid.New().String(),
|
|
Method: "POST",
|
|
Headers: `{}`,
|
|
Body: `{}`,
|
|
}
|
|
event.ID = uuid.New().String()
|
|
|
|
d := &database.Delivery{
|
|
EventID: event.ID,
|
|
TargetID: target.ID,
|
|
Status: database.DeliveryStatusPending,
|
|
Event: event,
|
|
Target: target,
|
|
}
|
|
d.ID = uuid.New().String()
|
|
|
|
require.NoError(t, db.Create(d).Error)
|
|
require.NoError(t, db.Model(d).
|
|
Update("status", database.DeliveryStatusDelivered).
|
|
Error)
|
|
|
|
// The file has no targets table, so the create and update above
|
|
// would have failed had GORM tried to save the target.
|
|
assert.False(t, db.Migrator().HasTable(&database.Target{}))
|
|
require.NoError(t, mgr.CloseAll())
|
|
}
|