@@ -60,9 +60,9 @@ func TestBytesMarshalJSON(t *testing.T) {
6060 for _ , test := range tests {
6161 t .Run (test .name , func (t * testing.T ) {
6262 json , err := json .Marshal (test .bytes )
63- if test . wantErr != nil {
64- if err == nil {
65- t .Fatalf ("json.Marshal() error = nil , want %v " , test . wantErr )
63+ if err != nil {
64+ if test . wantErr == nil {
65+ t .Fatalf ("json.Marshal() error = %v , want nil " , err )
6666 }
6767 if ! errors .Is (err , test .wantErr ) {
6868 t .Fatalf ("json.Marshal() error = %v, want %v" , err , test .wantErr )
@@ -81,6 +81,7 @@ func TestBytesUnmarshalJSON(t *testing.T) {
8181 want Bytes
8282 wantErr error
8383 }{
84+ {name : "Empty bytes" , json : `{"value":0,"unit":""}` , want : zeroBytes , wantErr : nil },
8485 {name : "1000 B" , json : `{"value":1000,"unit":"B"}` , want : NewBytes (1000 , Byte ), wantErr : nil },
8586 {name : "1000 KB" , json : `{"value":1000,"unit":"KB"}` , want : NewBytes (1000 , Kilobyte ), wantErr : nil },
8687 {name : "1000 MB" , json : `{"value":1000,"unit":"MB"}` , want : NewBytes (1000 , Megabyte ), wantErr : nil },
@@ -101,9 +102,9 @@ func TestBytesUnmarshalJSON(t *testing.T) {
101102 t .Run (test .name , func (t * testing.T ) {
102103 var bytes Bytes
103104 err := json .Unmarshal ([]byte (test .json ), & bytes )
104- if test . wantErr != nil {
105- if err == nil {
106- t .Fatalf ("json.Unmarshal() error = nil , want %v " , test . wantErr )
105+ if err != nil {
106+ if test . wantErr == nil {
107+ t .Fatalf ("json.Unmarshal() error = %v , want nil " , err )
107108 }
108109 if ! errors .Is (err , test .wantErr ) {
109110 t .Fatalf ("json.Unmarshal() error = %v, want %v" , err , test .wantErr )
@@ -404,12 +405,11 @@ func TestBytesByteCountInUnitInt64(t *testing.T) {
404405 t .Run (test .name , func (t * testing.T ) {
405406 got , err := test .bytes .ByteCountInUnitInt64 (test .unit )
406407 if err != nil {
407- if test .wantErr != nil {
408- if ! errors .Is (err , test .wantErr ) {
409- t .Errorf ("Bytes.ByteCountInUnitInt64() = %v, want %v" , err , test .wantErr )
410- }
411- } else {
412- t .Errorf ("Bytes.ByteCountInUnitInt64() = %v, want %v" , err , test .wantErr )
408+ if test .wantErr == nil {
409+ t .Fatalf ("Bytes.ByteCountInUnitInt64() error = %v, want nil" , err )
410+ }
411+ if ! errors .Is (err , test .wantErr ) {
412+ t .Fatalf ("Bytes.ByteCountInUnitInt64() error = %v, want %v" , err , test .wantErr )
413413 }
414414 } else if got != test .want {
415415 t .Errorf ("Bytes.ByteCountInUnitInt64() = %v, want %v" , got , test .want )
@@ -434,12 +434,11 @@ func TestBytesByteCountInUnitInt32(t *testing.T) {
434434 t .Run (test .name , func (t * testing.T ) {
435435 got , err := test .bytes .ByteCountInUnitInt32 (test .unit )
436436 if err != nil {
437- if test .wantErr != nil {
438- if ! errors .Is (err , test .wantErr ) {
439- t .Errorf ("Bytes.ByteCountInUnitInt32() = %v, want %v" , err , test .wantErr )
440- }
441- } else {
442- t .Errorf ("Bytes.ByteCountInUnitInt32() = %v, want %v" , err , test .wantErr )
437+ if test .wantErr == nil {
438+ t .Fatalf ("Bytes.ByteCountInUnitInt32() error = %v, want nil" , err )
439+ }
440+ if ! errors .Is (err , test .wantErr ) {
441+ t .Fatalf ("Bytes.ByteCountInUnitInt32() error = %v, want %v" , err , test .wantErr )
443442 }
444443 } else if got != test .want {
445444 t .Errorf ("Bytes.ByteCountInUnitInt32() = %v, want %v" , got , test .want )
0 commit comments