Skip to content

Dev#5

Merged
itsLeonB merged 2 commits into
mainfrom
dev
Oct 8, 2025
Merged

Dev#5
itsLeonB merged 2 commits into
mainfrom
dev

Conversation

@itsLeonB

@itsLeonB itsLeonB commented Oct 8, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added bulk insert and bulk delete operations for repositories.
  • Refactor
    • Renamed the bulk insert API to a new name; previous name replaced.
  • Tests
    • Updated tests to cover new/renamed bulk operations; added mocking support.
  • Chores
    • Expanded build/test commands with coverage and conditional guards.
    • Added mock generation script and Git pre-push hook management.
    • Introduced a new mocking library dependency.

@coderabbitai

coderabbitai Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Renames BatchInsert to InsertMany and adds DeleteMany in the generic GORM repository. Updates tests accordingly. Introduces GoMock mocks and a script to generate them. Adds make targets for testing, coverage, mocks, and git pre-push hook management. Updates pre-push script to use make test. Adds go.uber.org/mock dependency.

Changes

Cohort / File(s) Summary of Changes
Repository API updates
gorm_repository.go, test/repository_test.go
Rename BatchInsertInsertMany; add DeleteMany in interface and implementation; adjust tests to call InsertMany and update assertions.
Mocks and mocking tooling
go.mod, gorm_repository_mock.go, gorm_transactor_mock.go, scripts/gen-mocks.sh
Add go.uber.org/mock v0.6.0; add GoMock-generated mocks for Repository[T] and Transactor; introduce script to auto-generate mocks alongside source interfaces.
Build/test orchestration
Makefile, scripts/git-pre-push.sh
Add TEST_DIR, COVER_PKG; redefine phony targets: help, lint, test, test-verbose, test-coverage, test-coverage-html, test-clean, mock, install-pre-push-hook, uninstall-pre-push-hook; guard tests when no tests exist; new mock generation target; pre-push script uses make test instead of make test-all.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Make as Makefile
  participant Go as go toolchain
  participant Git as Git Hook

  Dev->>Make: make install-pre-push-hook
  Make->>Git: Install scripts/git-pre-push.sh as pre-push (chmod +x)
  Note right of Git: Hook installed

  Dev->>Git: git push
  Git->>Make: run "make test"
  alt Tests directory exists
    Make->>Go: go test ./... (with coverage when requested)
    Go-->>Make: pass/fail
  else No tests found
    Make-->>Git: Skip test targets
  end
  Git-->>Dev: Allow/deny push
Loading
sequenceDiagram
  autonumber
  actor Svc as Service
  participant Repo as Repository[T]
  participant DB as GORM

  rect rgb(234, 248, 255)
  note over Repo,DB: New insert flow
  Svc->>Repo: InsertMany(ctx, models)
  Repo->>DB: Create(&models)
  DB-->>Repo: error or inserted models
  Repo-->>Svc: models, error
  end

  rect rgb(255, 240, 240)
  note over Repo,DB: New delete flow
  Svc->>Repo: DeleteMany(ctx, models)
  Repo->>DB: Unscoped().Delete(&models)
  DB-->>Repo: error or nil
  Repo-->>Svc: error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • initial pkg #1 — Earlier CRUD repository introduction where BatchInsert was originally added; directly related to the rename to InsertMany and the addition of DeleteMany.

Poem

I tap my paws on Makefile ground,
New hooks and mocks hop all around.
InsertMany seeds a clover bed,
DeleteMany clears what’s shed.
Pre-push tests—thump, thump—okay!
With carrots cached, I code all day. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title “Dev” is a vague, single word that conveys no information about the substantive updates in this pull request, which include extensive Makefile enhancements and renaming/adding repository methods. It does not summarize the main changes nor give reviewers insight into the scope of work. A more descriptive title would aid in scanning history and understanding the intent at a glance. Please revise the pull request title to clearly summarize the primary change, for example “Add InsertMany/DeleteMany to repository and update Makefile with new test and mock targets.”
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7dd578 and c61b206.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (8)
  • Makefile (1 hunks)
  • go.mod (1 hunks)
  • gorm_repository.go (3 hunks)
  • gorm_repository_mock.go (1 hunks)
  • gorm_transactor_mock.go (1 hunks)
  • scripts/gen-mocks.sh (1 hunks)
  • scripts/git-pre-push.sh (1 hunks)
  • test/repository_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
gorm_repository_mock.go (1)
gorm_repository.go (1)
  • Specification (35-40)
🪛 checkmake (0.2.2)
Makefile

[warning] 15-15: Target body for "help" exceeds allowed length of 5 (10).

(maxbodylength)


[warning] 30-30: Target body for "test" exceeds allowed length of 5 (6).

(maxbodylength)


[warning] 4-4: Missing required phony target "all"

(minphony)


[warning] 4-4: Missing required phony target "clean"

(minphony)


[warning] 4-4: Missing required phony target "test"

(minphony)

🔇 Additional comments (5)
test/repository_test.go (1)

193-222: LGTM! Clean refactor from BatchInsert to InsertMany.

The test has been properly updated to reflect the method rename, with all assertions and error messages consistently updated. The test logic and coverage remain sound.

gorm_repository_mock.go (1)

1-160: LGTM! Generated mock follows standard GoMock patterns.

This is a generated file that properly mocks the Repository interface with all CRUD operations including the new InsertMany and DeleteMany methods. The structure and implementation follow standard GoMock conventions.

Makefile (3)

1-2: LGTM! Clear variable definitions.

The TEST_DIR and COVER_PKG variables make the test targets more maintainable and configurable.


72-73: LGTM! Mock generation target.

The new mock target provides a convenient way to regenerate mocks.


4-13: Static analysis hints are mostly pedantic.

The checkmake warnings about missing "all", "clean", and "test" phony targets, and body length limits are stylistic preferences rather than functional issues. The "test" target is actually declared (line 6), so that warning is incorrect.

These can be safely ignored unless the project has specific Makefile style requirements. The current structure is clear and functional.

Comment thread Makefile
Comment on lines +30 to +70
test:
@echo "Running all tests..."
go test ./test/...
@if [ -d $(TEST_DIR) ]; then \
go test $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi

test-verbose:
@echo "Running all tests with verbose output..."
go test -v ./test/...
@if [ -d $(TEST_DIR) ]; then \
go test -v $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi

test-coverage:
@echo "Running all tests with coverage report..."
go test -v -cover -coverprofile=coverage.out -coverpkg=./... ./test/...
@if [ -d $(TEST_DIR) ]; then \
go test -v -cover -coverprofile=coverage.out -coverpkg=$(COVER_PKG) $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi

test-coverage-html:
@echo "Running all tests and generating HTML coverage report..."
go test -v -cover -coverprofile=coverage.out -coverpkg=./... ./test/...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
@if [ -d $(TEST_DIR) ]; then \
go test -v -cover -coverprofile=coverage.out -coverpkg=$(COVER_PKG) $(TEST_DIR)/... && \
go tool cover -html=coverage.out -o coverage.html && \
echo "Coverage report generated: coverage.html"; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi

test-clean:
@echo "Cleaning test cache and running tests..."
go clean -testcache && go test -v ./test/...
@if [ -d $(TEST_DIR) ]; then \
go clean -testcache && go test -v $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Conditional guards silently skip tests when TEST_DIR is missing.

All test targets now check for TEST_DIR existence and echo a skip message if it's missing. While this prevents errors, it could mask issues if the directory is accidentally deleted, moved, or misnamed.

Consider whether the targets should fail loudly (exit with error) when TEST_DIR is expected but missing, especially in CI/CD environments where silent skips could give false confidence.

Example alternative approach:

 test:
 	@echo "Running all tests..."
 	@if [ -d $(TEST_DIR) ]; then \
 		go test $(TEST_DIR)/...; \
 	else \
-		echo "No tests found in $(TEST_DIR), skipping."; \
+		echo "ERROR: Test directory $(TEST_DIR) not found!"; \
+		exit 1; \
 	fi
🧰 Tools
🪛 checkmake (0.2.2)

[warning] 30-30: Target body for "test" exceeds allowed length of 5 (6).

(maxbodylength)

🤖 Prompt for AI Agents
Makefile lines 30-70: the test targets currently silently skip when $(TEST_DIR)
is missing; change the guard so CI/automated runs fail loudly by returning a
non-zero exit status if $(TEST_DIR) is expected but absent (or introduce an
environment flag like FAIL_ON_MISSING_TEST_DIR to control behavior), update each
target to print a clear error message and exit 1 when the directory is missing,
and keep the current soft-skip behavior only when the flag explicitly allows it.

Comment thread scripts/gen-mocks.sh
Comment on lines +18 to +45
find . -maxdepth 1 -name "*.go" \
-not -name "*_test.go" \
-not -name "*_mock.go" \
-type f | while read -r file; do

# Check if file contains interface definitions
if grep -q "type.*interface\s*{" "$file"; then
count=$((count + 1))

# Get base filename
base=$(basename "$file" .go)
output="./${base}_mock.go"

echo "Processing: $file"

# Get package name from the file
package=$(grep -m 1 "^package " "$file" | awk '{print $2}')

# Generate mock file
if GO111MODULE=on mockgen -source="$file" -destination="$output" -package="$package" 2>/dev/null; then
echo " ✓ Generated: $output"
success=$((success + 1))
else
echo " ✗ Failed to generate mock for: $file"
failed=$((failed + 1))
fi
fi
done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix counter tracking in mock generator loop

Because the while runs in a subshell (find … | while …), the count/success/failed variables are reset when the loop exits. The summary therefore always prints zeros, hiding failures. Run the loop in the current shell instead.

-find . -maxdepth 1 -name "*.go" \
-  -not -name "*_test.go" \
-  -not -name "*_mock.go" \
-  -type f | while read -r file; do
+while IFS= read -r -d '' file; do
@@
-  fi
-done
+  fi
+done < <(find . -maxdepth 1 -name "*.go" \
+  -not -name "*_test.go" \
+  -not -name "*_mock.go" \
+  -type f -print0)

@itsLeonB itsLeonB merged commit 770ca19 into main Oct 8, 2025
10 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jan 9, 2026
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant