Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracts logic for building URL to makeFunctionURL and adds several unit tests for either mode and querystring/path combination. Signed-off-by: Alex Ellis <alexellis2@gmail.com>
- Loading branch information
Showing
2 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/openfaas/faas/gateway/queue" | ||
) | ||
|
||
func Test_makeFunctionURL_DefaultPathQS_GatewayInvoke_IncludesGWAddress(t *testing.T) { | ||
config := QueueWorkerConfig{ | ||
FunctionSuffix: "", | ||
GatewayInvoke: true, | ||
GatewayAddress: "gateway", | ||
} | ||
req := queue.Request{ | ||
Function: "function1", | ||
Path: "/", | ||
} | ||
|
||
fnURL := makeFunctionURL(&req, &config, req.Path, req.QueryString) | ||
wantURL := "http://gateway:8080/function/function1/" | ||
if fnURL != wantURL { | ||
t.Errorf("want %s, got %s", wantURL, fnURL) | ||
} | ||
} | ||
|
||
func Test_makeFunctionURL_DefaultPathQS_GatewayInvoke_WithQS(t *testing.T) { | ||
config := QueueWorkerConfig{ | ||
FunctionSuffix: "", | ||
GatewayInvoke: true, | ||
GatewayAddress: "gateway", | ||
} | ||
req := queue.Request{ | ||
Function: "function1", | ||
QueryString: "user=1", | ||
} | ||
|
||
fnURL := makeFunctionURL(&req, &config, req.Path, req.QueryString) | ||
wantURL := "http://gateway:8080/function/function1/?user=1" | ||
if fnURL != wantURL { | ||
t.Errorf("want %s, got %s", wantURL, fnURL) | ||
} | ||
} | ||
|
||
func Test_makeFunctionURL_DefaultPathQS_GatewayInvoke_WithPath(t *testing.T) { | ||
config := QueueWorkerConfig{ | ||
FunctionSuffix: "", | ||
GatewayInvoke: true, | ||
GatewayAddress: "gateway", | ||
} | ||
req := queue.Request{ | ||
Function: "function1", | ||
Path: "/resources/main.css", | ||
} | ||
|
||
fnURL := makeFunctionURL(&req, &config, req.Path, req.QueryString) | ||
wantURL := "http://gateway:8080/function/function1/resources/main.css" | ||
if fnURL != wantURL { | ||
t.Errorf("want %s, got %s", wantURL, fnURL) | ||
} | ||
} | ||
|
||
func Test_makeFunctionURL_DefaultPathQS_GatewayInvokeOff_UsesDirectInvocation(t *testing.T) { | ||
config := QueueWorkerConfig{ | ||
FunctionSuffix: ".openfaas-fn", | ||
GatewayInvoke: false, | ||
GatewayAddress: "gateway", | ||
} | ||
req := queue.Request{ | ||
Function: "function1", | ||
Path: "/", | ||
} | ||
|
||
fnURL := makeFunctionURL(&req, &config, req.Path, req.QueryString) | ||
|
||
wantURL := "http://function1.openfaas-fn:8080/" | ||
if fnURL != wantURL { | ||
t.Errorf("want %s, got %s", wantURL, fnURL) | ||
} | ||
} |