#!/bin/sh set -eu REPO_ROOT="/go/src/github.com/shellhub-io/shellhub" PASS=0 FAIL=0 pass() { echo " PASS: $1"; PASS=$((PASS + 1)); } fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); } echo "=== gen-mock v3 convention tests ===" echo "" echo "--- Test 1: no //go:build mocks build tags in mock files ---" files_with_build_tag=$( find "$REPO_ROOT" -name "*.go" -path "*/mocks/*" \ -exec grep -l "//go:build mocks" {} + 2>/dev/null || true ) if [ -z "$files_with_build_tag" ]; then pass "no //go:build mocks tags found" else fail "found //go:build mocks in: $files_with_build_tag" fi echo "--- Test 2: all mock files live under .../mocks/ ---" mocks_outside=$( find "$REPO_ROOT" -name "*.go" \ ! -path "*/vendor/*" \ ! -path "*/mocks/*" \ | while read -r f; do if head -1 "$f" 2>/dev/null | grep -q "Code generated by mockery"; then echo "$f" fi done ) if [ -z "$mocks_outside" ]; then pass "all generated mock files are inside mocks/ directories" else fail "generated mock files found outside mocks/: $mocks_outside" fi # v3 mockery sets structname: "Mock{{.InterfaceName}}", so every primary echo "--- Test 3: mock struct names follow MockX pattern ---" bad_structs=$( find "$REPO_ROOT" -name "*.go" -path "*/mocks/*" \ ! -name "*_test.go" \ | while read -r f; do grep -n "^type [A-Z][A-Za-z0-9]* struct" "$f" 2>/dev/null \ | grep -v "^[0-9]*:type Mock" \ | while IFS= read -r line; do echo "$f:$line" done done ) if [ -z "$bad_structs" ]; then pass "all mock structs follow MockX naming pattern" else fail "mock structs not following MockX pattern:" echo "$bad_structs" | sed 's/^/ /' fi echo "" echo "Results: $PASS passed, $FAIL failed" if [ "$FAIL" -gt 0 ]; then exit 1 fi