Files
podinfo/pkg/api/version_test.go
2018-08-20 11:23:13 +03:00

37 lines
811 B
Go

package api
import (
"fmt"
"net/http"
"net/http/httptest"
"regexp"
"testing"
)
func TestVersionHandler(t *testing.T) {
req, err := http.NewRequest("GET", "/version", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
srv := NewMockServer()
handler := http.HandlerFunc(srv.versionHandler)
handler.ServeHTTP(rr, req)
// Check the status code is what we expect.
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
// Check the response body is what we expect.
expected := "unknown"
r := regexp.MustCompile(fmt.Sprintf("(?m:%s)", expected))
if !r.MatchString(rr.Body.String()) {
t.Fatalf("handler returned unexpected body:\ngot \n%v \nwant \n%s",
rr.Body.String(), expected)
}
}