Add query options to function test (#782)
This commit is contained in:
committed by
Ta-Ching Chen
parent
27c3a50d23
commit
e8b2a26a3b
+24
-2
@@ -716,9 +716,31 @@ func fnTest(c *cli.Context) error {
|
||||
fnUri = fmt.Sprintf("%v/%v", ns, fnName)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("http://%s/fission-function/%s", routerURL, fnUri)
|
||||
functionUrl, err := url.Parse(fmt.Sprintf("http://%s/fission-function/%s", routerURL, fnUri))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
queryParams := c.StringSlice("query")
|
||||
if len(queryParams) > 0 {
|
||||
query := url.Values{}
|
||||
for _, q := range queryParams {
|
||||
queryParts := strings.SplitN(q, "=", 2)
|
||||
var key, value string
|
||||
if len(queryParts) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(queryParts) > 0 {
|
||||
key = queryParts[0]
|
||||
}
|
||||
if len(queryParts) > 1 {
|
||||
value = queryParts[1]
|
||||
}
|
||||
query.Set(key, value)
|
||||
}
|
||||
functionUrl.RawQuery = query.Encode()
|
||||
}
|
||||
|
||||
resp := httpRequest(c.String("method"), url, c.String("body"), c.StringSlice("header"))
|
||||
resp := httpRequest(c.String("method"), functionUrl.String(), c.String("body"), c.StringSlice("header"))
|
||||
if resp.StatusCode < 400 {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
checkErr(err, "Function test")
|
||||
|
||||
+2
-1
@@ -130,6 +130,7 @@ func main() {
|
||||
fnLogDBTypeFlag := cli.StringFlag{Name: "dbtype", Usage: "log database type, e.g. influxdb (currently only influxdb is supported)"}
|
||||
fnBodyFlag := cli.StringFlag{Name: "body, b", Usage: "request body"}
|
||||
fnHeaderFlag := cli.StringSliceFlag{Name: "header, H", Usage: "request headers"}
|
||||
fnQueryFlag := cli.StringSliceFlag{Name: "query, q", Usage: "request query parameters: -q key1=value1 -q key2=value2"}
|
||||
fnEntryPointFlag := cli.StringFlag{Name: "entrypoint", Usage: "entry point for environment v2 to load with"}
|
||||
fnBuildCmdFlag := cli.StringFlag{Name: "buildcmd", Usage: "build command for builder to run with"}
|
||||
fnSecretFlag := cli.StringFlag{Name: "secret", Usage: "function access to secret, should be present in the same namespace as the function"}
|
||||
@@ -148,7 +149,7 @@ func main() {
|
||||
// so, in the future, if we end up using kubeconfig in fission cli and enforcing rolebindings to be created for users by admins etc, we can add this option at the time.
|
||||
{Name: "list", Usage: "List all functions in a namespace if specified, else, list functions across all namespaces", Flags: []cli.Flag{fnNamespaceFlag}, Action: fnList},
|
||||
{Name: "logs", Usage: "Display function logs", Flags: []cli.Flag{fnNameFlag, fnNamespaceFlag, fnPodFlag, fnFollowFlag, fnDetailFlag, fnLogDBTypeFlag, fnLogCountFlag}, Action: fnLogs},
|
||||
{Name: "test", Usage: "Test a function", Flags: []cli.Flag{fnNameFlag, fnNamespaceFlag, fnEnvNameFlag, fnCodeFlag, fnSrcArchiveFlag, htMethodFlag, fnBodyFlag, fnHeaderFlag}, Action: fnTest},
|
||||
{Name: "test", Usage: "Test a function", Flags: []cli.Flag{fnNameFlag, fnNamespaceFlag, fnEnvNameFlag, fnCodeFlag, fnSrcArchiveFlag, htMethodFlag, fnBodyFlag, fnHeaderFlag, fnQueryFlag}, Action: fnTest},
|
||||
}
|
||||
|
||||
// httptriggers
|
||||
|
||||
Reference in New Issue
Block a user