Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return a nil CalendarCompRequest when empty #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions caldav/caldav_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package caldav_test

import (
"testing"

"github.com/emersion/go-webdav/caldav"
)

func TestCalendarCompRequest_IsEmpty(b *testing.T) {
testCases := []struct {
Name string
Request caldav.CalendarCompRequest
ExpectedResult bool
}{
{
Name: "empty",
Request: caldav.CalendarCompRequest{},
ExpectedResult: true,
},
{
Name: "has-name",
Request: caldav.CalendarCompRequest{
Name: "name",
},
ExpectedResult: false,
},
}

for _, tCase := range testCases {
b.Run(tCase.Name, func(t *testing.T) {
if got, want := tCase.Request.Name == "", tCase.ExpectedResult; got != want { //nolint:scopelint
t.Errorf("bad result: %t, expected: %t", got, want)
}
})
}
}
8 changes: 7 additions & 1 deletion caldav/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (c *Client) FindCalendars(calendarHomeSet string) ([]Calendar, error) {
}

func encodeCalendarCompReq(c *CalendarCompRequest) (*comp, error) {
if c == nil || c.Name == "" {
return nil, nil
}

encoded := comp{Name: c.Name}

if c.AllProps {
Expand All @@ -123,7 +127,9 @@ func encodeCalendarCompReq(c *CalendarCompRequest) (*comp, error) {
if err != nil {
return nil, err
}
encoded.Comp = append(encoded.Comp, *encodedChild)
if encodedChild != nil {
encoded.Comp = append(encoded.Comp, *encodedChild)
}
}

return &encoded, nil
Expand Down