Skip to content

Instantly share code, notes, and snippets.

@trustmaster
Created January 24, 2021 10:43
Show Gist options
  • Save trustmaster/168c5325655e1690e32e62027bac52ab to your computer and use it in GitHub Desktop.
Save trustmaster/168c5325655e1690e32e62027bac52ab to your computer and use it in GitHub Desktop.
Go test pipeline
package pipeline
import fmt
// pipeline allows chaining simple calls in tests
type pipeline struct {
err error
}
// ok asserts that a function does not return an error
func (p *pipeline) ok(f func() error) *pipeline {
if p.err != nil {
return p
}
p.err = f()
return p
}
// fails asserts that a function returns an error
func (p *pipeline) fails(f func() error) *pipeline {
if p.err != nil {
return p
}
err := f()
if err == nil {
p.err = fmt.Errorf("Expected an error")
}
return p
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment