package lulu import ( "encoding/json" "testing" "github.com/stretchr/testify/require" ) func TestPkgId(t *testing.T) { t.Parallel() for _, pair := range []struct { j string pkg PkgId }{ { `"0850X1100.BW.STD.LW.060UW444.MNG"`, PkgId{ UsLetter, Mono, Standard, LinenWrap, P60UncoatedWhite, Matte, NavyLinen, GoldFoil}, }, { `"0600X0900.FC.STD.PB.080CW444.GXX"`, PkgId{ UsTrade, Color, Standard, Perfect, P80CoatedWhite, Gloss, NoLinen, NoFoil}, }, { `"0700X1000.FC.PRE.CO.060UC444.MXX"`, PkgId{ Executive, Color, Premium, Coil, P60UncoatedCream, Matte, NoLinen, NoFoil}, }, { `"0600X0900.BW.STD.PB.060UW444.MXX"`, PkgId{ UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Matte, NoLinen, NoFoil}, }, } { requireMarshalJsonEq(t, pair.j, pair.pkg) requireUnmarshalJsonEq(t, pair.pkg, pair.j) } } func TestUnmarshalInvalidPkgId(t *testing.T) { var pkg PkgId require.Error(t, json.Unmarshal([]byte(``), &pkg)) require.Error(t, json.Unmarshal([]byte(`""`), &pkg)) require.Error(t, json.Unmarshal([]byte(`"abc"`), &pkg)) require.Error(t, json.Unmarshal([]byte(`"9999X9999.XX.XXX.XX.999XX999.ZZZ"`), &pkg)) }