Created
January 24, 2021 10:43
-
-
Save trustmaster/168c5325655e1690e32e62027bac52ab to your computer and use it in GitHub Desktop.
Go test pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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