* skeleton for envtest fission * Refactor code and add CLI test * hack * Update server test * remove skip-ci for lint tests * Pass client go storagesvc * Add clientGen interface across code * Fix storagesvc test * Fix cmd client * add retry in server test * Fix concurrenct access to pool deployment * Remove old executor test * get rid of ginkgo/gomega * disable flaky test * flaky test * revert ci change * handle err from ParseBool --------- Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> Co-authored-by: Pranoy Kundu <pranoy1998k@gmail.com>
63 lines
1.5 KiB
Go
63 lines
1.5 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/fission/fission/pkg/utils/loggerfactory"
|
|
)
|
|
|
|
func TestStartServer(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
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))
|
|
}
|
|
}))
|
|
go StartServer(ctx, logger, "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)
|
|
})
|
|
}
|
|
}
|