github.com/stripe/stripe-go/v76@v76.25.0/ephemeralkey_test.go (about)

     1  package stripe
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	assert "github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestEphemeralKey_UnmarshalJSON(t *testing.T) {
    11  	// Test that we can extract the json even if parsing fails because the
    12  	// frontend and backend may be using different API versions
    13  	invalidJSON := []byte("{\"foo\":5}")
    14  	key := &EphemeralKey{}
    15  
    16  	err := json.Unmarshal(invalidJSON, key)
    17  	assert.NoError(t, err)
    18  	assert.Empty(t, key.ID)
    19  	assert.Equal(t, invalidJSON, key.RawJSON)
    20  }