github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/bytesize/bytesize_test.go (about) 1 package bytesize 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 ) 7 8 var _ = Describe("bytesize package", func() { 9 Describe("Parse", func() { 10 It("works with valid values", func() { 11 Expect(Parse("1TB")).To(Equal(1 * TB)) 12 Expect(Parse("1 TB")).To(Equal(1 * TB)) 13 Expect(Parse(" 1 TB ")).To(Equal(1 * TB)) 14 Expect(Parse(" 1 TB ")).To(Equal(1 * TB)) 15 16 Expect(Parse("1.0TB")).To(BeNumerically("~", 1*TB, GB)) 17 Expect(Parse("1.9TB")).To(BeNumerically("~", 1*TB+921*GB, GB)) 18 19 Expect(Parse("1")).To(Equal(1 * Byte)) 20 Expect(Parse(" 1 ")).To(Equal(1 * Byte)) 21 22 Expect(Parse("1mb")).To(Equal(1 * MB)) 23 Expect(Parse("1mB")).To(Equal(1 * MB)) 24 }) 25 It("returns error with invalid values", func() { 26 _, err := Parse("1UB") 27 Expect(err).To(MatchError("could not parse ByteSize")) 28 }) 29 }) 30 })