检查点:保存项目生命周期实现与待修复回归

This commit is contained in:
xuans committed 2026-09-28 20:53:17 +08:00
1 parent fca7b796a9
commit dcca17e371
20 files changed
+1383 -27

No files matched your search

+1
View File
@@ -157,6 +157,7 @@ func NewWithConfigPath(ctx context.Context, cfg config.Config, configPath string
Config: cfg, ConfigPath: configPath, Logger: logger, Repository: repo, Servers: serverRepo, Users: userRepo, SSHKeys: sshKeys, DeploymentFactory: deployment.SSHFactory{Secrets: secretStore},
ProjectMembers: repository.NewSQLProjectMemberRepository(db.DB, runtimeDatabaseConfig.Driver),
ProjectDirectory: repository.NewSQLProjectMemberRepository(db.DB, runtimeDatabaseConfig.Driver),
ProjectLifecycle: repository.NewSQLProjectMemberRepository(db.DB, runtimeDatabaseConfig.Driver),
SetupDNS: dnsVerification, Secrets: secretStore, Firewall: firewall.NewManager(), AliyunChecker: aliyunAuthChecker,
IssueCertificate: workflow.IssueForHTTP,
IssueSetupCertificate: func(ctx context.Context, request certificate.SetupCertificateRequest) (certificate.SavedResource, error) {
@@ -0,0 +1,53 @@
package app
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"git.pcux.cn/xuans/Scert/backend/internal/domain"
)
// 走真实应用装配和会话登录,不能以测试夹具注入证明生产接线正确。
func TestApplicationWiresProjectLifecycleAPI(t *testing.T) {
cfg := readyApplicationConfig(t)
application, err := NewWithConfigPath(t.Context(), cfg, filepath.Join(cfg.Paths.Config, "scert.json"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = application.Close() })
var cookies []*http.Cookie
request := func(method, path, body string, status int) *httptest.ResponseRecorder {
t.Helper()
req := httptest.NewRequest(method, path, strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
for _, cookie := range cookies {
req.AddCookie(cookie)
}
response := httptest.NewRecorder()
application.HTTP.Handler().ServeHTTP(response, req)
if response.Code != status {
t.Fatalf("实际应用请求失败:%s %s,%d,%s", method, path, response.Code, response.Body.String())
}
return response
}
login := request(http.MethodPost, "/api/v1/auth/login", `{"identifier":"admin","password":"Test1234!"}`, 200)
cookies = login.Result().Cookies()
created := request(http.MethodPost, "/api/v1/projects", `{"name":"实际应用项目","description":"接线验证"}`, 201)
var item domain.Project
if err := json.Unmarshal(created.Body.Bytes(), &item); err != nil || item.ID == "" {
t.Fatalf("创建未返回标识:%v", err)
}
path := "/api/v1/projects/" + item.ID
request(http.MethodPut, path, `{"name":"修改后的项目"}`, 200)
directory := request(http.MethodGet, "/api/v1/projects?page_size=30", "", 200)
if !strings.Contains(directory.Body.String(), `"can_create_project":true`) || !strings.Contains(directory.Body.String(), "修改后的项目") {
t.Fatalf("真实目录未更新或缺少能力:%s", directory.Body.String())
}
request(http.MethodDelete, path, fmt.Sprintf(`{"confirmation":%q}`, item.ID), 204)
request(http.MethodPut, path, `{"name":"已删除项目"}`, 403)
}