Skip to content

Instantly share code, notes, and snippets.

@prantoran
Last active April 27, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prantoran/fc4173bef95efb19f4ec794653308c16 to your computer and use it in GitHub Desktop.
Save prantoran/fc4173bef95efb19f4ec794653308c16 to your computer and use it in GitHub Desktop.
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