mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
remove Nil/NotNil functions
This commit is contained in:
parent
ff0b0ac4b6
commit
df7cc4dff5
14
head_test.go
14
head_test.go
|
@ -204,8 +204,8 @@ func TestHead_Truncate(t *testing.T) {
|
|||
{minTime: 3000, maxTime: 3999},
|
||||
}, h.series.getByID(s2.ref).chunks)
|
||||
|
||||
testutil.Nil(t, h.series.getByID(s3.ref), "")
|
||||
testutil.Nil(t, h.series.getByID(s4.ref), "")
|
||||
testutil.Assert(t, h.series.getByID(s3.ref) == nil, "")
|
||||
testutil.Assert(t, h.series.getByID(s4.ref) == nil, "")
|
||||
|
||||
postingsA1, _ := expandPostings(h.postings.get("a", "1"))
|
||||
postingsA2, _ := expandPostings(h.postings.get("a", "2"))
|
||||
|
@ -218,8 +218,8 @@ func TestHead_Truncate(t *testing.T) {
|
|||
testutil.Equals(t, []uint64{s2.ref}, postingsA2)
|
||||
testutil.Equals(t, []uint64{s1.ref, s2.ref}, postingsB1)
|
||||
testutil.Equals(t, []uint64{s1.ref, s2.ref}, postingsAll)
|
||||
testutil.Nil(t, postingsB2, "")
|
||||
testutil.Nil(t, postingsC1, "")
|
||||
testutil.Assert(t, postingsB2 == nil, "")
|
||||
testutil.Assert(t, postingsC1 == nil, "")
|
||||
|
||||
testutil.Equals(t, map[string]struct{}{
|
||||
"": struct{}{}, // from 'all' postings list
|
||||
|
@ -252,13 +252,13 @@ func TestMemSeries_truncateChunks(t *testing.T) {
|
|||
lastID := s.chunkID(countBefore - 1)
|
||||
lastChunk := s.chunk(lastID)
|
||||
|
||||
testutil.NotNil(t, s.chunk(0), "")
|
||||
testutil.NotNil(t, lastChunk, "")
|
||||
testutil.Assert(t, s.chunk(0) != nil, "")
|
||||
testutil.Assert(t, lastChunk != nil, "")
|
||||
|
||||
s.truncateChunksBefore(2000)
|
||||
|
||||
testutil.Equals(t, int64(2000), s.chunks[0].minTime)
|
||||
testutil.Nil(t, s.chunk(0), "first chunks not gone")
|
||||
testutil.Assert(t, s.chunk(0) == nil, "first chunks not gone")
|
||||
testutil.Equals(t, countBefore/2, len(s.chunks))
|
||||
testutil.Equals(t, lastChunk, s.chunk(lastID))
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ func TestBigEndian(t *testing.T) {
|
|||
}
|
||||
|
||||
testutil.Assert(t, bep.Next() == false, "")
|
||||
testutil.Nil(t, bep.Err(), "")
|
||||
testutil.Assert(t, bep.Err() == nil, "")
|
||||
})
|
||||
|
||||
t.Run("Seek", func(t *testing.T) {
|
||||
|
@ -370,7 +370,7 @@ func TestBigEndian(t *testing.T) {
|
|||
for _, v := range table {
|
||||
testutil.Equals(t, v.found, bep.Seek(uint64(v.seek)))
|
||||
testutil.Equals(t, uint64(v.val), bep.At())
|
||||
testutil.Nil(t, bep.Err(), "")
|
||||
testutil.Assert(t, bep.Err() == nil, "")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -65,65 +65,3 @@ func Equals(tb testing.TB, exp, act interface{}) {
|
|||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// from stretchr/testify
|
||||
|
||||
// Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell
|
||||
|
||||
// Please consider promoting this project if you find it useful.
|
||||
|
||||
// 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.
|
||||
|
||||
// isNil checks if a specified object is nil or not, without Failing.
|
||||
func isNil(object interface{}) bool {
|
||||
if object == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
value := reflect.ValueOf(object)
|
||||
kind := value.Kind()
|
||||
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// modified from stretchr/testify
|
||||
// Nil asserts that the specified object is nil.
|
||||
//
|
||||
// assert.Nil(t, err)
|
||||
//
|
||||
// Returns whether the assertion was successful (true) or not (false).
|
||||
func Nil(tb testing.TB, object interface{}, msg string) {
|
||||
if !isNil(object) {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v to be nil\n\n\tmsg: %#v\033[39m\n\n", filepath.Base(file), line, object, msg)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func NotNil(tb testing.TB, object interface{}, msg string) {
|
||||
if isNil(object) {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v to not be nil\n\n\tmsg: %#v\033[39m\n\n", filepath.Base(file), line, object, msg)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue