chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package im
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
)
|
||||
|
||||
type stubIMAgentService struct {
|
||||
interfaces.CustomAgentService
|
||||
agent *types.CustomAgent
|
||||
}
|
||||
|
||||
func (s *stubIMAgentService) GetAgentByID(_ context.Context, id string) (*types.CustomAgent, error) {
|
||||
if s.agent != nil && s.agent.ID == id {
|
||||
return s.agent, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func TestSetChannelAgentID(t *testing.T) {
|
||||
svc := &Service{
|
||||
agentService: &stubIMAgentService{
|
||||
agent: &types.CustomAgent{ID: "agent-new", TenantID: 42},
|
||||
},
|
||||
}
|
||||
channel := &IMChannel{
|
||||
ID: "im-1",
|
||||
TenantID: 42,
|
||||
AgentID: "agent-old",
|
||||
}
|
||||
|
||||
if err := svc.SetChannelAgentID(context.Background(), channel, "agent-new"); err != nil {
|
||||
t.Fatalf("SetChannelAgentID() error = %v", err)
|
||||
}
|
||||
if channel.AgentID != "agent-new" {
|
||||
t.Fatalf("channel.AgentID = %q, want agent-new", channel.AgentID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetChannelAgentIDRejectsForeignTenant(t *testing.T) {
|
||||
svc := &Service{
|
||||
agentService: &stubIMAgentService{
|
||||
agent: &types.CustomAgent{ID: "agent-new", TenantID: 99},
|
||||
},
|
||||
}
|
||||
channel := &IMChannel{
|
||||
ID: "im-1",
|
||||
TenantID: 42,
|
||||
AgentID: "agent-old",
|
||||
}
|
||||
|
||||
if err := svc.SetChannelAgentID(context.Background(), channel, "agent-new"); err == nil {
|
||||
t.Fatal("SetChannelAgentID() expected error for foreign tenant agent")
|
||||
}
|
||||
if channel.AgentID != "agent-old" {
|
||||
t.Fatalf("channel.AgentID = %q, want unchanged agent-old", channel.AgentID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetChannelAgentIDRequiresAgentID(t *testing.T) {
|
||||
svc := &Service{agentService: &stubIMAgentService{}}
|
||||
channel := &IMChannel{ID: "im-1", TenantID: 42, AgentID: "agent-old"}
|
||||
|
||||
if err := svc.SetChannelAgentID(context.Background(), channel, " "); err == nil {
|
||||
t.Fatal("SetChannelAgentID() expected error for empty agent_id")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user