Merge pull request #39 from nspcc-dev/fix/object_size_NaN

Fix NaN ObjectSize
This commit is contained in:
Evgeniy Kulikov 2020-01-27 15:14:19 +03:00 committed by GitHub
commit b9107680bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View file

@ -39,8 +39,8 @@ type (
) )
const ( const (
// UnitsB starts enum for amount of bytes. // starts enum for amount of bytes.
UnitsB int64 = 1 << (10 * iota) _ int64 = 1 << (10 * iota)
// UnitsKB defines amount of bytes in one kilobyte. // UnitsKB defines amount of bytes in one kilobyte.
UnitsKB UnitsKB

View file

@ -32,7 +32,7 @@ func (b ByteSize) String() string {
case num > UnitsKB: case num > UnitsKB:
unit = "KB" unit = "KB"
dec = UnitsKB dec = UnitsKB
case num > UnitsB: default:
dec = 1 dec = 1
} }

View file

@ -7,11 +7,16 @@ import (
) )
func TestByteSize_String(t *testing.T) { func TestByteSize_String(t *testing.T) {
var cases = []struct { cases := []struct {
name string name string
expect string expect string
actual ByteSize actual ByteSize
}{ }{
{
name: "0 bytes",
expect: "0",
actual: ByteSize(0),
},
{ {
name: "101 bytes", name: "101 bytes",
expect: "101", expect: "101",