package main import ( "path/filepath" "testing" ) func TestLaunchCategoryCRUD(t *testing.T) { s, e := OpenStore(filepath.Join(t.TempDir(), "cat.db")) if e != nil { t.Fatal(e) } defer s.db.Close() c, e := s.SaveLaunchCategory(LaunchCategory{Name: " 工作 "}) if e != nil || c.ID == 0 || c.Name != "工作" { t.Fatalf("save: %+v %v", c, e) } list, e := s.ListLaunchCategories() if e != nil || len(list) != 1 { t.Fatalf("list: %v %v", list, e) } app, e := s.SaveLaunchApp(LaunchApp{Name: "demo", Kind: "node", CategoryID: c.ID, Category: "前端"}) if e != nil { t.Fatal(e) } got, e := s.GetLaunchApp(app.ID) if e != nil || got.CategoryID != c.ID || got.Category != "前端" { t.Fatalf("app cats: %+v %v", got, e) } if e := s.DeleteLaunchCategory(c.ID); e != nil { t.Fatal(e) } got, e = s.GetLaunchApp(app.ID) if e != nil || got.CategoryID != 0 { t.Fatalf("after delete cat: %+v %v", got, e) } } func TestKindIconsLocal(t *testing.T) { s, e := OpenStore(filepath.Join(t.TempDir(), "kind.db")) if e != nil { t.Fatal(e) } defer s.db.Close() if e := s.setKindIcon("node", "data:image/png;base64,xx"); e != nil { t.Fatal(e) } m, e := s.ListKindIcons() if e != nil || m["node"] == "" { t.Fatalf("list: %v %v", m, e) } if e := s.clearKindIcon("node"); e != nil { t.Fatal(e) } m, e = s.ListKindIcons() if e != nil || len(m) != 0 { t.Fatalf("cleared: %v %v", m, e) } }