Skip to content

Instantly share code, notes, and snippets.

@softwarebygabe
Last active August 22, 2019 04:01
Show Gist options
  • Save softwarebygabe/94f1171cdd5eee4389aa8dc8a0a0bf6c to your computer and use it in GitHub Desktop.
Save softwarebygabe/94f1171cdd5eee4389aa8dc8a0a0bf6c to your computer and use it in GitHub Desktop.
package foo_test
import (
"errors"
"testing"
"interfaces/foo"
)
type MockClient struct {
GetDataReturn string
}
func (mc MockClient) GetData() (string, error) {
return mc.GetDataReturn, nil
}
func TestController_Success(t *testing.T) {
err := foo.Controller(MockClient{"data"})
if err != nil {
t.FailNow()
}
}
type FailingClient struct{}
func (fc FailingClient) GetData() (string, error) {
return "", errors.New("oh no")
}
func TestController_Failure(t *testing.T) {
// test failure of GetData()
err := foo.Controller(FailingClient{})
if err == nil {
t.FailNow()
}
// test unexpected data returned from GetData()
err = foo.Controller(MockClient{"not data"})
if err == nil {
t.FailNow()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment