mirror of https://github.com/knative/func.git
test: url for invoke test (#863)
This commit is contained in:
parent
efc3b208cb
commit
8702515d91
|
@ -4,10 +4,13 @@
|
||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -57,15 +60,23 @@ func TestInvoke(t *testing.T) {
|
||||||
run(t, bin, prefix, "create", "--verbose=true", "--language=go", "--template=cloudevents", cwd)
|
run(t, bin, prefix, "create", "--verbose=true", "--language=go", "--template=cloudevents", cwd)
|
||||||
set(t, "handle.go", TestInvokeFunctionImpl)
|
set(t, "handle.go", TestInvokeFunctionImpl)
|
||||||
run(t, bin, prefix, "deploy", "--verbose=true", "--registry", GetRegistry())
|
run(t, bin, prefix, "deploy", "--verbose=true", "--registry", GetRegistry())
|
||||||
|
infoOut := run(t, bin, prefix, "info", "--output", "plain")
|
||||||
run(t, bin, prefix, "invoke", "--verbose=true", "--content-type=text/plain", "--source=func:set", "--data=TEST")
|
run(t, bin, prefix, "invoke", "--verbose=true", "--content-type=text/plain", "--source=func:set", "--data=TEST")
|
||||||
|
|
||||||
|
// Resolve target service URL from info command stdout
|
||||||
|
targetUrl := "http://testinvoke.default.127.0.0.1.sslip.io"
|
||||||
|
matches := regexp.MustCompile("Route (http.*)").FindStringSubmatch(infoOut)
|
||||||
|
if len(matches) > 1 {
|
||||||
|
targetUrl = matches[1]
|
||||||
|
}
|
||||||
|
|
||||||
// Validate by fetching the contents of the Function's data global
|
// Validate by fetching the contents of the Function's data global
|
||||||
fmt.Println("Validate:")
|
fmt.Println("Validate:")
|
||||||
req := cloudevents.NewEvent()
|
req := cloudevents.NewEvent()
|
||||||
req.SetID("1")
|
req.SetID("1")
|
||||||
req.SetSource("func:get")
|
req.SetSource("func:get")
|
||||||
req.SetType("func.test")
|
req.SetType("func.test")
|
||||||
c, err := cloudevents.NewClientHTTP(cloudevents.WithTarget("http://testinvoke.default.127.0.0.1.sslip.io"))
|
c, err := cloudevents.NewClientHTTP(cloudevents.WithTarget(targetUrl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -99,17 +110,20 @@ func bin() (path string, args []string) {
|
||||||
// func [subcommand] [flags]
|
// func [subcommand] [flags]
|
||||||
// and
|
// and
|
||||||
// kn func [subcommand] [flags]
|
// kn func [subcommand] [flags]
|
||||||
func run(t *testing.T, bin string, prefix []string, suffix ...string) {
|
func run(t *testing.T, bin string, prefix []string, suffix ...string) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
args := append(prefix, suffix...)
|
args := append(prefix, suffix...)
|
||||||
fmt.Printf("%v %v\n", bin, strings.Join(args, " "))
|
fmt.Printf("%v %v\n", bin, strings.Join(args, " "))
|
||||||
|
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
|
||||||
cmd := exec.Command(bin, args...)
|
cmd := exec.Command(bin, args...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
return stdout.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the contents of the given file
|
// set the contents of the given file
|
||||||
|
|
Loading…
Reference in New Issue