初始化
This commit is contained in:
59
app_test.go
Normal file
59
app_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user