From 165a51d1d7f78e42557bd72dfd7a410beb19db12 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Wed, 21 Sep 2016 22:05:31 +0100 Subject: [PATCH] added go:generate example --- README.md | 17 +++++++++++++++++ generate/generate.go | 3 +++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index eb9cad5..698b116 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,23 @@ func CompleteSignUp(to string, sender EmailSender) { The mocked structure implements the interface, where each method calls the associated function field. +### Using go generate + +At the top of the file containing the interface you wish to mock, you can use +`go generate` to specify the interface to mock: + +``` +package test + +//go:generate moq -out myface_test.go . MyFace + +type MyFace interface { + Method() string +} +``` + +Then navigate to the directory in a shell, and run `go generate`. + ## Tips * Keep mocked logic inside the test that is using it diff --git a/generate/generate.go b/generate/generate.go index 1873ed4..335e9e8 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -1,5 +1,8 @@ package generate +// In a terminal, run `go generate` in this directory to have +// it generates the generated.go file. + //go:generate moq -out generated.go . MyInterface type MyInterface interface {