mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 16:56:47 +00:00
Introduces a single-flight call to a function's health endpoint to verify that it is registered with an Istio sidecar (Envoy) before letting the invocation through. Results are cached for 5 seconds, before a probe is required again. Tested without Istio, with probe_functions environment variable set to true, I saw a probe execute in the logs. Fixes: #1721 for Istio users. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
package handlers
|
|
|
|
import (
|
|
"github.com/openfaas/faas/gateway/pkg/middleware"
|
|
"testing"
|
|
)
|
|
|
|
func Test_getNamespace_Default(t *testing.T) {
|
|
root, ns := middleware.GetNamespace("openfaas-fn", "figlet.openfaas-fn")
|
|
wantRoot := "figlet"
|
|
wantNs := "openfaas-fn"
|
|
|
|
if root != wantRoot {
|
|
t.Errorf("function root: want %s, got %s", wantRoot, root)
|
|
}
|
|
if ns != wantNs {
|
|
t.Errorf("function ns: want %s, got %s", wantNs, ns)
|
|
}
|
|
}
|
|
|
|
func Test_getNamespace_Override(t *testing.T) {
|
|
root, ns := middleware.GetNamespace("fn", "figlet.fn")
|
|
wantRoot := "figlet"
|
|
wantNs := "fn"
|
|
|
|
if root != wantRoot {
|
|
t.Errorf("function root: want %s, got %s", wantRoot, root)
|
|
}
|
|
if ns != wantNs {
|
|
t.Errorf("function ns: want %s, got %s", wantNs, ns)
|
|
}
|
|
}
|
|
|
|
func Test_getNamespace_Empty(t *testing.T) {
|
|
root, ns := middleware.GetNamespace("", "figlet")
|
|
wantRoot := "figlet"
|
|
wantNs := ""
|
|
|
|
if root != wantRoot {
|
|
t.Errorf("function root: want %s, got %s", wantRoot, root)
|
|
}
|
|
if ns != wantNs {
|
|
t.Errorf("function ns: want %s, got %s", wantNs, ns)
|
|
}
|
|
}
|