Address Gadfly review on #12: helper naming + FK-backstop test
Build image / build-and-push (push) Successful in 5s

- Rename test helper intPtr → ptrInt to match the package's ptrBool sibling
  (2/5 reviewers flagged the naming inconsistency).
- Add a store-level test that drives DeletePlant into the ON DELETE RESTRICT
  foreign key so the isForeignKeyViolation string-match (→ ErrPlantInUse) is
  pinned; a driver-message change now fails here, not as a prod 500.

Skipped (advisory, non-blocking): the parseNullableInt/parseNullableString
generic-helper refactor (cosmetic, touches working code) and the documented
LIMIT 5000 backstop.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdQpdYYsTgtkJBxbcpAszi
This commit is contained in:
2026-07-18 21:47:54 -04:00
co-authored by Claude Opus 4.8
parent 78dbadf95c
commit 02e66f462f
2 changed files with 46 additions and 5 deletions
+5 -5
View File
@@ -9,7 +9,7 @@ import (
"gitea.stevedudenhoeffer.com/steve/pansy/internal/domain"
)
func intPtr(n int) *int { return &n }
func ptrInt(n int) *int { return &n }
// validPlant is a well-formed PlantInput for tests to tweak.
func validPlant(name string) PlantInput {
@@ -53,7 +53,7 @@ func TestCreatePlantIsOwnedAndTrimmed(t *testing.T) {
owner := seedUser(t, s, "[email protected]")
in := validPlant(" Purple basil ")
in.DaysToMaturity = intPtr(60)
in.DaysToMaturity = ptrInt(60)
p, err := s.CreatePlant(context.Background(), owner, in)
if err != nil {
t.Fatalf("CreatePlant: %v", err)
@@ -147,7 +147,7 @@ func TestUpdatePlantClearsDays(t *testing.T) {
s := newTestService(t, openConfig())
owner := seedUser(t, s, "[email protected]")
in := validPlant("Dill")
in.DaysToMaturity = intPtr(50)
in.DaysToMaturity = ptrInt(50)
p, _ := s.CreatePlant(context.Background(), owner, in)
// SetDays with nil clears; absent (SetDays=false) would leave it.
@@ -191,7 +191,7 @@ func TestCreatePlantValidation(t *testing.T) {
{Name: "x", Category: domain.CategoryHerb, SpacingCM: 10, Color: "nope", Icon: "🌿"}, // bad color
{Name: "x", Category: domain.CategoryHerb, SpacingCM: 10, Color: "#4a7c3f", Icon: ""}, // empty icon
{Name: strings.Repeat("x", maxPlantNameLen+1), Category: domain.CategoryHerb, SpacingCM: 10, Color: "#4a7c3f", Icon: "🌿"}, // name too long
{Name: "x", Category: domain.CategoryHerb, SpacingCM: 10, Color: "#4a7c3f", Icon: "🌿", DaysToMaturity: intPtr(0)}, // days must be >= 1
{Name: "x", Category: domain.CategoryHerb, SpacingCM: 10, Color: "#4a7c3f", Icon: "🌿", DaysToMaturity: ptrInt(0)}, // days must be >= 1
}
for i, in := range bad {
if _, err := s.CreatePlant(context.Background(), owner, in); !errors.Is(err, domain.ErrInvalidInput) {
@@ -202,7 +202,7 @@ func TestCreatePlantValidation(t *testing.T) {
// A shorthand hex (#rgb) and a set days value pass.
ok := validPlant("Thyme")
ok.Color = "#0a0"
ok.DaysToMaturity = intPtr(90)
ok.DaysToMaturity = ptrInt(90)
if _, err := s.CreatePlant(context.Background(), owner, ok); err != nil {
t.Errorf("valid plant rejected: %v", err)
}