初始化

This commit is contained in:
李琦
2026-08-11 19:07:05 +08:00
commit d2aeb13a09
94 changed files with 8704 additions and 0 deletions

59
app_test.go Normal file
View File

@@ -0,0 +1,59 @@
package main
import (
"context"
"path/filepath"
"strings"
"testing"
)
func TestAppSaveProjectWritesProjectAndLog(t *testing.T) {
s, e := OpenStore(filepath.Join(t.TempDir(), "app.db"))
if e != nil {
t.Fatal(e)
}
defer s.db.Close()
a := &App{ctx: context.Background(), store: s, tasks: map[string]context.CancelFunc{}}
dir := t.TempDir()
p, e := a.SaveProject(0, ProjectInput{Name: "saved", Path: dir})
if e != nil {
t.Fatal(e)
}
if p.Path != dir {
t.Fatalf("path=%q", p.Path)
}
projects, e := s.ListProjects(0)
if e != nil {
t.Fatal(e)
}
if len(projects) != 1 {
t.Fatalf("projects=%d", len(projects))
}
logs, e := s.Logs("all")
if e != nil {
t.Fatal(e)
}
if len(logs) == 0 || logs[0].Message != "项目保存成功" {
t.Fatalf("missing save log: %#v", logs)
}
}
func TestAppSaveProjectFailureIsLogged(t *testing.T) {
s, e := OpenStore(filepath.Join(t.TempDir(), "app.db"))
if e != nil {
t.Fatal(e)
}
defer s.db.Close()
a := &App{ctx: context.Background(), store: s, tasks: map[string]context.CancelFunc{}}
_, e = a.SaveProject(0, ProjectInput{Name: "missing", Path: filepath.Join(t.TempDir(), "missing")})
if e == nil {
t.Fatal("invalid project saved")
}
logs, e := s.Logs("error")
if e != nil {
t.Fatal(e)
}
if len(logs) == 0 || !strings.Contains(logs[0].Detail, "PROJECT_PATH_NOT_FOUND") {
t.Fatalf("missing failure log: %#v", logs)
}
}