* Update timetrigger crd and add method and subpath fields in spec. Update fission-cli to accept user input for method and subpath fields. Update publisher package to utilize these fields for triggering a function. Update timer controller to use method and subpath fields for publishing a request. Add a new test TestPublisherSubpath in pulisher package. Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io> * Use kubebuilder default annotation. Update test for fission-cli timetrigger create, update command to support method and subpath flags. Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io> --------- Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io>
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package publisher
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/fission/fission/pkg/utils/loggerfactory"
|
|
otelUtils "github.com/fission/fission/pkg/utils/otel"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPublisher(t *testing.T) {
|
|
fnName := "test-fn"
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "/"+fnName, r.URL.Path)
|
|
assert.Equal(t, "aaa", r.Header.Get("X-Fission-Test"))
|
|
assert.Contains(t, r.Header, "Traceparent")
|
|
}))
|
|
|
|
ctx := context.Background()
|
|
logger := loggerfactory.GetLogger()
|
|
shutdown, err := otelUtils.InitProvider(ctx, logger, fnName)
|
|
assert.NoError(t, err)
|
|
if shutdown != nil {
|
|
defer shutdown(ctx)
|
|
}
|
|
|
|
wp := MakeWebhookPublisher(logger, s.URL)
|
|
wp.Publish(ctx, "", map[string]string{"X-Fission-Test": "aaa"}, http.MethodPost, fnName)
|
|
time.Sleep(time.Second * 1)
|
|
}
|
|
|
|
func TestPublisherSubpath(t *testing.T) {
|
|
subpath := "/api/v1/read"
|
|
fnName := "test-fn-subpath"
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "/"+fnName+subpath, r.URL.Path)
|
|
assert.Equal(t, "aaa", r.Header.Get("X-Fission-Test"))
|
|
assert.Contains(t, r.Header, "Traceparent")
|
|
}))
|
|
|
|
ctx := context.Background()
|
|
logger := loggerfactory.GetLogger()
|
|
shutdown, err := otelUtils.InitProvider(ctx, logger, fnName)
|
|
assert.NoError(t, err)
|
|
if shutdown != nil {
|
|
defer shutdown(ctx)
|
|
}
|
|
|
|
wp := MakeWebhookPublisher(logger, s.URL)
|
|
wp.Publish(ctx, "", map[string]string{"X-Fission-Test": "aaa"}, http.MethodGet, fnName+subpath)
|
|
time.Sleep(time.Second * 1)
|
|
}
|