diff --git a/pkgs/development/tools/go-mockery/default.nix b/pkgs/development/tools/go-mockery/default.nix index a80249026960..118c8f52f740 100644 --- a/pkgs/development/tools/go-mockery/default.nix +++ b/pkgs/development/tools/go-mockery/default.nix @@ -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 < 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";