Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: emersion/go-webdav
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 96422a07deb3e64d073d4d7d155d3b51dfc44bca
Choose a base ref
..
head repository: emersion/go-webdav
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab37619919dfe6e3e8fa061fff7f136b360cfd5b
Choose a head ref
Showing with 116 additions and 51 deletions.
  1. +116 −34 caldav/server_test.go
  2. +0 −1 go.mod
  3. +0 −16 go.sum
150 changes: 116 additions & 34 deletions caldav/server_test.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"encoding/xml"
"fmt"
"github.com/emersion/go-webdav/internal"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"net/http/httptest"
@@ -87,40 +86,74 @@ func TestPropFindCalendar(t *testing.T) {

var ms internal.MultiStatus
err := xml.NewDecoder(resp.Body).Decode(&ms)
assert.NoError(t, err)
assert.Len(t, ms.Responses, 1)
assert.Len(t, ms.Responses[0].PropStats, 1)
assert.Equal(t, 200, ms.Responses[0].PropStats[0].Status.Code)
assert.Len(t, ms.Responses[0].PropStats[0].Prop.Raw, 4)
if err != nil {
t.Fatalf("Unexpcted error in xml.NewDecoder: %s", err)
}
if len(ms.Responses) != 1 {
t.Fatalf("Found %d multi status responses, expected 1", len(ms.Responses))
}
if len(ms.Responses[0].PropStats) != 1 {
t.Fatalf("Found %d prop stats, expected 1", len(ms.Responses[0].PropStats))
}
if ms.Responses[0].PropStats[0].Status.Code != 200 {
t.Fatalf("Received %d prop stat status, expected 200", ms.Responses[0].PropStats[0].Status.Code)
}
if len(ms.Responses[0].PropStats[0].Prop.Raw) != 4 {
t.Fatalf("Found %d props, expected 4", len(ms.Responses[0].PropStats[0].Prop.Raw))
}

rawDisplayName := ms.Responses[0].PropStats[0].Prop.Get(internal.DisplayNameName)
rawCalendarDescription := ms.Responses[0].PropStats[0].Prop.Get(calendarDescriptionName)
rawTimezone := ms.Responses[0].PropStats[0].Prop.Get(calendarTimezoneName)
rawColor := ms.Responses[0].PropStats[0].Prop.Get(calendarColorName)
assert.NotNil(t, rawDisplayName)
assert.NotNil(t, rawCalendarDescription)
assert.NotNil(t, rawTimezone)
assert.NotNil(t, rawColor)
if rawDisplayName == nil {
t.Fatal("Got unexpected nil rawDisplayName")
}
if rawCalendarDescription == nil {
t.Fatal("Got unexpected nil rawCalendarDescription")
}
if rawTimezone == nil {
t.Fatal("Got unexpected nil rawTimezone")
}
if rawColor == nil {
t.Fatal("Got unexpected nil rawColor")
}

v0 := internal.DisplayName{}
err = rawDisplayName.Decode(&v0)
assert.NoError(t, err)
assert.Equal(t, calendar.Name, v0.Name)
if err != nil {
t.Fatalf("Unexpcted error in rawDisplayName.Decode: %s", err)
}
if calendar.Name != v0.Name {
t.Fatalf("Calendar name is '%s', expected '%s'", calendar.Name, v0.Name)
}

v1 := calendarDescription{}
err = rawCalendarDescription.Decode(&v1)
assert.NoError(t, err)
assert.Equal(t, calendar.Description, v1.Description)
if err != nil {
t.Fatalf("Unexpcted error in rawCalendarDescription.Decode: %s", err)
}
if calendar.Description != v1.Description {
t.Fatalf("Calendar description is '%s', expected '%s'", calendar.Description, v1.Description)
}

v2 := calendarTimezone{}
err = rawTimezone.Decode(&v2)
assert.NoError(t, err)
assert.Equal(t, calendar.Timezone, v2.Timezone)
if err != nil {
t.Fatalf("Unexpcted error in rawTimezone.Decode: %s", err)
}
if calendar.Timezone != v2.Timezone {
t.Fatalf("Calendar timezone is '%s', expected '%s'", calendar.Timezone, v2.Timezone)
}

v3 := calendarColor{}
err = rawColor.Decode(&v3)
assert.NoError(t, err)
assert.Equal(t, calendar.Color, v3.Color)
if err != nil {
t.Fatalf("Unexpcted error in rawColor.Decode: %s", err)
}
if calendar.Color != v3.Color {
t.Fatalf("Calendar color is '%s', expected '%s'", calendar.Color, v3.Color)
}
}

var propFindUserPrincipal = `
@@ -399,15 +432,44 @@ func TestCreateCalendar(t *testing.T) {
req.Header.Set("Content-Type", "application/xml")

err := b.Mkcol(req)
assert.NoError(t, err)
assert.Len(t, tb.calendars, 1)
if err != nil {
t.Fatalf("Unexpcted error in Mkcol: %s", err)
}
if len(tb.calendars) != 1 {
t.Fatalf("Found %d calendars, expected 1", len(tb.calendars))
}
c := tb.calendars[0]
assert.Equal(t, "Test calendar", c.Name)
assert.Equal(t, "/dav/calendars/user0/test-calendar", c.Path)
assert.Equal(t, "A calendar for testing", c.Description)
assert.Equal(t, "#009688FF", c.Color)
assert.Equal(t, []string{"VEVENT", "VTODO", "VJOURNAL"}, c.SupportedComponentSet)
assert.Contains(t, c.Timezone, "BEGIN:VCALENDAR")
if c.Name != "Test calendar" {
t.Fatalf("Calendar name is '%s', expected 'Test calendar'", c.Name)
}
expectedPath := "/dav/calendars/user0/test-calendar"
if c.Path != expectedPath {
t.Fatalf("Calendar path is '%s', expected '%s'", c.Path, expectedPath)
}
expectedDescription := "A calendar for testing"
if c.Description != expectedDescription {
t.Fatalf("Calendar description is '%s', expected '%s'", c.Description, expectedDescription)
}
expectedColor := "#009688FF"
if c.Color != expectedColor {
t.Fatalf("Calendar color is '%s', expected '%s'", c.Color, expectedColor)
}
expectedTimezone := "BEGIN:VCALENDAR"
if !strings.Contains(c.Timezone, expectedTimezone) {
t.Fatalf("Calendar timezone is '%s', expected to contain '%s'", c.Timezone, expectedTimezone)
}
if len(c.SupportedComponentSet) != 3 {
t.Fatalf("Found %d SupportedComponentSet, expected 3", len(c.SupportedComponentSet))
}
if c.SupportedComponentSet[0] != "VEVENT" {
t.Fatalf("Calendar 0.SupportedComponentSet is '%s', expected '%s'", c.SupportedComponentSet[0], "VEVENT")
}
if c.SupportedComponentSet[1] != "VTODO" {
t.Fatalf("Calendar 1.SupportedComponentSet is '%s', expected '%s'", c.SupportedComponentSet[1], "VTODO")
}
if c.SupportedComponentSet[2] != "VJOURNAL" {
t.Fatalf("Calendar 2.SupportedComponentSet is '%s', expected '%s'", c.SupportedComponentSet[2], "VJOURNAL")
}
}

var mkcolRequestDataMinimalBody = `
@@ -440,15 +502,35 @@ func TestCreateCalendarMinimalBody(t *testing.T) {
req.Header.Set("Content-Type", "application/xml")

err := b.Mkcol(req)
assert.NoError(t, err)
assert.Len(t, tb.calendars, 1)
if err != nil {
t.Fatalf("Unexpcted error in Mkcol: %s", err)
}
if len(tb.calendars) != 1 {
t.Fatalf("Found %d calendars, expected 1", len(tb.calendars))
}
c := tb.calendars[0]
assert.Equal(t, "Test calendar", c.Name)
assert.Equal(t, "/dav/calendars/user0/test-calendar", c.Path)
assert.Equal(t, "", c.Description)
assert.Equal(t, "", c.Color)
assert.Equal(t, []string{}, c.SupportedComponentSet)
assert.Equal(t, "", c.Timezone)
if c.Name != "Test calendar" {
t.Fatalf("Calendar name is '%s', expected 'Test calendar'", c.Name)
}
expectedPath := "/dav/calendars/user0/test-calendar"
if c.Path != expectedPath {
t.Fatalf("Calendar path is '%s', expected '%s'", c.Path, expectedPath)
}
expectedDescription := ""
if c.Description != expectedDescription {
t.Fatalf("Calendar description is '%s', expected '%s'", c.Description, expectedDescription)
}
expectedColor := ""
if c.Color != expectedColor {
t.Fatalf("Calendar color is '%s', expected '%s'", c.Color, expectedColor)
}
expectedTimezone := ""
if c.Timezone != expectedTimezone {
t.Fatalf("Calendar timezone is '%s', expected '%s'", c.Timezone, expectedTimezone)
}
if len(c.SupportedComponentSet) != 0 {
t.Fatalf("Found %d SupportedComponentSet, expected 0", len(c.SupportedComponentSet))
}
}

type testBackend struct {
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -5,6 +5,5 @@ go 1.13
require (
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9
github.com/stretchr/testify v1.8.4 // indirect
github.com/teambition/rrule-go v1.8.2 // indirect
)
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f h1:feGUUxxvOtWVOhTko8Cbmp33a+tU0IMZxMEmnkoAISQ=
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f/go.mod h1:2MKFUgfNMULRxqZkadG1Vh44we3y5gJAtTBlVsx1BKQ=
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9 h1:ATgqloALX6cHCranzkLb8/zjivwQ9DWWDCQRnxTPfaA=
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/teambition/rrule-go v1.7.2/go.mod h1:mBJ1Ht5uboJ6jexKdNUJg2NcwP8uUMNvStWXlJD3MvU=
github.com/teambition/rrule-go v1.8.2 h1:lIjpjvWTj9fFUZCmuoVDrKVOtdiyzbzc93qTmRVe/J8=
github.com/teambition/rrule-go v1.8.2/go.mod h1:Ieq5AbrKGciP1V//Wq8ktsTXwSwJHDD5mD/wLBGl3p4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=