mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 20:16:37 +00:00
Add feature for invoking namespaced functions
When coupled with the latest version of faas-netes, the gateway can now invoke, query and deploy functions into alternative namespaces. Tested e2e by creating a namespace "fn" and deploying, then invoking a function deployed there and in the default namespace. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
0a90125aba
commit
238ce1be23
@ -5,8 +5,10 @@ package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -27,6 +29,28 @@ func TestSingleHostBaseURLResolver(t *testing.T) {
|
||||
|
||||
const watchdogPort = 8080
|
||||
|
||||
func TestFunctionAsHostBaseURLResolver_WithNamespaceOverride(t *testing.T) {
|
||||
|
||||
suffix := "openfaas-fn.local.cluster.svc."
|
||||
namespace := "openfaas-fn"
|
||||
newNS := "production-fn"
|
||||
|
||||
r := FunctionAsHostBaseURLResolver{FunctionSuffix: suffix, FunctionNamespace: namespace}
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/function/hello."+newNS, nil)
|
||||
|
||||
resolved := r.Resolve(req)
|
||||
|
||||
newSuffix := strings.Replace(suffix, namespace, newNS, -1)
|
||||
|
||||
want := fmt.Sprintf("http://hello.%s:%d", newSuffix, watchdogPort)
|
||||
log.Println(want)
|
||||
if resolved != want {
|
||||
t.Logf("r.Resolve failed, want: %s got: %s", want, resolved)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFunctionAsHostBaseURLResolver_WithSuffix(t *testing.T) {
|
||||
suffix := "openfaas-fn.local.cluster.svc."
|
||||
r := FunctionAsHostBaseURLResolver{FunctionSuffix: suffix}
|
||||
@ -35,7 +59,7 @@ func TestFunctionAsHostBaseURLResolver_WithSuffix(t *testing.T) {
|
||||
|
||||
resolved := r.Resolve(req)
|
||||
want := fmt.Sprintf("http://hello.%s:%d", suffix, watchdogPort)
|
||||
|
||||
log.Println(want)
|
||||
if resolved != want {
|
||||
t.Logf("r.Resolve failed, want: %s got: %s", want, resolved)
|
||||
t.Fail()
|
||||
|
Reference in New Issue
Block a user