statping/types/time_test.go

44 lines
829 B
Go
Raw Normal View History

2020-02-24 05:53:15 +00:00
package types
import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)
func TestFixedTime(t *testing.T) {
timeVal, err := time.Parse("2006-01-02T15:04:05Z", "2020-05-22T06:02:13Z")
require.Nil(t, err)
examples := []struct {
Time time.Time
Duration time.Duration
Expected string
}{{
timeVal,
time.Second,
"2020-05-22T06:02:13Z",
}, {
timeVal,
time.Minute,
"2020-05-22T06:02:00Z",
}, {
timeVal,
time.Hour,
"2020-05-22T06:00:00Z",
}, {
timeVal,
2020-03-02 07:53:46 +00:00
Day,
2020-02-24 05:53:15 +00:00
"2020-05-22T00:00:00Z",
}}
for _, e := range examples {
2020-03-08 01:23:41 +00:00
t.Logf("Testing is %v time converts to %v duration\n", e.Time.String(), e.Duration.String())
2020-02-24 05:53:15 +00:00
assert.Equal(t, e.Expected, FixedTime(e.Time, e.Duration), fmt.Sprintf("reformating for: %v %v", e.Time, e.Duration))
}
}