diff --git a/v1/bytes.go b/v1/bytes.go index 465a48ee..06c3204b 100644 --- a/v1/bytes.go +++ b/v1/bytes.go @@ -10,7 +10,7 @@ import ( ) var ( - zeroBytes = Bytes{value: 0, unit: Byte} + zero = Bytes{} ErrBytesInvalidUnit = errors.New("invalid unit") ErrBytesNotAnInt64 = errors.New("byte count is not an int64") @@ -128,7 +128,7 @@ func (b *Bytes) UnmarshalJSON(data []byte) error { } if bytesJSON.Value == 0 && bytesJSON.Unit == "" { - *b = zeroBytes + *b = zero return nil } diff --git a/v1/bytes_test.go b/v1/bytes_test.go index dbed83ed..e3b9bb2e 100644 --- a/v1/bytes_test.go +++ b/v1/bytes_test.go @@ -81,7 +81,7 @@ func TestBytesUnmarshalJSON(t *testing.T) { want Bytes wantErr error }{ - {name: "Empty bytes", json: `{"value":0,"unit":""}`, want: zeroBytes, wantErr: nil}, + {name: "Empty bytes", json: `{"value":0,"unit":""}`, want: zero, wantErr: nil}, {name: "1000 B", json: `{"value":1000,"unit":"B"}`, want: NewBytes(1000, Byte), wantErr: nil}, {name: "1000 KB", json: `{"value":1000,"unit":"KB"}`, want: NewBytes(1000, Kilobyte), wantErr: nil}, {name: "1000 MB", json: `{"value":1000,"unit":"MB"}`, want: NewBytes(1000, Megabyte), wantErr: nil}, @@ -94,8 +94,8 @@ func TestBytesUnmarshalJSON(t *testing.T) { {name: "1000 TiB", json: `{"value":1000,"unit":"TiB"}`, want: NewBytes(1000, Tebibyte), wantErr: nil}, {name: "1000 PiB", json: `{"value":1000,"unit":"PiB"}`, want: NewBytes(1000, Pebibyte), wantErr: nil}, - {name: "Empty unit", json: `{"value":1000,"unit":""}`, want: zeroBytes, wantErr: ErrBytesInvalidUnit}, - {name: "Invalid unit", json: `{"value":1000,"unit":"invalid"}`, want: zeroBytes, wantErr: ErrBytesInvalidUnit}, + {name: "Empty unit", json: `{"value":1000,"unit":""}`, want: zero, wantErr: ErrBytesInvalidUnit}, + {name: "Invalid unit", json: `{"value":1000,"unit":"invalid"}`, want: zero, wantErr: ErrBytesInvalidUnit}, } for _, test := range tests {