chore: 初始开源发布
iotlcm-bot:独立飞书应用机器人(读取 Worker 终态 Run JSON,渲染并发送全量同步结果卡片)。
- Go module:git.5iot.com/iotlcm/iotlcm-bot → git.5iot.com/iotlcm-public/iotlcm-bot
- 飞书凭据占位:appId/appSecret/chatId → ${FEISHU_APP_ID}/${FEISHU_APP_SECRET}/${FEISHU_CHAT_ID}
- 移除内部资产:CI 触发器
- Dockerfile 改用公共基础镜像(golang:1.25-alpine → scratch)
- README 重写(命令/配置/挂载契约/常见问题),去掉内部环境路径
- 补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSendText(t *testing.T) {
|
||||
var gotText string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/open-apis/auth/v3/tenant_access_token/internal":
|
||||
_, _ = w.Write([]byte(`{"code":0,"tenant_access_token":"test-token","expire":7200}`))
|
||||
case "/open-apis/im/v1/messages":
|
||||
if r.URL.Query().Get("receive_id_type") != "chat_id" || r.Header.Get("Authorization") != "Bearer test-token" {
|
||||
t.Errorf("unexpected request: %s %s", r.URL.String(), r.Header.Get("Authorization"))
|
||||
}
|
||||
var payload struct {
|
||||
ReceiveID string `json:"receive_id"`
|
||||
MsgType string `json:"msg_type"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if payload.ReceiveID != "test-chat" || payload.MsgType != "text" {
|
||||
t.Errorf("unexpected payload: %+v", payload)
|
||||
}
|
||||
var content struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(payload.Content), &content); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
gotText = content.Text
|
||||
_, _ = w.Write([]byte(`{"code":0,"msg":"success"}`))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewClient("test-app", "test-secret", "test-chat")
|
||||
client.baseURL = server.URL
|
||||
message := "连接测试:含引号 \" 和换行\n第二行"
|
||||
if err := client.SendText(context.Background(), message); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if gotText != message {
|
||||
t.Fatalf("text mismatch: %q", gotText)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendTextRejectsEmpty(t *testing.T) {
|
||||
client := NewClient("test-app", "test-secret", "test-chat")
|
||||
if err := client.SendText(context.Background(), ""); err == nil || !strings.Contains(err.Error(), "text is required") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user