示例#1
0
func (s *GeoSuite) TestEncode(c *C) {
	gto := new(geoTestObj)
	gto.Geo = NewGeo(10, -20)
	encoded, err := icalendar.Marshal(gto)
	c.Assert(err, IsNil)
	expected := fmt.Sprintf("BEGIN:VGEOTESTOBJ\r\nGEO:%f %f\r\nEND:VGEOTESTOBJ", gto.Geo.Lat(), gto.Geo.Lng())
	c.Assert(encoded, Equals, expected)
}
示例#2
0
func (s *EventSuite) TestFullEventMarshal(c *C) {
	now := time.Now().UTC()
	end := now.Add(time.Hour)
	oneDay := time.Hour * 24
	oneWeek := oneDay * 7
	event := NewEventWithEnd("1:2:3", now, end)
	uri, _ := url.Parse("http://taviti.com/some/attachment.ics")
	event.Attachment = values.NewUrl(*uri)
	event.Attendees = []*values.AttendeeContact{
		values.NewAttendeeContact("Jon Azoff", "*****@*****.**"),
		values.NewAttendeeContact("Matthew Davie", "*****@*****.**"),
	}
	event.Categories = values.NewCSV("vinyasa", "level 1")
	event.Comments = values.NewComments("Great class, 5 stars!", "I love this class!")
	event.ContactInfo = values.NewCSV("Send us an email!", "<*****@*****.**>")
	event.Created = event.DateStart
	event.Description = "An all-levels class combining strength and flexibility with breath"
	ex1 := values.NewDateTime(now.Add(oneWeek))
	ex2 := values.NewDateTime(now.Add(oneWeek * 2))
	event.ExceptionDateTimes = values.NewExceptionDateTimes(ex1, ex2)
	event.Geo = values.NewGeo(37.747643, -122.445400)
	event.LastModified = event.DateStart
	event.Location = values.NewLocation("Dolores Park")
	event.Organizer = values.NewOrganizerContact("Jon Azoff", "*****@*****.**")
	event.Priority = 1
	event.RecurrenceId = event.DateStart
	r1 := values.NewDateTime(now.Add(oneWeek + oneDay))
	r2 := values.NewDateTime(now.Add(oneWeek*2 + oneDay))
	event.RecurrenceDateTimes = values.NewRecurrenceDateTimes(r1, r2)
	event.AddRecurrenceRules(values.NewRecurrenceRule(values.WeekRecurrenceFrequency))
	uri, _ = url.Parse("*****@*****.**")
	event.RelatedTo = values.NewUrl(*uri)
	event.Resources = values.NewCSV("yoga mat", "towel")
	event.Sequence = 1
	event.Status = values.TentativeEventStatus
	event.Summary = "Jon's Super-Sweaty Vinyasa 1"
	event.TimeTransparency = values.OpaqueTimeTransparency
	uri, _ = url.Parse("http://student.taviti.com/san-francisco/jonathan-azoff/vinyasa-1")
	event.Url = values.NewUrl(*uri)
	enc, err := icalendar.Marshal(event)
	if err != nil {
		c.Fatal(err.Error())
	}
	tmpl := "BEGIN:VEVENT\r\nUID:1:2:3\r\nDTSTAMP:%sZ\r\nDTSTART:%sZ\r\nDTEND:%sZ\r\nCREATED:%sZ\r\n" +
		"DESCRIPTION:An all-levels class combining strength and flexibility with breath\r\n" +
		"GEO:37.747643 -122.445400\r\nLAST-MODIFIED:%sZ\r\nLOCATION:Dolores Park\r\n" +
		"ORGANIZER;CN=\"Jon Azoff\":MAILTO:[email protected]\r\nPRIORITY:1\r\nSEQUENCE:1\r\nSTATUS:TENTATIVE\r\n" +
		"SUMMARY:Jon's Super-Sweaty Vinyasa 1\r\nTRANSP:OPAQUE\r\n" +
		"URL;VALUE=URI:http://student.taviti.com/san-francisco/jonathan-azoff/vinyasa-1\r\n" +
		"RECURRENCE-ID:%sZ\r\nRRULE:FREQ=WEEKLY\r\nATTACH;VALUE=URI:http://taviti.com/some/attachment.ics\r\n" +
		"ATTENDEE;CN=\"Jon Azoff\":MAILTO:[email protected]\r\nATTENDEE;CN=\"Matthew Davie\":MAILTO:[email protected]\r\n" +
		"CATEGORIES:vinyasa,level 1\r\nCOMMENT:Great class, 5 stars!\r\nCOMMENT:I love this class!\r\n" +
		"CONTACT:Send us an email!,<*****@*****.**>\r\nEXDATE:%s,%s\r\nRDATE:%s,%s\r\n" +
		"RELATED-TO;VALUE=URI:[email protected]\r\nRESOURCES:yoga mat,towel\r\nEND:VEVENT"
	sdate := now.Format(values.DateTimeFormatString)
	edate := end.Format(values.DateTimeFormatString)
	c.Assert(enc, Equals, fmt.Sprintf(tmpl, sdate, sdate, edate, sdate, sdate, sdate, ex1, ex2, r1, r2))
}
示例#3
0
func (s *EventSuite) TestBasicWithDurationMarshal(c *C) {
	now := time.Now().UTC()
	event := NewEventWithDuration("test", now, time.Hour)
	enc, err := icalendar.Marshal(event)
	c.Assert(err, IsNil)
	tmpl := "BEGIN:VEVENT\r\nUID:test\r\nDTSTAMP:%sZ\r\nDTSTART:%sZ\r\nDURATION:PT1H\r\nEND:VEVENT"
	fdate := now.Format(values.DateTimeFormatString)
	c.Assert(enc, Equals, fmt.Sprintf(tmpl, fdate, fdate))
}
示例#4
0
// tests the current server for CalDAV support
func (s *TimezoneSuite) TestMarshal(c *C) {
	loc, err := time.LoadLocation("America/Los_Angeles")
	c.Assert(err, IsNil)
	tz := NewDynamicTimeZone(loc)
	enc, err := icalendar.Marshal(tz)
	c.Assert(err, IsNil)
	c.Assert(enc, Equals, "BEGIN:VTIMEZONE\r\nTZID:America/Los_Angeles\r\nX-LIC-LOCATION:America/Los_Angeles\r\n"+
		"TZURL;VALUE=URI:http://tzurl.org/zoneinfo/America/Los_Angeles\r\nEND:VTIMEZONE")
}
func (s *RecurrenceRuleSuite) TestEncode(c *C) {
	fs := "RRULE:FREQ=WEEKLY;UNTIL=%s;INTERVAL=2;" +
		"BYSECOND=3;BYMINUTE=4;BYHOUR=5,6;BYDAY=MO,TU;BYMONTHDAY=7,8;BYYEARDAY=9,10,11;" +
		"BYWEEKNO=12;BYMONTH=3;BYSETPOS=1;WKST=SU"
	expected := fmt.Sprintf(fs, s.RecurrenceRule.Until)
	actual, err := icalendar.Marshal(s.RecurrenceRule)
	c.Assert(err, IsNil)
	c.Assert(actual, Equals, expected)

}
示例#6
0
func (s *DateTimeSuite) TestMarshal(c *C) {
	l, err := time.LoadLocation("America/New_York")
	c.Assert(err, IsNil)
	t := time.Now().In(l)
	exdate := ExceptionDateTimes([]*DateTime{NewDateTime(t)})
	enc, err := icalendar.Marshal(&exdate)
	c.Assert(err, IsNil)
	expect := fmt.Sprintf("EXDATE;TZID=%s:%s", l, t.Format(DateTimeFormatString))
	c.Assert(enc, Equals, expect)
}
示例#7
0
func (s *EventSuite) TestBasicWithEndMarshal(c *C) {
	now := time.Now().UTC()
	end := now.Add(time.Hour)
	event := NewEventWithEnd("test", now, end)
	enc, err := icalendar.Marshal(event)
	c.Assert(err, IsNil)
	tmpl := "BEGIN:VEVENT\r\nUID:test\r\nDTSTAMP:%sZ\r\nDTSTART:%sZ\r\nDTEND:%sZ\r\nEND:VEVENT"
	sdate := now.Format(values.DateTimeFormatString)
	edate := end.Format(values.DateTimeFormatString)
	c.Assert(enc, Equals, fmt.Sprintf(tmpl, sdate, sdate, edate))
}
示例#8
0
func (s *ContactSuite) TestItentity(c *C) {

	before := NewOrganizerContact("Foo", "*****@*****.**")
	encoded, err := icalendar.Marshal(before)
	c.Assert(err, IsNil)

	after := new(OrganizerContact)
	err = icalendar.Unmarshal(encoded, after)
	c.Assert(err, IsNil)

	c.Assert(after, DeepEquals, before)

}
func (s *RecurrenceRuleSuite) TestIdentity(c *C) {

	encoded, err := icalendar.Marshal(s.RecurrenceRule)
	c.Assert(err, IsNil)

	after := new(RecurrenceRule)
	if err = icalendar.Unmarshal(encoded, after); err != nil {
		c.Fatal(err.Error())
	}

	c.Assert(after, DeepEquals, s.RecurrenceRule)

}
示例#10
0
func (s *GeoSuite) TestIdentity(c *C) {

	before := &geoTestObj{Geo: NewGeo(10, 20)}
	encoded, err := icalendar.Marshal(before)
	c.Assert(err, IsNil)

	after := new(geoTestObj)
	if err := icalendar.Unmarshal(encoded, after); err != nil {
		c.Fatal(err.Error())
	}

	c.Assert(after, DeepEquals, before)

}
示例#11
0
func (s *DateTimeSuite) TestItentity(c *C) {

	t := time.Now().UTC()

	before := RecurrenceDateTimes([]*DateTime{NewDateTime(t)})
	encoded, err := icalendar.Marshal(&before)
	c.Assert(err, IsNil)

	after := make(RecurrenceDateTimes, 0)
	err = icalendar.Unmarshal(encoded, &after)
	c.Assert(err, IsNil)

	c.Assert(after[0], DeepEquals, before[0])

}
示例#12
0
func icalToReadCloser(icaldata ...interface{}) (io.ReadCloser, error) {
	var buffer []string
	for _, icaldatum := range icaldata {
		if encoded, err := icalendar.Marshal(icaldatum); err != nil {
			return nil, utils.NewError(icalToReadCloser, "unable to encode as icalendar data", icaldatum, err)
		} else {
			//			log.Printf("OUT: %+v", encoded)
			buffer = append(buffer, encoded)
		}
	}
	if len(buffer) > 0 {
		var encoded = strings.Join(buffer, "\n")
		return ioutil.NopCloser(bytes.NewBuffer([]byte(encoded))), nil
	} else {
		return nil, nil
	}
}
示例#13
0
func (s *DurationSuite) TestIdentity(c *C) {

	type test struct {
		*Duration
	}

	before := &test{Duration: NewDuration(12*time.Hour + 10*time.Minute)}
	encoded, err := icalendar.Marshal(before)
	c.Assert(err, IsNil)

	after := new(test)
	err = icalendar.Unmarshal(encoded, after)
	c.Assert(err, IsNil)

	c.Assert(after, DeepEquals, before)

}
示例#14
0
func (s *ContactSuite) TestMarshalWithName(c *C) {
	o := NewOrganizerContact("Foo Bar", "*****@*****.**")
	enc, err := icalendar.Marshal(o)
	c.Assert(err, IsNil)
	c.Assert(enc, Equals, "ORGANIZER;CN=\"Foo Bar\":MAILTO:[email protected]")
}
示例#15
0
// tests the current server for CalDAV support
func (s *CalendarSuite) TestMarshal(c *C) {
	enc, err := icalendar.Marshal(s.calendar)
	c.Assert(err, IsNil)
	c.Assert(enc, Equals, "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//taviti/caldav-go//NONSGML v1.0.0//EN\r\nEND:VCALENDAR")
}
示例#16
0
func (s *ContactSuite) TestMarshalWithoutName(c *C) {
	o := NewAttendeeContact("", "*****@*****.**")
	enc, err := icalendar.Marshal(o)
	c.Assert(err, IsNil)
	c.Assert(enc, Equals, "ATTENDEE:MAILTO:[email protected]")
}
示例#17
0
func (s *EventSuite) TestMissingEndMarshal(c *C) {
	now := time.Now().UTC()
	event := NewEvent("test", now)
	_, err := icalendar.Marshal(event)
	c.Assert(err, ErrorMatches, "end date or duration must be set")
}