mirror of
https://github.com/openfaas/faas.git
synced 2025-06-27 09:13:24 +00:00
Enhance info endpoint to include gateway version
Extend the health endpoint and add gateway version information Resolves: #733 Signed-off-by: Edward Wilde <ewilde@gmail.com>
This commit is contained in:
48
gateway/tests/integration/infohandler_test.go
Normal file
48
gateway/tests/integration/infohandler_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package inttests
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/openfaas/faas/gateway/types"
|
||||
)
|
||||
|
||||
func Test_InfoEndpoint_Returns_200(t *testing.T) {
|
||||
_, code, err := fireRequest("http://localhost:8080/system/info", http.MethodGet, "")
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
wantCode := http.StatusOK
|
||||
if code != wantCode {
|
||||
t.Errorf("status code, want: %d, got: %d", wantCode, code)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func Test_InfoEndpoint_Returns_Gateway_Version_SHA_And_Message(t *testing.T) {
|
||||
body, _, err := fireRequest("http://localhost:8080/system/info", http.MethodGet, "")
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
gatewayInfo := &types.GatewayInfo{}
|
||||
err = json.Unmarshal([]byte(body), gatewayInfo)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if len(gatewayInfo.Version.SHA) != 40 {
|
||||
t.Errorf("length of SHA incorrect, want: %d, got: %d. Json body was %s", 40, len(gatewayInfo.Version.SHA), body)
|
||||
}
|
||||
|
||||
if len(gatewayInfo.Version.CommitMessage) == 0 {
|
||||
t.Errorf("length of commit message should be greater than 0. Json body was %s", body)
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ func fireRequestWithHeaders(url string, method string, reqBody string, headers m
|
||||
func TestGet_Rejected(t *testing.T) {
|
||||
var reqBody string
|
||||
unsupportedMethod := http.MethodHead
|
||||
_, code, err := fireRequest("http://localhost:8080/function/func_echoit", unsupportedMethod, reqBody)
|
||||
_, code, err := fireRequest("http://localhost:8080/function/echoit", unsupportedMethod, reqBody)
|
||||
want := http.StatusMethodNotAllowed
|
||||
if code != want {
|
||||
t.Logf("Failed got: %d, wanted: %d", code, want)
|
||||
@ -68,15 +68,18 @@ func TestEchoIt_Post_Route_Handler_ForwardsClientHeaders(t *testing.T) {
|
||||
headers := make(map[string]string, 0)
|
||||
headers["X-Api-Key"] = "123"
|
||||
|
||||
body, code, err := fireRequestWithHeaders("http://localhost:8080/function/func_echoit", http.MethodPost, reqBody, headers)
|
||||
body, code, err := fireRequestWithHeaders("http://localhost:8080/function/echoit", http.MethodPost, reqBody, headers)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if code != http.StatusOK {
|
||||
t.Log("Failed")
|
||||
t.Logf("Failed, code: %d, body:%s", code, body)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if body != reqBody {
|
||||
t.Log("Expected body returned")
|
||||
t.Fail()
|
||||
@ -85,7 +88,7 @@ func TestEchoIt_Post_Route_Handler_ForwardsClientHeaders(t *testing.T) {
|
||||
|
||||
func TestEchoIt_Post_Route_Handler(t *testing.T) {
|
||||
reqBody := "test message"
|
||||
body, code, err := fireRequest("http://localhost:8080/function/func_echoit", http.MethodPost, reqBody)
|
||||
body, code, err := fireRequest("http://localhost:8080/function/echoit", http.MethodPost, reqBody)
|
||||
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
|
Reference in New Issue
Block a user