Skip to content

Commit

Permalink
Weed out our homegrown test.Tester.
Browse files Browse the repository at this point in the history
The Go stdlib has testing.TB now, which fulfills the exact same
purpose.

Change-Id: I0db9c73400e208ca376b932a02b7e3402234b87c
  • Loading branch information
Bjoern Rabenstein committed May 21, 2014
1 parent 23255f1 commit ca6a4fc
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 71 deletions.
7 changes: 4 additions & 3 deletions retrieval/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
package retrieval

import (
"github.com/prometheus/prometheus/utility"
"github.com/prometheus/prometheus/utility/test"
"testing"
"time"

"github.com/prometheus/prometheus/utility"
"github.com/prometheus/prometheus/utility/test"
)

type fakeHealthReporter struct {
Expand All @@ -33,7 +34,7 @@ func (h fakeHealthReporter) State() (state TargetState) {
return
}

func testHealthScheduler(t test.Tester) {
func testHealthScheduler(t testing.TB) {
now := time.Now()
var scenarios = []struct {
futureHealthState []TargetState
Expand Down
3 changes: 1 addition & 2 deletions retrieval/targetmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
pb "github.com/prometheus/prometheus/config/generated"

"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/utility/test"
)

type fakeTarget struct {
Expand Down Expand Up @@ -77,7 +76,7 @@ func (t *fakeTarget) Merge(newTarget Target) {}

func (t *fakeTarget) EstimatedTimeToExecute() time.Duration { return 0 }

func testTargetManager(t test.Tester) {
func testTargetManager(t testing.TB) {
targetManager := NewTargetManager(nopIngester{}, 3)
testJob1 := config.JobConfig{
JobConfig: pb.JobConfig{
Expand Down
4 changes: 1 addition & 3 deletions retrieval/targetpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import (
"sort"
"testing"
"time"

"github.com/prometheus/prometheus/utility/test"
)

func testTargetPool(t test.Tester) {
func testTargetPool(t testing.TB) {
type expectation struct {
size int
}
Expand Down
4 changes: 2 additions & 2 deletions rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (t testTieredStorageCloser) Close() {

// This is copied from storage/metric/helpers_test.go, which is unfortunate but
// presently required to make things work.
func NewTestTieredStorage(t test.Tester) (storage *tiered.TieredStorage, closer test.Closer) {
func NewTestTieredStorage(t testing.TB) (storage *tiered.TieredStorage, closer test.Closer) {
var directory test.TemporaryDirectory
directory = test.NewTemporaryDirectory("test_tiered_storage", t)
storage, err := tiered.NewTieredStorage(2500, 1000, 5*time.Second, 0*time.Second, directory.Path())
Expand All @@ -91,7 +91,7 @@ func NewTestTieredStorage(t test.Tester) (storage *tiered.TieredStorage, closer
return
}

func newTestStorage(t test.Tester) (storage *tiered.TieredStorage, closer test.Closer) {
func newTestStorage(t testing.TB) (storage *tiered.TieredStorage, closer test.Closer) {
storage, closer = NewTestTieredStorage(t)
if storage == nil {
t.Fatal("storage == nil")
Expand Down
4 changes: 1 addition & 3 deletions storage/metric/labelpair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ package metric
import (
"sort"
"testing"

"github.com/prometheus/prometheus/utility/test"
)

func testLabelPairs(t test.Tester) {
func testLabelPairs(t testing.TB) {
var scenarios = []struct {
in LabelPairs
out LabelPairs
Expand Down
11 changes: 5 additions & 6 deletions storage/metric/tiered/end_to_end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
clientmodel "github.com/prometheus/client_golang/model"

"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/utility/test"
)

func GetFingerprintsForLabelSetTests(p metric.Persistence, t test.Tester) {
func GetFingerprintsForLabelSetTests(p metric.Persistence, t testing.TB) {
metrics := []clientmodel.Metric{
{
clientmodel.MetricNameLabel: "test_metric",
Expand Down Expand Up @@ -153,7 +152,7 @@ func GetFingerprintsForLabelSetTests(p metric.Persistence, t test.Tester) {
}
}

func GetLabelValuesForLabelNameTests(p metric.Persistence, t test.Tester) {
func GetLabelValuesForLabelNameTests(p metric.Persistence, t testing.TB) {
testAppendSamples(p, &clientmodel.Sample{
Value: 0,
Timestamp: 0,
Expand Down Expand Up @@ -197,7 +196,7 @@ func GetLabelValuesForLabelNameTests(p metric.Persistence, t test.Tester) {
}
}

func GetMetricForFingerprintTests(p metric.Persistence, t test.Tester) {
func GetMetricForFingerprintTests(p metric.Persistence, t testing.TB) {
testAppendSamples(p, &clientmodel.Sample{
Value: 0,
Timestamp: 0,
Expand Down Expand Up @@ -308,7 +307,7 @@ func GetMetricForFingerprintTests(p metric.Persistence, t test.Tester) {
}
}

func AppendRepeatingValuesTests(p metric.Persistence, t test.Tester) {
func AppendRepeatingValuesTests(p metric.Persistence, t testing.TB) {
m := clientmodel.Metric{
clientmodel.MetricNameLabel: "errors_total",
"controller": "foo",
Expand Down Expand Up @@ -368,7 +367,7 @@ func AppendRepeatingValuesTests(p metric.Persistence, t test.Tester) {
}
}

func AppendsRepeatingValuesTests(p metric.Persistence, t test.Tester) {
func AppendsRepeatingValuesTests(p metric.Persistence, t testing.TB) {
m := clientmodel.Metric{
clientmodel.MetricNameLabel: "errors_total",
"controller": "foo",
Expand Down
15 changes: 8 additions & 7 deletions storage/metric/tiered/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package tiered

import (
"fmt"
"testing"
"time"

clientmodel "github.com/prometheus/client_golang/model"
Expand All @@ -29,14 +30,14 @@ var (
testInstant = clientmodel.TimestampFromTime(time.Date(1972, 7, 18, 19, 5, 45, 0, usEastern).In(time.UTC))
)

func testAppendSamples(p metric.Persistence, s *clientmodel.Sample, t test.Tester) {
func testAppendSamples(p metric.Persistence, s *clientmodel.Sample, t testing.TB) {
err := p.AppendSamples(clientmodel.Samples{s})
if err != nil {
t.Fatal(err)
}
}

func buildLevelDBTestPersistencesMaker(name string, t test.Tester) func() (metric.Persistence, test.Closer) {
func buildLevelDBTestPersistencesMaker(name string, t testing.TB) func() (metric.Persistence, test.Closer) {
return func() (metric.Persistence, test.Closer) {
temporaryDirectory := test.NewTemporaryDirectory("get_value_at_time", t)

Expand All @@ -49,8 +50,8 @@ func buildLevelDBTestPersistencesMaker(name string, t test.Tester) func() (metri
}
}

func buildLevelDBTestPersistence(name string, f func(p metric.Persistence, t test.Tester)) func(t test.Tester) {
return func(t test.Tester) {
func buildLevelDBTestPersistence(name string, f func(p metric.Persistence, t testing.TB)) func(t testing.TB) {
return func(t testing.TB) {

temporaryDirectory := test.NewTemporaryDirectory(fmt.Sprintf("test_leveldb_%s", name), t)
defer temporaryDirectory.Close()
Expand All @@ -67,8 +68,8 @@ func buildLevelDBTestPersistence(name string, f func(p metric.Persistence, t tes
}
}

func buildMemoryTestPersistence(f func(p metric.Persistence, t test.Tester)) func(t test.Tester) {
return func(t test.Tester) {
func buildMemoryTestPersistence(f func(p metric.Persistence, t testing.TB)) func(t testing.TB) {
return func(t testing.TB) {

p := NewMemorySeriesStorage(MemorySeriesOptions{})

Expand All @@ -88,7 +89,7 @@ func (t *testTieredStorageCloser) Close() {
t.directory.Close()
}

func NewTestTieredStorage(t test.Tester) (*TieredStorage, test.Closer) {
func NewTestTieredStorage(t testing.TB) (*TieredStorage, test.Closer) {
directory := test.NewTemporaryDirectory("test_tiered_storage", t)
storage, err := NewTieredStorage(2500, 1000, 5*time.Second, 0, directory.Path())

Expand Down
3 changes: 1 addition & 2 deletions storage/metric/tiered/regressions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
clientmodel "github.com/prometheus/client_golang/model"

"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/utility/test"
)

func GetFingerprintsForLabelSetUsesAndForLabelMatchingTests(p metric.Persistence, t test.Tester) {
func GetFingerprintsForLabelSetUsesAndForLabelMatchingTests(p metric.Persistence, t testing.TB) {
metrics := []clientmodel.LabelSet{
{clientmodel.MetricNameLabel: "request_metrics_latency_equal_tallying_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
{clientmodel.MetricNameLabel: "requests_metrics_latency_equal_accumulating_microseconds", "instance": "http://localhost:9090/metrics.json", "percentile": "0.010000"},
Expand Down
10 changes: 5 additions & 5 deletions storage/metric/tiered/rule_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/prometheus/prometheus/utility/test"
)

func GetValueAtTimeTests(persistenceMaker func() (metric.ViewablePersistence, test.Closer), t test.Tester) {
func GetValueAtTimeTests(persistenceMaker func() (metric.ViewablePersistence, test.Closer), t testing.TB) {
type value struct {
year int
month time.Month
Expand Down Expand Up @@ -356,7 +356,7 @@ func GetValueAtTimeTests(persistenceMaker func() (metric.ViewablePersistence, te
}
}

func GetRangeValuesTests(persistenceMaker func() (metric.ViewablePersistence, test.Closer), onlyBoundaries bool, t test.Tester) {
func GetRangeValuesTests(persistenceMaker func() (metric.ViewablePersistence, test.Closer), onlyBoundaries bool, t testing.TB) {
type value struct {
year int
month time.Month
Expand Down Expand Up @@ -899,7 +899,7 @@ func GetRangeValuesTests(persistenceMaker func() (metric.ViewablePersistence, te

// Test Definitions Follow

func testMemoryGetValueAtTime(t test.Tester) {
func testMemoryGetValueAtTime(t testing.TB) {
persistenceMaker := func() (metric.ViewablePersistence, test.Closer) {
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
}
Expand Down Expand Up @@ -927,15 +927,15 @@ func BenchmarkMemoryGetBoundaryValues(b *testing.B) {
}
}

func testMemoryGetRangeValues(t test.Tester) {
func testMemoryGetRangeValues(t testing.TB) {
persistenceMaker := func() (metric.ViewablePersistence, test.Closer) {
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
}

GetRangeValuesTests(persistenceMaker, false, t)
}

func testMemoryGetBoundaryValues(t test.Tester) {
func testMemoryGetBoundaryValues(t testing.TB) {
persistenceMaker := func() (metric.ViewablePersistence, test.Closer) {
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
}
Expand Down
16 changes: 8 additions & 8 deletions storage/metric/tiered/stochastic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import (

const stochasticMaximumVariance = 8

func BasicLifecycleTests(p metric.Persistence, t test.Tester) {
func BasicLifecycleTests(p metric.Persistence, t testing.TB) {
if p == nil {
t.Errorf("Received nil Metric Persistence.\n")
return
}
}

func ReadEmptyTests(p metric.Persistence, t test.Tester) {
func ReadEmptyTests(p metric.Persistence, t testing.TB) {
hasLabelPair := func(x int) (success bool) {
fingerprints, err := p.GetFingerprintsForLabelMatchers(metric.LabelMatchers{{
Type: metric.Equal,
Expand Down Expand Up @@ -89,7 +89,7 @@ func ReadEmptyTests(p metric.Persistence, t test.Tester) {
}
}

func AppendSampleAsPureSparseAppendTests(p metric.Persistence, t test.Tester) {
func AppendSampleAsPureSparseAppendTests(p metric.Persistence, t testing.TB) {
appendSample := func(x int) (success bool) {
v := clientmodel.SampleValue(x)
ts := clientmodel.TimestampFromUnix(int64(x))
Expand Down Expand Up @@ -118,7 +118,7 @@ func AppendSampleAsPureSparseAppendTests(p metric.Persistence, t test.Tester) {
}
}

func AppendSampleAsSparseAppendWithReadsTests(p metric.Persistence, t test.Tester) {
func AppendSampleAsSparseAppendWithReadsTests(p metric.Persistence, t testing.TB) {
appendSample := func(x int) (success bool) {
v := clientmodel.SampleValue(x)
ts := clientmodel.TimestampFromUnix(int64(x))
Expand Down Expand Up @@ -170,7 +170,7 @@ func AppendSampleAsSparseAppendWithReadsTests(p metric.Persistence, t test.Teste
}
}

func AppendSampleAsPureSingleEntityAppendTests(p metric.Persistence, t test.Tester) {
func AppendSampleAsPureSingleEntityAppendTests(p metric.Persistence, t testing.TB) {
appendSample := func(x int) bool {
sample := &clientmodel.Sample{
Value: clientmodel.SampleValue(x),
Expand Down Expand Up @@ -237,7 +237,7 @@ func (t timeslice) Less(i, j int) bool {
return t[i].Before(t[j])
}

func StochasticTests(persistenceMaker func() (metric.Persistence, test.Closer), t test.Tester) {
func StochasticTests(persistenceMaker func() (metric.Persistence, test.Closer), t testing.TB) {
stochastic := func(x int) (success bool) {
p, closer := persistenceMaker()
defer closer.Close()
Expand Down Expand Up @@ -528,7 +528,7 @@ func BenchmarkLevelDBAppendSampleAsPureSingleEntityAppend(b *testing.B) {
}
}

func testLevelDBStochastic(t test.Tester) {
func testLevelDBStochastic(t testing.TB) {
persistenceMaker := func() (metric.Persistence, test.Closer) {
temporaryDirectory := test.NewTemporaryDirectory("test_leveldb_stochastic", t)

Expand Down Expand Up @@ -613,7 +613,7 @@ func BenchmarkMemoryAppendSampleAsPureSingleEntityAppend(b *testing.B) {
}
}

func testMemoryStochastic(t test.Tester) {
func testMemoryStochastic(t testing.TB) {
persistenceMaker := func() (metric.Persistence, test.Closer) {
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
}
Expand Down
3 changes: 1 addition & 2 deletions storage/metric/tiered/tiered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/prometheus/prometheus/stats"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/utility/test"
)

func buildSamples(from, to clientmodel.Timestamp, interval time.Duration, m clientmodel.Metric) (v clientmodel.Samples) {
Expand Down Expand Up @@ -57,7 +56,7 @@ func buildValues(firstValue clientmodel.SampleValue, from, to clientmodel.Timest
return
}

func testMakeView(t test.Tester, flushToDisk bool) {
func testMakeView(t testing.TB, flushToDisk bool) {
type in struct {
atTime []getValuesAtTimeOp
atInterval []getValuesAtIntervalOp
Expand Down
4 changes: 1 addition & 3 deletions storage/metric/tiered/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import (
"time"

clientmodel "github.com/prometheus/client_golang/model"

"github.com/prometheus/prometheus/utility/test"
)

func testBuilder(t test.Tester) {
func testBuilder(t testing.TB) {
type atTime struct {
fingerprint string
time clientmodel.Timestamp
Expand Down
5 changes: 3 additions & 2 deletions storage/raw/leveldb/test/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package test

import (
"testing"
"code.google.com/p/goprotobuf/proto"

"github.com/prometheus/prometheus/storage/raw/leveldb"
Expand Down Expand Up @@ -50,7 +51,7 @@ type (
}

preparer struct {
tester test.Tester
tester testing.TB
}

cassetteFactory struct {
Expand Down Expand Up @@ -108,7 +109,7 @@ func (f *cassetteFactory) Next() (key proto.Message, value interface{}) {
}

// NewPreparer creates a new Preparer for use in testing scenarios.
func NewPreparer(t test.Tester) Preparer {
func NewPreparer(t testing.TB) Preparer {
return preparer{t}
}

Expand Down
5 changes: 3 additions & 2 deletions utility/test/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package test
import (
"io/ioutil"
"os"
"testing"
)

const (
Expand Down Expand Up @@ -50,7 +51,7 @@ type (
// their interactions.
temporaryDirectory struct {
path string
tester Tester
tester testing.TB
}
)

Expand All @@ -75,7 +76,7 @@ func (t temporaryDirectory) Path() string {

// NewTemporaryDirectory creates a new temporary directory for transient POSIX
// activities.
func NewTemporaryDirectory(name string, t Tester) (handler TemporaryDirectory) {
func NewTemporaryDirectory(name string, t testing.TB) (handler TemporaryDirectory) {
var (
directory string
err error
Expand Down
Loading

0 comments on commit ca6a4fc

Please sign in to comment.