flamingo.me/flamingo-commerce/v3@v3.11.0/cart/interfaces/graphql/dto/additional_data_test.go (about) 1 package dto_test 2 3 import ( 4 "testing" 5 6 "flamingo.me/flamingo-commerce/v3/cart/interfaces/graphql/dto" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestAttributes_Get(t *testing.T) { 11 t.Run("should return entry of map as key value pair value or nil if not found", func(t *testing.T) { 12 var tests = []struct { 13 inMap map[string]string 14 inKey string 15 out *dto.KeyValue 16 }{ 17 {map[string]string{"key": "true"}, "key", &dto.KeyValue{Key: "key", Value: "true"}}, 18 {map[string]string{"foo": "bar"}, "foo", &dto.KeyValue{Key: "foo", Value: "bar"}}, 19 {map[string]string{"foo": "bar"}, "bar", nil}, 20 {map[string]string{"key": "true"}, "notfound", nil}, 21 } 22 23 for _, tt := range tests { 24 t.Run("", func(t *testing.T) { 25 attr := dto.CustomAttributes{Attributes: tt.inMap} 26 value := attr.Get(tt.inKey) 27 assert.Equal(t, tt.out, value) 28 }) 29 } 30 }) 31 }