diff options
Diffstat (limited to 'pkgid_test.go')
| -rw-r--r-- | pkgid_test.go | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/pkgid_test.go b/pkgid_test.go index 4a6120f..6a6865c 100644 --- a/pkgid_test.go +++ b/pkgid_test.go @@ -1,51 +1,73 @@ package lulu -import "testing" +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" +) func TestPkgId(t *testing.T) { t.Parallel() - requireJsonEq(t, - `"0850X1100.BW.STD.LW.060UW444.MNG"`, - PkgId{ - UsLetter, - Mono, - Standard, - LinenWrap, - P60UncoatedWhite, - Matte, - NavyLinen, - GoldFoil}) - requireJsonEq(t, - `"0600X0900.FC.STD.PB.080CW444.GXX"`, - PkgId{ - UsTrade, - Color, - Standard, - Perfect, - P80CoatedWhite, - Gloss, - NoLinen, - NoFoil}) - requireJsonEq(t, - `"0700X1000.FC.PRE.CO.060UC444.MXX"`, - PkgId{ - Executive, - Color, - Premium, - Coil, - P60UncoatedCream, - Matte, - NoLinen, - NoFoil}) - requireJsonEq(t, - `"0600X0900.BW.STD.PB.060UW444.MXX"`, - PkgId{ - UsTrade, - Mono, - Standard, - Perfect, - P60UncoatedWhite, - Matte, - NoLinen, - NoFoil}) + 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)) } |