Skip to content

Commit 9670b19

Browse files
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>
1 parent ffdae3d commit 9670b19

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

pkgs/development/tools/go-mockery/default.nix

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, buildGoModule, fetchFromGitHub }:
1+
{ lib, buildGoModule, fetchFromGitHub, go-mockery, runCommand, go }:
22

33
buildGoModule rec {
44
pname = "go-mockery";
@@ -24,6 +24,37 @@ buildGoModule rec {
2424

2525
vendorHash = "sha256-Dl8Q6fQa7BKp06a4OT82+wHYQRN1aWZ2qK25GzhOw8A=";
2626

27+
passthru.tests = {
28+
generateMock = runCommand "${pname}-test" {
29+
nativeBuildInputs = [ go-mockery ];
30+
buildInputs = [ go ];
31+
} ''
32+
if [[ $(mockery --version) != *"${version}"* ]]; then
33+
echo "Error: program version does not match package version"
34+
exit 1
35+
fi
36+
37+
export HOME=$TMPDIR
38+
39+
cat <<EOF > foo.go
40+
package main
41+
42+
type Foo interface {
43+
Bark() string
44+
}
45+
EOF
46+
47+
mockery --name Foo --dir .
48+
49+
if [[ ! -f "mocks/Foo.go" ]]; then
50+
echo "Error: mocks/Foo.go was not generated by ${pname}"
51+
exit 1
52+
fi
53+
54+
touch $out
55+
'';
56+
};
57+
2758
meta = with lib; {
2859
homepage = "https://github.com/vektra/mockery";
2960
description = "A mock code autogenerator for Golang";

0 commit comments

Comments
 (0)