Remove testify dependency

This commit is contained in:
2026-07-04 18:51:08 -04:00
parent 199e555e3d
commit 4a8b1768a1
20 changed files with 1335 additions and 495 deletions
+6 -4
View File
@@ -4,8 +4,6 @@ import (
"fmt"
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
)
// bstreamBytes writes (value, nbits) pairs and returns the encoded bytes.
@@ -144,8 +142,12 @@ func TestBstream(t *testing.T) {
r := newBReader(tc.data)
for i, op := range tc.reads {
got, err := r.readBits(op.nbits)
assert.Equal(t, op.wantVal, got, "op %d val (nbits=%d)", i, op.nbits)
assert.Equal(t, op.wantErr, err, "op %d err (nbits=%d)", i, op.nbits)
if got != op.wantVal {
t.Errorf("op %d val (nbits=%d): got %v, want %v", i, op.nbits, got, op.wantVal)
}
if err != op.wantErr {
t.Errorf("op %d err (nbits=%d): got %v, want %v", i, op.nbits, err, op.wantErr)
}
}
})
}
+46 -17
View File
@@ -6,9 +6,8 @@ import (
"fmt"
"math"
"math/rand"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
// encodeChunk builds a valid XOR chunk from samples and returns its bytes.
@@ -284,16 +283,28 @@ func TestXORChunk(t *testing.T) {
for i, r := range tc.reads {
next := it.Next()
gotT, gotV := it.At()
assert.Equal(t, r.wantNext, next, "read %d Next()", i)
assert.Equal(t, r.wantT, gotT, "read %d timestamp", i)
assert.Equal(t, r.wantVBits, math.Float64bits(gotV), "read %d value", i)
if next != r.wantNext {
t.Errorf("read %d Next(): got %v, want %v", i, next, r.wantNext)
}
if gotT != r.wantT {
t.Errorf("read %d timestamp: got %v, want %v", i, gotT, r.wantT)
}
if math.Float64bits(gotV) != r.wantVBits {
t.Errorf("read %d value: got %v, want %v", i, math.Float64bits(gotV), r.wantVBits)
}
}
if it.Err() != tc.wantIterErr {
t.Errorf("iter err: got %v, want %v", it.Err(), tc.wantIterErr)
}
assert.Equal(t, tc.wantIterErr, it.Err())
assert.LessOrEqual(t, len(tc.data), tc.maxBytes)
if !(len(tc.data) <= tc.maxBytes) {
t.Errorf("got %v bytes, want <= %v", len(tc.data), tc.maxBytes)
}
_, appErr := c.Appender()
assert.Equal(t, tc.wantAppenderErr, appErr)
if !reflect.DeepEqual(appErr, tc.wantAppenderErr) {
t.Errorf("appender err: got %v, want %v", appErr, tc.wantAppenderErr)
}
})
}
}
@@ -329,23 +340,39 @@ func TestXORChunkFromBytes(t *testing.T) {
reconstituted := XORChunkFromBytes(orig.Bytes())
assert.Equal(t, orig.NumSamples(), reconstituted.NumSamples())
assert.Equal(t, orig.Bytes(), reconstituted.Bytes())
if orig.NumSamples() != reconstituted.NumSamples() {
t.Errorf("NumSamples: got %v, want %v", reconstituted.NumSamples(), orig.NumSamples())
}
if !reflect.DeepEqual(orig.Bytes(), reconstituted.Bytes()) {
t.Errorf("Bytes mismatch")
}
// Verify iteration produces identical samples.
it := reconstituted.Iterator()
for i, s := range tc.samples {
assert.True(t, it.Next(), "sample %d", i)
if !it.Next() {
t.Errorf("sample %d: expected Next()=true", i)
}
gotT, gotV := it.At()
assert.Equal(t, int64(s[0]), gotT, "sample %d t", i)
assert.Equal(t, math.Float64bits(s[1]), math.Float64bits(gotV), "sample %d v", i)
if gotT != int64(s[0]) {
t.Errorf("sample %d t: got %v, want %v", i, gotT, int64(s[0]))
}
if math.Float64bits(gotV) != math.Float64bits(s[1]) {
t.Errorf("sample %d v: got %v, want %v", i, math.Float64bits(gotV), math.Float64bits(s[1]))
}
}
if it.Next() {
t.Errorf("expected Next()=false after all samples")
}
if it.Err() != nil {
t.Errorf("unexpected iter error: %v", it.Err())
}
assert.False(t, it.Next())
assert.NoError(t, it.Err())
// Appender on non-empty reconstituted chunk should fail.
_, err := reconstituted.Appender()
assert.Error(t, err)
if err == nil {
t.Errorf("expected error from Appender on non-empty chunk")
}
})
}
}
@@ -429,7 +456,9 @@ func TestBytesPerSample(t *testing.T) {
c := benchChunk(tc.gen)
bps := float64(len(c.Bytes())) / 120.0
t.Logf("%s: %.3f bytes/sample (%d bytes total)", tc.name, bps, len(c.Bytes()))
assert.LessOrEqual(t, bps, tc.max, "%s bytes/sample exceeds ceiling", tc.name)
if !(bps <= tc.max) {
t.Errorf("%s bytes/sample exceeds ceiling: got %v, want <= %v", tc.name, bps, tc.max)
}
})
}
}