jokes-bapak2/api/utils/date_test.go

48 lines
907 B
Go
Raw Normal View History

2021-07-09 12:13:19 +00:00
package utils_test
import (
2021-10-30 03:24:53 +00:00
"jokes-bapak2-api/utils"
2021-07-09 12:13:19 +00:00
"testing"
"time"
)
2021-08-04 05:56:14 +00:00
func TestIsToday_Today(t *testing.T) {
today, err := utils.IsToday(time.Now().Format(time.RFC3339))
if err != nil {
t.Error(err.Error())
}
if today == false {
t.Error("today should be true:", today)
}
}
2021-07-09 12:13:19 +00:00
2021-08-04 05:56:14 +00:00
func TestIsToday_NotToday(t *testing.T) {
today, err := utils.IsToday("2021-01-01T11:48:24Z")
if err != nil {
t.Error(err.Error())
}
if today == true {
t.Error("today should be false:", today)
}
}
2021-07-14 18:24:47 +00:00
2021-08-04 05:56:14 +00:00
func TestIsToday_ErrorIfEmpty(t *testing.T) {
today, err := utils.IsToday("")
if err != nil {
t.Error(err.Error())
}
if today != false {
t.Error("it should be false:", today)
}
2021-07-09 12:13:19 +00:00
}
2021-08-04 05:56:14 +00:00
func TestIsToday_ErrorIfInvalid(t *testing.T) {
today, err := utils.IsToday("asdfghjkl")
if err == nil {
t.Error("it should be error:", today, err)
}
if today != false {
t.Error("it should be false:", today)
}
2021-08-04 09:03:53 +00:00
}