safesight/control/internal/service/template_test.go
tian 98e375dc36 chore: 合并 safesight-control 仓库为 control/ 子目录
项目合并为单仓库:设备端(根) + 管理端(control/)。
两端 git 历史完整保留(git subtree 合并)。

git-subtree-dir: control
git-subtree-mainline: 923ab10d5c
git-subtree-split: 70738edb31
2026-08-02 11:13:26 +08:00

51 lines
1.1 KiB
Go

package service
import (
"safesight-control/internal/config"
"os"
"testing"
)
func TestTemplateService(t *testing.T) {
// Ensure templates dir exists relative to test execution (which is internal/service)
_ = os.MkdirAll("templates", 0755)
// Create a dummy template for test
content := `{
"name": "test-template",
"schema": {},
"body": {}
}`
_ = os.WriteFile("templates/test-template.json", []byte(content), 0644)
defer os.RemoveAll("templates")
cfg := &config.Config{}
svc := NewTemplateService(cfg)
list, err := svc.ListTemplates()
if err != nil {
t.Fatalf("failed to list templates: %v", err)
}
found := false
for _, tpl := range list {
if tpl.Name == "test-template" {
found = true
break
}
}
if !found {
t.Error("expected test-template to be found")
}
tpl, err := svc.GetTemplate("test-template")
if err != nil {
t.Fatalf("failed to get template: %v", err)
}
if tpl.Name != "test-template" {
t.Errorf("expected test-template, got %s", tpl.Name)
}
}