Skip to content

Commit

Permalink
Add e2e tests for issue vektra#681
Browse files Browse the repository at this point in the history
This adds e2e tests for vektra#681, which asserts packages containing only
auto-generated files are added to the list of importable packages
when doing recursive package discovery.
  • Loading branch information
LandonTClipp committed Aug 3, 2023
1 parent dbad753 commit 871bca9
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 24 deletions.
29 changes: 16 additions & 13 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
version: "3"

tasks:
test:
cmds:
- go test -v -coverprofile=coverage.txt ./...
desc: run unit tests
sources:
- "**/*.go"
generates:
- coverage.txt

coverage:
deps: [test]
desc: run unit tests and create HTML coverage file
Expand All @@ -23,14 +14,14 @@ tasks:
cmds:
- go fmt ./...

rm_mocks:
mocks.remove:
desc: remove all mock files
cmds:
- find . -name '*_mock.go' | xargs rm
- rm -rf mocks/

mocks:
mocks.generate:
desc: generate mockery mocks
deps: [rm_mocks]
cmds:
- go run .

Expand All @@ -41,6 +32,8 @@ tasks:

mkdocs.install:
desc: install mkdocs and plugins
sources:
- "docs/requirements.txt"
cmds:
- pip install -r docs/requirements.txt

Expand All @@ -57,6 +50,15 @@ tasks:
cmds:
- go run github.com/golangci/golangci-lint/cmd/golangci-lint run

test:
cmds:
- go test -v -coverprofile=coverage.txt ./...
desc: run unit tests
sources:
- "**/*.go"
generates:
- coverage.txt

test.e2e:
desc: run end-to-end tests
sources:
Expand All @@ -68,7 +70,8 @@ tasks:
test.ci:
deps: [fmt, lint]
cmds:
- task: mocks
- task: mocks.remove
- task: mocks.generate
- task: test
- task: test.e2e

Expand Down
5 changes: 5 additions & 0 deletions e2e/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

for file in $(ls $SCRIPT_DIR/test_*.sh); do
echo "=========="
echo "RUNNING $file"
echo "=========="
task mocks.remove || exit 1
task mocks.generate || exit 1
$file
done
7 changes: 1 addition & 6 deletions e2e/test_infinite_mocking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# This tests https://github.com/vektra/mockery/issues/632, where
# mockery was generating mocks of its own auto-generated code.

echo "=========="
echo "RUNNING $0"
echo "=========="

# New mocks may legimitately be created, so we run mockery once first
go run .
num_files_before=$(find . -type f | wc -l)
go run .
task mocks.generate
num_files_after=$(find . -type f | wc -l)

if [ $num_files_before -ne $num_files_after ]; then
Expand Down
6 changes: 1 addition & 5 deletions e2e/test_mockery_generation.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash

echo "=========="
echo "RUNNING $0"
echo "=========="

go run .
task mocks.generate
rt=$?
if [ $rt -ne 0 ]; then
echo "ERROR: non-zero return code from mockery"
Expand Down
8 changes: 8 additions & 0 deletions e2e/test_recursive_package_with_only_autogenerated_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# This tests https://github.com/vektra/mockery/pull/682

FILE="pkg/fixtures/recursive_generation/subpkg_with_only_autogenerated_files/Foo_mock.go"
if ! [ -f $FILE ]; then
echo "ERROR: $FILE does not exist"
exit 1
fi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 871bca9

Please sign in to comment.