knative-function/handle_test.go
Adrien le Maire 278c611bab first commit
2023-12-08 10:32:20 +01:00

27 lines
539 B
Go

package function
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
// TestHandle ensures that Handle executes without error and returns the
// HTTP 200 status code indicating no errors.
func TestHandle(t *testing.T) {
var (
w = httptest.NewRecorder()
req = httptest.NewRequest("GET", "http://example.com/test", nil)
res *http.Response
)
Handle(context.Background(), w, req)
res = w.Result()
defer res.Body.Close()
if res.StatusCode != 200 {
t.Fatalf("unexpected response code: %v", res.StatusCode)
}
}