Merge pull request #217547 from cideM/go-migrate-tests

go-mockery: add package test
This commit is contained in:
Sandro 2023-03-09 16:14:47 +01:00 committed by GitHub
commit 324ef866e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
{ lib, buildGoModule, fetchFromGitHub }:
{ lib, buildGoModule, fetchFromGitHub, go-mockery, runCommand, go }:
buildGoModule rec {
pname = "go-mockery";
@ -24,6 +24,37 @@ buildGoModule rec {
vendorHash = "sha256-3lx3wHnPQ/slRXnlVAnI1ZqSykDXNivjwg1WUITGj64=";
passthru.tests = {
generateMock = runCommand "${pname}-test" {
nativeBuildInputs = [ go-mockery ];
buildInputs = [ go ];
} ''
if [[ $(mockery --version) != *"${version}"* ]]; then
echo "Error: program version does not match package version"
exit 1
fi
export HOME=$TMPDIR
cat <<EOF > foo.go
package main
type Foo interface {
Bark() string
}
EOF
mockery --name Foo --dir .
if [[ ! -f "mocks/Foo.go" ]]; then
echo "Error: mocks/Foo.go was not generated by ${pname}"
exit 1
fi
touch $out
'';
};
meta = with lib; {
homepage = "https://github.com/vektra/mockery";
description = "A mock code autogenerator for Golang";