github.com/MontFerret/ferret@v0.18.0/pkg/runtime/values/date_time_test.go (about)

     1  package values_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  	"time"
     7  
     8  	. "github.com/smartystreets/goconvey/convey"
     9  
    10  	"github.com/MontFerret/ferret/pkg/runtime/values"
    11  )
    12  
    13  func TestDateTime(t *testing.T) {
    14  	Convey(".Hash", t, func() {
    15  		Convey("It should calculate hash", func() {
    16  			d := values.NewCurrentDateTime()
    17  
    18  			h := d.Hash()
    19  
    20  			So(h, ShouldBeGreaterThan, 0)
    21  		})
    22  
    23  		Convey("Hash sum should be consistent", func() {
    24  			d := values.NewCurrentDateTime()
    25  
    26  			So(d.Hash(), ShouldEqual, d.Hash())
    27  		})
    28  	})
    29  
    30  	Convey(".MarshalJSON", t, func() {
    31  		Convey("It should correctly serialize value", func() {
    32  			value := time.Now()
    33  
    34  			json1, err := json.Marshal(value)
    35  			So(err, ShouldBeNil)
    36  
    37  			json2, err := values.NewDateTime(value).MarshalJSON()
    38  			So(err, ShouldBeNil)
    39  
    40  			So(json1, ShouldResemble, json2)
    41  		})
    42  	})
    43  }