github.com/tufanbarisyildirim/pop@v4.13.1+incompatible/nulls/uuid_test.go (about)

     1  package nulls_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/gobuffalo/pop/nulls"
     8  	"github.com/gofrs/uuid"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_UUID_UnmarshalJSON(t *testing.T) {
    13  	r := require.New(t)
    14  	id, err := uuid.NewV4()
    15  	r.NoError(err)
    16  
    17  	b, err := json.Marshal(id)
    18  	r.NoError(err)
    19  
    20  	nid := &nulls.UUID{}
    21  
    22  	r.NoError(nid.UnmarshalJSON(b))
    23  
    24  	r.True(nid.Valid)
    25  	r.Equal(id.String(), nid.UUID.String())
    26  }