From ca6a4fccef0ef3854b9309cfccbc54baed773d97 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Wed, 21 May 2014 19:27:24 +0200 Subject: [PATCH] Weed out our homegrown test.Tester. The Go stdlib has testing.TB now, which fulfills the exact same purpose. Change-Id: I0db9c73400e208ca376b932a02b7e3402234b87c --- retrieval/scheduler_test.go | 7 ++++--- retrieval/targetmanager_test.go | 3 +-- retrieval/targetpool_test.go | 4 +--- rules/rules_test.go | 4 ++-- storage/metric/labelpair_test.go | 4 +--- storage/metric/tiered/end_to_end_test.go | 11 +++++----- storage/metric/tiered/helpers_test.go | 15 ++++++------- storage/metric/tiered/regressions_test.go | 3 +-- .../metric/tiered/rule_integration_test.go | 10 ++++----- storage/metric/tiered/stochastic_test.go | 16 +++++++------- storage/metric/tiered/tiered_test.go | 3 +-- storage/metric/tiered/view_test.go | 4 +--- storage/raw/leveldb/test/fixtures.go | 5 +++-- utility/test/directory.go | 5 +++-- utility/test/interface.go | 21 ------------------- 15 files changed, 44 insertions(+), 71 deletions(-) delete mode 100644 utility/test/interface.go diff --git a/retrieval/scheduler_test.go b/retrieval/scheduler_test.go index 39c19ac8c..decc4fe18 100644 --- a/retrieval/scheduler_test.go +++ b/retrieval/scheduler_test.go @@ -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 { @@ -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 diff --git a/retrieval/targetmanager_test.go b/retrieval/targetmanager_test.go index 501626194..bd46b3b9f 100644 --- a/retrieval/targetmanager_test.go +++ b/retrieval/targetmanager_test.go @@ -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 { @@ -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{ diff --git a/retrieval/targetpool_test.go b/retrieval/targetpool_test.go index 54897721f..52c4befd1 100644 --- a/retrieval/targetpool_test.go +++ b/retrieval/targetpool_test.go @@ -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 } diff --git a/rules/rules_test.go b/rules/rules_test.go index 2da3f390a..e25e4af7c 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -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()) @@ -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") diff --git a/storage/metric/labelpair_test.go b/storage/metric/labelpair_test.go index 50ebfedab..df3c3e8a9 100644 --- a/storage/metric/labelpair_test.go +++ b/storage/metric/labelpair_test.go @@ -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 diff --git a/storage/metric/tiered/end_to_end_test.go b/storage/metric/tiered/end_to_end_test.go index 94f5698bf..40a1ff10f 100644 --- a/storage/metric/tiered/end_to_end_test.go +++ b/storage/metric/tiered/end_to_end_test.go @@ -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", @@ -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, @@ -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, @@ -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", @@ -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", diff --git a/storage/metric/tiered/helpers_test.go b/storage/metric/tiered/helpers_test.go index ae15f2832..d8cb5f340 100644 --- a/storage/metric/tiered/helpers_test.go +++ b/storage/metric/tiered/helpers_test.go @@ -15,6 +15,7 @@ package tiered import ( "fmt" + "testing" "time" clientmodel "github.com/prometheus/client_golang/model" @@ -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) @@ -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() @@ -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{}) @@ -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()) diff --git a/storage/metric/tiered/regressions_test.go b/storage/metric/tiered/regressions_test.go index 84c484955..97b514eb4 100644 --- a/storage/metric/tiered/regressions_test.go +++ b/storage/metric/tiered/regressions_test.go @@ -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"}, diff --git a/storage/metric/tiered/rule_integration_test.go b/storage/metric/tiered/rule_integration_test.go index dea44ebc8..7d2ca993d 100644 --- a/storage/metric/tiered/rule_integration_test.go +++ b/storage/metric/tiered/rule_integration_test.go @@ -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 @@ -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 @@ -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 } @@ -927,7 +927,7 @@ 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 } @@ -935,7 +935,7 @@ func testMemoryGetRangeValues(t test.Tester) { 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 } diff --git a/storage/metric/tiered/stochastic_test.go b/storage/metric/tiered/stochastic_test.go index db931f647..a1ed24697 100644 --- a/storage/metric/tiered/stochastic_test.go +++ b/storage/metric/tiered/stochastic_test.go @@ -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, @@ -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)) @@ -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)) @@ -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), @@ -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() @@ -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) @@ -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 } diff --git a/storage/metric/tiered/tiered_test.go b/storage/metric/tiered/tiered_test.go index 0b2500904..cb549d5ff 100644 --- a/storage/metric/tiered/tiered_test.go +++ b/storage/metric/tiered/tiered_test.go @@ -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) { @@ -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 diff --git a/storage/metric/tiered/view_test.go b/storage/metric/tiered/view_test.go index 0de264ed4..9328dccac 100644 --- a/storage/metric/tiered/view_test.go +++ b/storage/metric/tiered/view_test.go @@ -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 diff --git a/storage/raw/leveldb/test/fixtures.go b/storage/raw/leveldb/test/fixtures.go index b9121ba8c..d04339f46 100644 --- a/storage/raw/leveldb/test/fixtures.go +++ b/storage/raw/leveldb/test/fixtures.go @@ -14,6 +14,7 @@ package test import ( + "testing" "code.google.com/p/goprotobuf/proto" "github.com/prometheus/prometheus/storage/raw/leveldb" @@ -50,7 +51,7 @@ type ( } preparer struct { - tester test.Tester + tester testing.TB } cassetteFactory struct { @@ -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} } diff --git a/utility/test/directory.go b/utility/test/directory.go index 4263fcf4b..35f30ffd9 100644 --- a/utility/test/directory.go +++ b/utility/test/directory.go @@ -16,6 +16,7 @@ package test import ( "io/ioutil" "os" + "testing" ) const ( @@ -50,7 +51,7 @@ type ( // their interactions. temporaryDirectory struct { path string - tester Tester + tester testing.TB } ) @@ -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 diff --git a/utility/test/interface.go b/utility/test/interface.go deleted file mode 100644 index e46e85f9e..000000000 --- a/utility/test/interface.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2013 Prometheus Team -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package test - -type Tester interface { - Error(args ...interface{}) - Errorf(format string, args ...interface{}) - Fatal(args ...interface{}) - Fatalf(format string, args ...interface{}) -}