From 0aff2f214db95a061705fe78ea77d39d77538113 Mon Sep 17 00:00:00 2001 From: Vishal Date: Mon, 30 Apr 2018 11:44:46 +0530 Subject: [PATCH] Fixes the issue with fn test and adds relevant test cases, fixes #650 (#651) * Fixes the issue with fn test and adds relevant test cases, fixes #650 * Checking log size for invalid function * Testing the invalid function logs a few time beforr quitting * Disabling the test for now, linked to issue #653 --- fission/function.go | 2 +- test/tests/test_function_test/errhello.js | 7 ++ test/tests/test_function_test/hello.js | 6 ++ test/tests/test_function_test/test_fn_test.sh | 68 +++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 test/tests/test_function_test/errhello.js create mode 100644 test/tests/test_function_test/hello.js create mode 100755 test/tests/test_function_test/test_fn_test.sh diff --git a/fission/function.go b/fission/function.go index d682c6dd..99cdf725 100644 --- a/fission/function.go +++ b/fission/function.go @@ -43,7 +43,7 @@ func printPodLogs(c *cli.Context) error { fatal("Need --name argument.") } - queryURL, err := url.Parse(c.GlobalString("server")) + queryURL, err := url.Parse(getServerUrl()) checkErr(err, "parse the base URL") queryURL.Path = fmt.Sprintf("/proxy/logs/%s", fnName) diff --git a/test/tests/test_function_test/errhello.js b/test/tests/test_function_test/errhello.js new file mode 100644 index 00000000..5de8d48a --- /dev/null +++ b/test/tests/test_function_test/errhello.js @@ -0,0 +1,7 @@ +// This file has an error on purpose; async is replaced with aasync +module.exports = aasync function(context) { + return { + status: 200, + body: "Hello, Fission!\n" + }; +} \ No newline at end of file diff --git a/test/tests/test_function_test/hello.js b/test/tests/test_function_test/hello.js new file mode 100644 index 00000000..c7853394 --- /dev/null +++ b/test/tests/test_function_test/hello.js @@ -0,0 +1,6 @@ +module.exports = async function (context) { + return { + status: 200, + body: "Hello, Fission!\n" + }; +} \ No newline at end of file diff --git a/test/tests/test_function_test/test_fn_test.sh b/test/tests/test_function_test/test_fn_test.sh new file mode 100755 index 00000000..518f145a --- /dev/null +++ b/test/tests/test_function_test/test_fn_test.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +#test:disabled +# Disabled because CI Fails for invalid function https://github.com/fission/fission/issues/653 + +set -euo pipefail + +env=nodejs-$(date +%N) +valid_fn_name=hello-$(date +%N) +invalid_fn_name=errhello-$(date +%N) + +function cleanup { + log "Cleaning up" + fission env delete --name $env + fission fn delete --name $valid_fn_name + fission fn delete --name $invalid_fn_name +} + +log "Creating env $env" +fission env create --name $env --image fission/node-env +trap cleanup EXIT + +log "Creating valid function $valid_fn_name" +fission fn create --name $valid_fn_name --env $env --code hello.js + +log "Testing valid function $valid_fn_name" +fission fn test --name $valid_fn_name > /tmp/valid.log + +log "---Valid Function logs---" +cat /tmp/valid.log +log "------" +valid_num=$(grep 'Hello, Fission' /tmp/valid.log | wc -l) + +if [ $valid_num -ne 1 ] +then + log "Valid function Test Failed: expected 1, found $valid_num logs" + exit 1 +fi + +log "Creating function with an error $invalid_fn_name" +fission fn create --name $invalid_fn_name --env $env --code errhello.js + +log "Testing invalid function $valid_fn_name" +fission fn test --name $invalid_fn_name > /tmp/invalid.log + +for i in {1..10} +do + size=$(wc -c /tmp/invalid.log + else + break + fi +done + +log "---Invalid Function logs---" +cat /tmp/invalid.log +log "------" +invalid_num=$(grep 'SyntaxError' /tmp/invalid.log | wc -l) + +if [ $invalid_num -ne 1 ] +then + log "Invalid function Failed: expected 1, found $invalid_num logs" + exit 1 +fi + +log "All tests passed" \ No newline at end of file