github.com/Odesyuk/pop@v4.13.1+incompatible/slices/uuid_test.go (about)

     1  package slices
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/gofrs/uuid"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Test_UUID_JSON_Unmarshal(t *testing.T) {
    13  	r := require.New(t)
    14  
    15  	a, err := uuid.NewV4()
    16  	r.NoError(err)
    17  	b, err := uuid.NewV4()
    18  	r.NoError(err)
    19  	x := fmt.Sprintf("[%q, %q]", a, b)
    20  	s := UUID{}
    21  	r.NoError(json.Unmarshal([]byte(x), &s))
    22  	r.Equal(UUID{a, b}, s)
    23  }
    24  
    25  func Test_UUID_JSON_Marshal(t *testing.T) {
    26  	r := require.New(t)
    27  
    28  	a, err := uuid.NewV4()
    29  	r.NoError(err)
    30  	b, err := uuid.NewV4()
    31  	r.NoError(err)
    32  	x := fmt.Sprintf("[%q,%q]", a, b)
    33  
    34  	s := UUID{a, b}
    35  	bb, err := json.Marshal(s)
    36  	r.NoError(err)
    37  	r.Equal(x, string(bb))
    38  }