Skip to content

Commit

Permalink
Move buffers package to internal, add some test coverage (uber-go#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv authored and Akshay Shah committed Feb 15, 2017
1 parent 3a0511d commit f370abc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export GO15VENDOREXPERIMENT=1
BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
PKGS ?= $(shell glide novendor)
# Many Go tools take file globs or directories as arguments instead of packages.
PKG_FILES ?= *.go zapcore buffers benchmarks testutils internal/exit
PKG_FILES ?= *.go zapcore benchmarks testutils internal/buffers internal/exit

# The linting tools evolve with each Go version, so run them only on the latest
# stable release.
Expand Down
2 changes: 1 addition & 1 deletion field.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"math"
"time"

"go.uber.org/zap/buffers"
"go.uber.org/zap/internal/buffers"
"go.uber.org/zap/zapcore"
)

Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions internal/buffers/buffers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package buffers

import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBuffers(t *testing.T) {
var wg sync.WaitGroup
for g := 0; g < 10; g++ {
wg.Add(1)
go func() {
for i := 0; i < 100; i++ {
buf := Get()
assert.Zero(t, len(buf), "Expected truncated buffer")
assert.NotZero(t, cap(buf), "Expected non-zero capacity")
Put(buf)
}
wg.Done()
}()
}
wg.Wait()
}
2 changes: 1 addition & 1 deletion zapcore/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sync"
"time"

"go.uber.org/zap/buffers"
"go.uber.org/zap/internal/buffers"
"go.uber.org/zap/internal/exit"
)

Expand Down

0 comments on commit f370abc

Please sign in to comment.