Last active
April 27, 2018 17:47
-
-
Save prantoran/fc4173bef95efb19f4ec794653308c16 to your computer and use it in GitHub Desktop.
This file contains 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 main | |
import ( | |
"net/http" | |
"os" | |
"testing" | |
"github.com/prantoran/go-mock-microservice/mocks" | |
"github.com/prantoran/go-mock-microservice/printer" | |
) | |
func TestMain(m *testing.M) { | |
pr := mocks.NewMockPrinter() | |
pr.SetPrintFunc( | |
func(s string) (*printer.Resp, error) { | |
return &printer.Resp{Body: "hello", Status: http.StatusText(http.StatusOK)}, nil | |
}) | |
printer.Cur = pr | |
os.Exit(m.Run()) | |
} | |
func TestPrint(t *testing.T) { | |
var tests = []struct { | |
body, status string | |
}{ | |
{"hello", http.StatusText(http.StatusOK)}, | |
{"notok", http.StatusText(http.StatusNotFound)}, | |
} | |
for _, tt := range tests { | |
res, _ := printer.Cur.Print(tt.body) | |
if res.Status != tt.status { | |
t.Errorf("status got %v, want %v", res.Status, tt.status) | |
} | |
if res.Body != tt.body { | |
t.Errorf("body got %v, want %v", res.Body, tt.body) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment