mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 16:56:47 +00:00
Enables publishing to various topics according to annotations on the functions. The function cache is moved up one level so that it can be shared between the scale from zero code and the queue proxy. Unit tests added for new internal methods. Tested e2e with arkade and the newest queue-worker and RC gateway image with two queues and an annotation on one of the functions of com.openfaas.queue. It worked as expected including with multiple namespace support. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
75 lines
1.5 KiB
Go
75 lines
1.5 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 (
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func Test_getNameParts(t *testing.T) {
|
|
fn, ns := getNameParts("figlet.openfaas-fn")
|
|
wantFn := "figlet"
|
|
wantNs := "openfaas-fn"
|
|
|
|
if fn != wantFn {
|
|
t.Fatalf("want %s, got %s", wantFn, fn)
|
|
}
|
|
if ns != wantNs {
|
|
t.Fatalf("want %s, got %s", wantNs, ns)
|
|
}
|
|
}
|
|
|
|
func Test_getNamePartsDualDot(t *testing.T) {
|
|
fn, ns := getNameParts("dev.figlet.openfaas-fn")
|
|
wantFn := "dev.figlet"
|
|
wantNs := "openfaas-fn"
|
|
|
|
if fn != wantFn {
|
|
t.Fatalf("want %s, got %s", wantFn, fn)
|
|
}
|
|
if ns != wantNs {
|
|
t.Fatalf("want %s, got %s", wantNs, ns)
|
|
}
|
|
}
|
|
|
|
func Test_getNameParts_NoNs(t *testing.T) {
|
|
fn, ns := getNameParts("figlet")
|
|
wantFn := "figlet"
|
|
wantNs := ""
|
|
|
|
if fn != wantFn {
|
|
t.Fatalf("want %s, got %s", wantFn, fn)
|
|
}
|
|
if ns != wantNs {
|
|
t.Fatalf("want %s, got %s", wantNs, ns)
|
|
}
|
|
}
|
|
|
|
func Test_getCallbackURLHeader(t *testing.T) {
|
|
want := "http://localhost:8080"
|
|
header := http.Header{}
|
|
header.Add("X-Callback-Url", want)
|
|
|
|
uri, err := getCallbackURLHeader(header)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if uri.String() != want {
|
|
t.Fatalf("want %s, but got %s", want, uri.String())
|
|
}
|
|
}
|
|
|
|
func Test_getCallbackURLHeader_ParseFails(t *testing.T) {
|
|
want := "ht tp://foo.com"
|
|
header := http.Header{}
|
|
header.Add("X-Callback-Url", want)
|
|
|
|
_, err := getCallbackURLHeader(header)
|
|
if err == nil {
|
|
t.Fatal("wanted a parsing error.")
|
|
}
|
|
}
|