mirror of
https://github.com/hanzoai/functions.git
synced 2026-10-30 15:04:37 +00:00
Module github.com/fission/fission -> github.com/hanzoai/functions (288 files). CRD API group fission.io -> hanzo.ai (67 files): functions.hanzo.ai, environments.hanzo.ai, httptriggers.hanzo.ai, messagequeuetriggers.hanzo.ai, joining apps.hanzo.ai under the one house group. Doc URLs preserved. Builds green. Matches the cloud contract: clients/functions, /v1/functions, App CR role "function". Remaining: fork the env images + the live CRD-group migration (demo-only today, low risk).
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package publisher
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/hanzoai/functions/pkg/utils/loggerfactory"
|
|
otelUtils "github.com/hanzoai/functions/pkg/utils/otel"
|
|
)
|
|
|
|
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)
|
|
}
|