| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package bundler |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 "time" |
| 10 |
| 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) |
| 13 |
| 14 func TestDataPool(t *testing.T) { |
| 15 Convey(`A data pool registry`, t, func() { |
| 16 reg := dataPoolRegistry{} |
| 17 |
| 18 Convey(`Can retrieve a 1024-byte data pool.`, func() { |
| 19 pool := reg.getPool(1024) |
| 20 So(pool.size, ShouldEqual, 1024) |
| 21 |
| 22 Convey(`Subsequent requests return the same pool.`, func
() { |
| 23 So(reg.getPool(1024), ShouldEqual, pool) |
| 24 }) |
| 25 }) |
| 26 }) |
| 27 } |
| 28 |
| 29 func TestData(t *testing.T) { |
| 30 Convey(`A 512-byte data pool`, t, func() { |
| 31 pool := (&dataPoolRegistry{}).getPool(512) |
| 32 |
| 33 Convey(`Will allocate a clean 512-byte Data`, func() { |
| 34 d := pool.getData().(*streamData) |
| 35 defer d.Release() |
| 36 |
| 37 So(d, ShouldNotBeNil) |
| 38 So(len(d.Bytes()), ShouldEqual, 512) |
| 39 So(cap(d.Bytes()), ShouldEqual, 512) |
| 40 |
| 41 Convey(`When bound, adjusts its byte size and retains a
timestamp.`, func() { |
| 42 now := time.Date(2015, 1, 1, 0, 0, 0, 0, time.UT
C) |
| 43 data := [64]byte{} |
| 44 for i := range data { |
| 45 data[i] = byte(i) |
| 46 } |
| 47 |
| 48 copy(d.Bytes(), data[:]) |
| 49 So(d.Bind(len(data), now), ShouldEqual, d) |
| 50 So(d.Bytes(), ShouldResemble, data[:]) |
| 51 So(d.Len(), ShouldEqual, len(data)) |
| 52 So(d.Timestamp().Equal(now), ShouldBeTrue) |
| 53 }) |
| 54 }) |
| 55 }) |
| 56 } |
| OLD | NEW |