Files
zeekay bd81b9f2e2 canonical: hanzoai imports + hanzo.ai CRD group (de-fission)
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).
2026-07-19 23:37:32 -07:00

69 lines
1.6 KiB
Go

package httpserver
import (
"context"
"io"
"net/http"
"testing"
"github.com/gorilla/mux"
"github.com/hashicorp/go-retryablehttp"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/hanzoai/functions/pkg/utils/loggerfactory"
"github.com/hanzoai/functions/pkg/utils/manager"
)
func TestStartServer(t *testing.T) {
mgr := manager.New()
t.Cleanup(mgr.Wait)
ctx := t.Context()
logger := loggerfactory.GetLogger()
m := mux.NewRouter()
m.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("test handler"))
if err != nil {
logger.Error("failed to write response", zap.Error(err))
}
}))
mgr.Add(ctx, func(ctx context.Context) {
StartServer(ctx, logger, mgr, "test", "8999", m)
})
tests := []struct {
Name string
URL string
StatusCode int
Body string
}{
{
Name: "test handler",
URL: "http://localhost:8999",
StatusCode: http.StatusOK,
Body: "test handler",
},
{
Name: "not found",
URL: "http://localhost:8999/notfound",
StatusCode: http.StatusNotFound,
Body: "404 page not found\n",
},
}
client := retryablehttp.NewClient()
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
resp, err := client.Get(test.URL)
require.NoError(t, err, "failed to make get request %s", test.URL)
defer resp.Body.Close()
require.Equal(t, test.StatusCode, resp.StatusCode)
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, string(body), test.Body)
})
}
}