package caldav import ( "context" "net/http" "net/http/httptest" "testing" ) const findCalendarsReadOnlyResponse = ` /cal/read-only/ HTTP/1.1 200 OK /cal/write-content/ HTTP/1.1 200 OK /cal/write/ HTTP/1.1 200 OK /cal/unknown/ HTTP/1.1 200 OK HTTP/1.1 404 Not Found ` func TestFindCalendarsReadOnly(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(findCalendarsReadOnlyResponse)) })) defer srv.Close() c, err := NewClient(http.DefaultClient, srv.URL) if err != nil { t.Fatalf("NewClient: %v", err) } cals, err := c.FindCalendars(context.Background(), "/cal/") if err != nil { t.Fatalf("FindCalendars: %v", err) } want := map[string]bool{ "/cal/read-only/": true, "/cal/write-content/": true, "/cal/write/": false, "/cal/unknown/": false, } if len(cals) != len(want) { t.Fatalf("got %d calendars, want %d", len(cals), len(want)) } for _, cal := range cals { if cal.ReadOnly != want[cal.Path] { t.Errorf("%s: ReadOnly = %v, want %v", cal.Path, cal.ReadOnly, want[cal.Path]) } } }