Commit 11fa38ed authored by Pablo Carranza's avatar Pablo Carranza 🦄

Committing with a failing test just to make a point

You should never parse dates and times if you can avoid it. Just use the
date and time provided packages.
parent c7704022
Pipeline #13310223 failed with stage
in 40 seconds
package oncall
import (
"fmt"
"testing"
"time"
)
func TestOncallDates(t *testing.T) {
c := &Config{
OncallStartTime: "04:00:00",
OncallEndTime: "16:00:00",
}
tt := []struct {
offset int
start string
end string
}{
{
0,
fmt.Sprintf("%sT%sZ", time.Now().Format("2006-01-02"), c.OncallStartTime),
fmt.Sprintf("%sT%sZ", time.Now().Format("2006-01-02"), c.OncallEndTime),
},
{
1,
fmt.Sprintf("%sT%sZ", time.Now().Add(24*time.Hour).Format("2006-01-02"), c.OncallStartTime),
fmt.Sprintf("%sT%sZ", time.Now().Add(24*time.Hour).Format("2006-01-02"), c.OncallEndTime),
},
{
7,
fmt.Sprintf("%sT%sZ", time.Now().Add(24*7*time.Hour).Format("2006-01-02"), c.OncallStartTime),
fmt.Sprintf("%sT%sZ", time.Now().Add(24*7*time.Hour).Format("2006-01-02"), c.OncallEndTime),
},
}
for _, tc := range tt {
t.Run(fmt.Sprintf("With %d offset", tc.offset), func(t *testing.T) {
start, end := getOncallDates(c, tc.offset)
if tc.start != start {
t.Fatalf("incorrect start, expected %s; got %s", tc.start, start)
}
if tc.end != end {
t.Fatalf("incorrect end, expected %s; got %s", tc.end, end)
}
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment