mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 17:03:01 +00:00
go-mockery: add package test
Add a very basic package test for go-mockery that asserts: * version matches what is expected * running the program generates a *.go file Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
This commit is contained in:
parent
ffdae3d386
commit
9670b19ce8
@ -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-Dl8Q6fQa7BKp06a4OT82+wHYQRN1aWZ2qK25GzhOw8A=";
|
||||
|
||||
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";
|
||||
|
Loading…
Reference in New Issue
Block a user