github.com/lestrrat-go/jwx/v2@v2.0.21/jwe/message_test.go (about) 1 package jwe_test 2 3 import ( 4 "testing" 5 6 "github.com/lestrrat-go/jwx/v2/internal/json" 7 8 "github.com/lestrrat-go/jwx/v2/jwe" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRecipient(t *testing.T) { 13 t.Run("JSON Marshaling", func(t *testing.T) { 14 const src = `{"header":{"foo":"bar"},"encrypted_key":"Zm9vYmFyYmF6"}` 15 r1 := jwe.NewRecipient() 16 17 if !assert.NoError(t, json.Unmarshal([]byte(src), r1), `json.Unmarshal should succeed`) { 18 return 19 } 20 21 buf, err := json.Marshal(r1) 22 if !assert.NoError(t, err, `json.Marshal should succeed`) { 23 return 24 } 25 26 if !assert.Equal(t, []byte(src), buf, `json representation should match`) { 27 return 28 } 29 }) 30 }