fix(feishu): upload card markdown images
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package feishu
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFeishuThreadID_ThreadedReply(t *testing.T) {
|
||||
// Simulate: message is a reply in a thread (root_id is set)
|
||||
@@ -51,3 +55,37 @@ func TestFeishuMessageStruct_JSONFields(t *testing.T) {
|
||||
t.Errorf("MessageID zero value = %q, want empty", msg.MessageID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageCacheKey_StripsQuery(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"https://host/a.png?sig=1&t=2": "https://host/a.png",
|
||||
"https://host/a.png": "https://host/a.png",
|
||||
}
|
||||
for in, want := range cases {
|
||||
if got := imageCacheKey(in); got != want {
|
||||
t.Errorf("imageCacheKey(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveMarkdownImages_NoImageUnchanged(t *testing.T) {
|
||||
a := &Adapter{}
|
||||
in := "hello **world** [link](https://example.com)"
|
||||
if got := a.resolveMarkdownImages(context.Background(), "tok", in); got != in {
|
||||
t.Errorf("content without image was modified: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveMarkdownImages_FallbackToLinkOnFailure(t *testing.T) {
|
||||
a := &Adapter{}
|
||||
// A direct-IP loopback URL fails SSRF validation before any network call,
|
||||
// so the image must degrade to a plain markdown link (never left as ![]()).
|
||||
in := "see  here"
|
||||
got := a.resolveMarkdownImages(context.Background(), "tok", in)
|
||||
if strings.Contains(got, "") {
|
||||
t.Errorf("expected link fallback with alt text, got: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user