Skip to content

Version 0.10.0

Compare
Choose a tag to compare
@ryanmoran ryanmoran released this 06 May 18:51

Supports interfaces that pass functions as arguments

// example_test.go
package example_test

//go:generate faux --interface example --output fakes/example.com
type example interface {
  Example(func(string) err) func(int) bool
}
// fakes/example.go
package fakes

import "sync"

type Example struct {
	ExampleCall struct {
		sync.Mutex
		CallCount int
		Receives  struct {
			FuncStringError func(string) error
		}
		Returns struct {
			FuncIntBool func(int) bool
		}
		Stub func(func(string) error) func(int) bool
	}
}

func (f *Example) Example(param1 func(string) error) func(int) bool {
	f.ExampleCall.Lock()
	defer f.ExampleCall.Unlock()
	f.ExampleCall.CallCount++
	f.ExampleCall.Receives.FuncStringError = param1
	if f.ExampleCall.Stub != nil {
		return f.ExampleCall.Stub(param1)
	}
	return f.ExampleCall.Returns.FuncIntBool
}