Cover the service nil-slice contract and the client normalization of a null payload. Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
852 B
Go
39 lines
852 B
Go
package traceimpact
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestListMethodsReturnEmptySlicesNotNil(t *testing.T) {
|
|
svc := NewService(nil)
|
|
ctx := context.Background()
|
|
|
|
items, err := svc.ListItems(ctx, 42)
|
|
if err != nil || items == nil {
|
|
t.Fatalf("ListItems items=%v err=%v", items, err)
|
|
}
|
|
index, err := svc.ListIndex(ctx, 42)
|
|
if err != nil || index == nil {
|
|
t.Fatalf("ListIndex index=%v err=%v", index, err)
|
|
}
|
|
marks, err := svc.ListOpenMarks(ctx, 42, "")
|
|
if err != nil || marks == nil {
|
|
t.Fatalf("ListOpenMarks marks=%v err=%v", marks, err)
|
|
}
|
|
|
|
raw, err := json.Marshal(map[string]any{
|
|
"items": items,
|
|
"index": index,
|
|
"recheck_marks": marks,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(raw), "null") {
|
|
t.Fatalf("empty lists encoded as JSON null: %s", raw)
|
|
}
|
|
}
|