package srarchive_test import ( "fmt" "testing" "git.icedream.tech/icedream/gdq-archive/vod/pkg/srarchive" "github.com/stretchr/testify/assert" ) func TestSourceSetSpecifier_Marshal(t *testing.T) { for _, test := range []struct { Input srarchive.SourceSetSpecifier Want string }{ { Input: srarchive.SourceSetSpecifier{ Value: 123, DescriptorType: srarchive.Width, }, Want: `"123w"`, }, { Input: srarchive.SourceSetSpecifier{ Value: 2, DescriptorType: srarchive.PixelDensity, }, Want: `"2x"`, }, } { name := fmt.Sprintf("MarshalJSON %s", test.Input.String()) t.Run(name, func(t *testing.T) { got, err := test.Input.MarshalJSON() assert.NoError(t, err) assert.Equal(t, []byte(test.Want), got) }) name = fmt.Sprintf("UnmarshalJSON %s", test.Input.String()) t.Run(name, func(t *testing.T) { var got srarchive.SourceSetSpecifier err := got.UnmarshalJSON([]byte(test.Want)) assert.NoError(t, err) assert.Equal(t, test.Input.DescriptorType, got.DescriptorType) assert.Equal(t, test.Input.Value, got.Value) }) } }