package caldav import ( "context" "errors" "net/http" "net/http/httptest" "testing" "github.com/emersion/go-webdav/internal" ) const queryCalendarMalformedResponse = ` /cal/good.ics "good" BEGIN:VCALENDAR VERSION:2.0 PRODID:-//go-webdav//test//EN BEGIN:VEVENT UID:good DTSTAMP:20260624T000000Z END:VEVENT END:VCALENDAR HTTP/1.1 200 OK /cal/bad.ics "bad" BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT UID:bad HTTP/1.1 200 OK ` func TestQueryCalendarMalformedObject(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/xml; charset=utf-8") w.WriteHeader(http.StatusMultiStatus) w.Write([]byte(queryCalendarMalformedResponse)) })) defer srv.Close() c, err := NewClient(http.DefaultClient, srv.URL) if err != nil { t.Fatalf("NewClient: %v", err) } objs, err := c.QueryCalendar(context.Background(), "/cal/", &CalendarQuery{ CompFilter: CompFilter{Name: "VCALENDAR"}, }) var hrefErr *internal.HrefError if !errors.As(err, &hrefErr) { t.Fatalf("QueryCalendar: want an *internal.HrefError, got %v", err) } if hrefErr.Href.Path != "/cal/bad.ics" { t.Errorf("HrefError.Href = %q, want %q", hrefErr.Href.Path, "/cal/bad.ics") } if len(objs) != 1 { t.Fatalf("got %d objects, want 1", len(objs)) } if objs[0].Path != "/cal/good.ics" || objs[0].ETag != "good" || objs[0].Data == nil { t.Errorf("got object %+v, want /cal/good.ics with ETag good and data", objs[0]) } }