chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)

This commit is contained in:
runny committed 2026-11-13 17:54:56 +08:00
commit 9097ee699d
5769 files changed
+1446466

No files matched your search

@@ -0,0 +1,65 @@
package handler
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
func TestPickHostProjectDirUnavailableWithoutDesktop(t *testing.T) {
gin.SetMode(gin.TestMode)
SetHostProjectPicker(nil)
t.Cleanup(func() { SetHostProjectPicker(nil) })
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/system/host-project-dir", nil)
(&SystemHandler{}).PickHostProjectDir(c)
require.Equal(t, http.StatusNotFound, w.Code)
}
func TestPickHostProjectDirReturnsPickedPath(t *testing.T) {
gin.SetMode(gin.TestMode)
SetHostProjectPicker(func() (string, error) {
return "/Users/dev/My Project", nil
})
t.Cleanup(func() { SetHostProjectPicker(nil) })
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/system/host-project-dir", nil)
(&SystemHandler{}).PickHostProjectDir(c)
require.Equal(t, http.StatusOK, w.Code)
var body struct {
Data struct {
Dir string `json:"dir"`
} `json:"data"`
}
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &body))
require.Equal(t, "/Users/dev/My Project", body.Data.Dir)
}
func TestPickHostProjectDirCancelReturnsEmptyDir(t *testing.T) {
gin.SetMode(gin.TestMode)
SetHostProjectPicker(func() (string, error) { return "", nil })
t.Cleanup(func() { SetHostProjectPicker(nil) })
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/system/host-project-dir", nil)
(&SystemHandler{}).PickHostProjectDir(c)
require.Equal(t, http.StatusOK, w.Code)
var body struct {
Data struct {
Dir string `json:"dir"`
} `json:"data"`
}
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &body))
require.Empty(t, body.Data.Dir)
}