Files
QuoteForge/internal/handlers/setup_tls_test.go
T

38 lines
1.0 KiB
Go

package handlers
import (
"net/http"
"net/http/httptest"
"net/url"
"path/filepath"
"strings"
"testing"
"git.mchus.pro/mchus/quoteforge/internal/localdb"
"github.com/gin-gonic/gin"
)
func TestSetupFreshSettingsValidateTLS(t *testing.T) {
local, err := localdb.New(filepath.Join(t.TempDir(), "qfs.db"))
if err != nil {
t.Fatal(err)
}
defer local.Close()
handler := &SetupHandler{localDB: local}
for _, test := range []struct {
path string
handler gin.HandlerFunc
}{{"/setup/test", handler.TestConnection}, {"/setup", handler.SaveConnection}} {
router := gin.New()
router.POST(test.path, test.handler)
body := url.Values{"host": {"db.example"}, "user": {"example"}, "tls_mode": {"invalid"}}.Encode()
req := httptest.NewRequest(http.MethodPost, test.path, strings.NewReader(body))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusUnprocessableEntity {
t.Fatalf("%s: status=%d body=%s", test.path, w.Code, w.Body.String())
}
}
}