* feat: add trace and timeout support for the timer Co-authored-by: gw123 <iamakillerforyou@gmail.com> Signed-off-by: saltbo <saltbo@foxmail.com> * fix: add error check for the lint Signed-off-by: saltbo <saltbo@foxmail.com> --------- Signed-off-by: saltbo <saltbo@foxmail.com> Co-authored-by: gw123 <iamakillerforyou@gmail.com>
35 lines
885 B
Go
35 lines
885 B
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"}, fnName)
|
|
time.Sleep(time.Second * 1)
|
|
}
|