2018-10-05 15:17:22 -04:00
|
|
|
package values_test
|
|
|
|
|
|
|
|
import (
|
2020-11-23 20:12:04 -05:00
|
|
|
"encoding/json"
|
2018-10-05 15:17:22 -04:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"testing"
|
2020-11-23 20:12:04 -05:00
|
|
|
"time"
|
2018-10-05 15:17:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDateTime(t *testing.T) {
|
|
|
|
Convey(".Hash", t, func() {
|
|
|
|
Convey("It should calculate hash", func() {
|
|
|
|
d := values.NewCurrentDateTime()
|
|
|
|
|
|
|
|
h := d.Hash()
|
|
|
|
|
|
|
|
So(h, ShouldBeGreaterThan, 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Hash sum should be consistent", func() {
|
|
|
|
d := values.NewCurrentDateTime()
|
|
|
|
|
|
|
|
So(d.Hash(), ShouldEqual, d.Hash())
|
|
|
|
})
|
|
|
|
})
|
2020-11-23 20:12:04 -05:00
|
|
|
|
|
|
|
Convey(".MarshalJSON", t, func() {
|
|
|
|
Convey("It should correctly serialize value", func() {
|
|
|
|
value := time.Now()
|
|
|
|
|
|
|
|
json1, err := json.Marshal(value)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
json2, err := values.NewDateTime(value).MarshalJSON()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
So(json1, ShouldResemble, json2)
|
|
|
|
})
|
|
|
|
})
|
2018-10-05 15:17:22 -04:00
|
|
|
}
|