mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: system tests should default to hot/json (#983)
This commit is contained in:
@@ -2,9 +2,10 @@ package tests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
//"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -24,12 +25,36 @@ func LB() (string, error) {
|
|||||||
return u.Host, nil
|
return u.Host, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEchoContent(respBytes []byte) (string, error) {
|
||||||
|
|
||||||
|
var respJs map[string]interface{}
|
||||||
|
|
||||||
|
err := json.Unmarshal(respBytes, &respJs)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, ok := respJs["request"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return "", errors.New("unexpected json: request map")
|
||||||
|
}
|
||||||
|
|
||||||
|
echo, ok := req["echoContent"].(string)
|
||||||
|
if !ok {
|
||||||
|
return "", errors.New("unexpected json: echoContent string")
|
||||||
|
}
|
||||||
|
|
||||||
|
return echo, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestCanExecuteFunction(t *testing.T) {
|
func TestCanExecuteFunction(t *testing.T) {
|
||||||
s := apiutils.SetupHarness()
|
s := apiutils.SetupHarness()
|
||||||
s.GivenAppExists(t, &sdkmodels.App{Name: s.AppName})
|
s.GivenAppExists(t, &sdkmodels.App{Name: s.AppName})
|
||||||
defer s.Cleanup()
|
defer s.Cleanup()
|
||||||
|
|
||||||
rt := s.BasicRoute()
|
rt := s.BasicRoute()
|
||||||
|
rt.Image = "fnproject/fn-test-utils"
|
||||||
|
rt.Format = "json"
|
||||||
rt.Type = "sync"
|
rt.Type = "sync"
|
||||||
|
|
||||||
s.GivenRouteExists(t, s.AppName, rt)
|
s.GivenRouteExists(t, s.AppName, rt)
|
||||||
@@ -44,16 +69,18 @@ func TestCanExecuteFunction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
u.Path = path.Join(u.Path, "r", s.AppName, s.RoutePath)
|
u.Path = path.Join(u.Path, "r", s.AppName, s.RoutePath)
|
||||||
|
|
||||||
content := &bytes.Buffer{}
|
body := `{"echoContent": "HelloWorld", "sleepTime": 0, "isDebug": true}`
|
||||||
|
content := bytes.NewBuffer([]byte(body))
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
|
|
||||||
_, err = apiutils.CallFN(u.String(), content, output, "POST", []string{})
|
_, err = apiutils.CallFN(u.String(), content, output, "POST", []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Got unexpected error: %v", err)
|
t.Errorf("Got unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
expectedOutput := "Hello World!\n"
|
|
||||||
actual := output.String()
|
echo, err := getEchoContent(output.Bytes())
|
||||||
if !strings.Contains(expectedOutput, actual) || len(expectedOutput) != len(actual) {
|
if err != nil || echo != "HelloWorld" {
|
||||||
t.Errorf("Assertion error.\n\tExpected: %v\n\tActual: %v", expectedOutput, output.String())
|
t.Fatalf("getEchoContent/HelloWorld check failed on %v", output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +94,8 @@ func TestBasicConcurrentExecution(t *testing.T) {
|
|||||||
defer s.Cleanup()
|
defer s.Cleanup()
|
||||||
|
|
||||||
rt := s.BasicRoute()
|
rt := s.BasicRoute()
|
||||||
|
rt.Image = "fnproject/fn-test-utils"
|
||||||
|
rt.Format = "json"
|
||||||
rt.Type = "sync"
|
rt.Type = "sync"
|
||||||
|
|
||||||
s.GivenRouteExists(t, s.AppName, rt)
|
s.GivenRouteExists(t, s.AppName, rt)
|
||||||
@@ -85,19 +114,21 @@ func TestBasicConcurrentExecution(t *testing.T) {
|
|||||||
concurrentFuncs := 10
|
concurrentFuncs := 10
|
||||||
for i := 0; i < concurrentFuncs; i++ {
|
for i := 0; i < concurrentFuncs; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
content := &bytes.Buffer{}
|
body := `{"echoContent": "HelloWorld", "sleepTime": 0, "isDebug": true}`
|
||||||
|
content := bytes.NewBuffer([]byte(body))
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
_, err = apiutils.CallFN(u.String(), content, output, "POST", []string{})
|
_, err = apiutils.CallFN(u.String(), content, output, "POST", []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results <- fmt.Errorf("Got unexpected error: %v", err)
|
results <- fmt.Errorf("Got unexpected error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
expectedOutput := "Hello World!\n"
|
|
||||||
actual := output.String()
|
echo, err := getEchoContent(output.Bytes())
|
||||||
if !strings.Contains(expectedOutput, actual) || len(expectedOutput) != len(actual) {
|
if err != nil || echo != "HelloWorld" {
|
||||||
results <- fmt.Errorf("Assertion error.\n\tExpected: %v\n\tActual: %v", expectedOutput, output.String())
|
results <- fmt.Errorf("Assertion error.\n\tActual: %v", output.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
results <- nil
|
results <- nil
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -121,6 +152,8 @@ func TestSaturatedSystem(t *testing.T) {
|
|||||||
defer s.Cleanup()
|
defer s.Cleanup()
|
||||||
|
|
||||||
rt := s.BasicRoute()
|
rt := s.BasicRoute()
|
||||||
|
rt.Image = "fnproject/fn-test-utils"
|
||||||
|
rt.Format = "json"
|
||||||
rt.Type = "sync"
|
rt.Type = "sync"
|
||||||
|
|
||||||
s.GivenRouteExists(t, s.AppName, rt)
|
s.GivenRouteExists(t, s.AppName, rt)
|
||||||
@@ -135,8 +168,10 @@ func TestSaturatedSystem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
u.Path = path.Join(u.Path, "r", s.AppName, s.RoutePath)
|
u.Path = path.Join(u.Path, "r", s.AppName, s.RoutePath)
|
||||||
|
|
||||||
content := &bytes.Buffer{}
|
body := `{"echoContent": "HelloWorld", "sleepTime": 0, "isDebug": true}`
|
||||||
|
content := bytes.NewBuffer([]byte(body))
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
|
|
||||||
_, err = apiutils.CallFN(u.String(), content, output, "POST", []string{})
|
_, err = apiutils.CallFN(u.String(), content, output, "POST", []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != apimodels.ErrCallTimeoutServerBusy {
|
if err != apimodels.ErrCallTimeoutServerBusy {
|
||||||
|
|||||||
Reference in New Issue
Block a user