feat(03-03): add typed path params and per-plugin rollback
Compile regex and enum constraints at route registration so malformed and unknown IDs share a 404, and named rollback errors isolate one plugin's history. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,12 +2,16 @@ package lagoon
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/backpack"
|
||||
"git.golem15.com/golem15/summercms/bonfire"
|
||||
"git.golem15.com/golem15/summercms/party"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestHistoryTableName(t *testing.T) {
|
||||
@@ -95,3 +99,27 @@ func TestOpenRequiresDSN(t *testing.T) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type stubPlugin struct{ id string }
|
||||
|
||||
func (s stubPlugin) ID() string { return s.id }
|
||||
func (s stubPlugin) Requires() []string { return nil }
|
||||
func (s stubPlugin) Register(*backpack.App) error { return nil }
|
||||
func (s stubPlugin) Boot(*backpack.App) error { return nil }
|
||||
|
||||
func TestRollbackUnknownPluginIsNamedError(t *testing.T) {
|
||||
err := RollbackLast(&gorm.DB{}, []party.Plugin{stubPlugin{id: "golem15.user"}}, "golem15.missing")
|
||||
if !errors.Is(err, ErrUnknownPlugin) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "golem15.missing") {
|
||||
t.Fatalf("error should name plugin: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollbackMissingPluginIsNamedError(t *testing.T) {
|
||||
err := RollbackLast(&gorm.DB{}, nil, "")
|
||||
if !errors.Is(err, ErrNoMigrations) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user