1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
package ics
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSetDuration(t *testing.T) {
date, _ := time.Parse(time.RFC822, time.RFC822)
duration := time.Duration(float64(time.Hour) * 2)
testCases := []struct {
name string
start time.Time
end time.Time
output string
}{
{
name: "test set duration - start",
start: date,
output: `BEGIN:VEVENT
UID:test-duration
DTSTART:20060102T150400Z
DTEND:20060102T170400Z
END:VEVENT
`,
},
{
name: "test set duration - end",
end: date,
output: `BEGIN:VEVENT
UID:test-duration
DTEND:20060102T150400Z
DTSTART:20060102T130400Z
END:VEVENT
`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
e := NewEvent("test-duration")
if !tc.start.IsZero() {
e.SetStartAt(tc.start)
}
if !tc.end.IsZero() {
e.SetEndAt(tc.end)
}
err := e.SetDuration(duration)
// we're not testing for encoding here so lets make the actual output line breaks == expected line breaks
text := strings.Replace(e.Serialize(), "\r\n", "\n", -1)
assert.Equal(t, tc.output, text)
assert.Equal(t, nil, err)
})
}
}
|