github.com/hamba/avro@v1.8.0/config_internal_test.go (about)

     1  package avro
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/modern-go/reflect2"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestConfig_Freeze(t *testing.T) {
    11  	api := Config{
    12  		TagKey:      "test",
    13  		BlockLength: 2,
    14  	}.Freeze()
    15  	cfg := api.(*frozenConfig)
    16  
    17  	assert.Equal(t, "test", cfg.getTagKey())
    18  	assert.Equal(t, 2, cfg.getBlockLength())
    19  }
    20  
    21  func TestConfig_ReusesDecoders(t *testing.T) {
    22  	api := Config{
    23  		TagKey:      "test",
    24  		BlockLength: 2,
    25  	}.Freeze()
    26  	cfg := api.(*frozenConfig)
    27  
    28  	schema := MustParse(`"long"`)
    29  	var long int64
    30  	typ := reflect2.TypeOfPtr(&long)
    31  
    32  	dec1 := cfg.DecoderOf(schema, typ)
    33  	dec2 := cfg.DecoderOf(schema, typ)
    34  
    35  	assert.Equal(t, dec1, dec2)
    36  }
    37  
    38  func TestConfig_ReusesEncoders(t *testing.T) {
    39  	api := Config{
    40  		TagKey:      "test",
    41  		BlockLength: 2,
    42  	}.Freeze()
    43  	cfg := api.(*frozenConfig)
    44  
    45  	schema := MustParse(`"long"`)
    46  	var long int64
    47  	typ := reflect2.TypeOfPtr(long)
    48  
    49  	enc1 := cfg.EncoderOf(schema, typ)
    50  	enc2 := cfg.EncoderOf(schema, typ)
    51  
    52  	assert.Equal(t, enc1, enc2)
    53  }