Files
Enterprise-Knowledge-Base/internal/im/dingtalk/finalize_fail_closed_test.go
T
2026-07-16 00:17:16 +08:00

44 lines
1.1 KiB
Go

package dingtalk
import (
"context"
"errors"
"net/http"
"testing"
"time"
"github.com/Tencent/WeKnora/internal/im"
)
type failingCardRoundTripper struct{}
func (failingCardRoundTripper) RoundTrip(*http.Request) (*http.Response, error) {
return nil, errors.New("simulated delivery failure")
}
func TestFinalizeStreamPropagatesCardDeliveryFailure(t *testing.T) {
oldClient := httpClient
httpClient = &http.Client{Transport: failingCardRoundTripper{}, Timeout: time.Second}
t.Cleanup(func() { httpClient = oldClient })
adapter := &Adapter{
clientID: "robot",
token: "cached-token",
tokenExpAt: time.Now().Add(time.Hour),
}
streamID := "dt:fail-closed-test"
streamsMu.Lock()
dStreams[streamID] = &streamState{outTrackID: "track-id", createdAt: time.Now()}
streamsMu.Unlock()
t.Cleanup(func() {
streamsMu.Lock()
delete(dStreams, streamID)
streamsMu.Unlock()
})
err := adapter.FinalizeStream(context.Background(), &im.IncomingMessage{}, streamID, "image recognition failed")
if err == nil {
t.Fatal("expected final card delivery failure to propagate")
}
}