Last active
August 22, 2019 04:01
-
-
Save softwarebygabe/94f1171cdd5eee4389aa8dc8a0a0bf6c to your computer and use it in GitHub Desktop.
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 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