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
+42 -16
View File
@@ -9,15 +9,15 @@ import (
"git.dvdt.dev/david/ingot/internal/block"
"git.dvdt.dev/david/ingot/internal/chunkenc"
"git.dvdt.dev/david/ingot/labels"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func makeChunk(t *testing.T, samples []struct{ t int64; v float64 }) []byte {
t.Helper()
c := chunkenc.NewXORChunk()
a, err := c.Appender()
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, s := range samples {
a.Append(s.t, s.v)
}
@@ -51,7 +51,9 @@ func setupTestData(t *testing.T) string {
}
_, err := block.Flush(dir, series)
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
return dir
}
@@ -59,7 +61,9 @@ func setupTestData(t *testing.T) string {
func blockDir(t *testing.T, dataDir string) string {
t.Helper()
entries, err := os.ReadDir(dataDir)
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, e := range entries {
if e.IsDir() && e.Name() != "wal" {
return filepath.Join(dataDir, e.Name())
@@ -124,10 +128,16 @@ func TestCmdBlocks(t *testing.T) {
return cmdErr
}()
assert.Equal(t, tc.wantErr != "", err != nil, "error presence")
assert.Contains(t, errString(err), tc.wantErr)
if got := (err != nil); got != (tc.wantErr != "") {
t.Errorf("error presence: got %v, want %v", got, tc.wantErr != "")
}
if !strings.Contains(errString(err), tc.wantErr) {
t.Errorf("got %q, want substring %q", errString(err), tc.wantErr)
}
for _, want := range tc.wantOutputs {
assert.Contains(t, output, want)
if !strings.Contains(output, want) {
t.Errorf("got %q, want substring %q", output, want)
}
}
})
}
@@ -166,10 +176,16 @@ func TestCmdInspect(t *testing.T) {
return cmdErr
}()
assert.Equal(t, tc.wantErr != "", err != nil, "error presence")
assert.Contains(t, errString(err), tc.wantErr)
if got := (err != nil); got != (tc.wantErr != "") {
t.Errorf("error presence: got %v, want %v", got, tc.wantErr != "")
}
if !strings.Contains(errString(err), tc.wantErr) {
t.Errorf("got %q, want substring %q", errString(err), tc.wantErr)
}
for _, want := range tc.wantOutputs {
assert.Contains(t, output, want)
if !strings.Contains(output, want) {
t.Errorf("got %q, want substring %q", output, want)
}
}
})
}
@@ -220,10 +236,16 @@ func TestCmdChunks(t *testing.T) {
return cmdErr
}()
assert.Equal(t, tc.wantErr != "", err != nil, "error presence")
assert.Contains(t, errString(err), tc.wantErr)
if got := (err != nil); got != (tc.wantErr != "") {
t.Errorf("error presence: got %v, want %v", got, tc.wantErr != "")
}
if !strings.Contains(errString(err), tc.wantErr) {
t.Errorf("got %q, want substring %q", errString(err), tc.wantErr)
}
for _, want := range tc.wantOutputs {
assert.Contains(t, output, want)
if !strings.Contains(output, want) {
t.Errorf("got %q, want substring %q", output, want)
}
}
})
}
@@ -263,8 +285,12 @@ func TestCmdFsck(t *testing.T) {
return cmdErr
}()
assert.Equal(t, tc.wantErr != "", err != nil, "error presence")
assert.Contains(t, errString(err), tc.wantErr)
if got := (err != nil); got != (tc.wantErr != "") {
t.Errorf("error presence: got %v, want %v", got, tc.wantErr != "")
}
if !strings.Contains(errString(err), tc.wantErr) {
t.Errorf("got %q, want substring %q", errString(err), tc.wantErr)
}
})
}
}
+39 -15
View File
@@ -10,14 +10,14 @@ import (
"git.dvdt.dev/david/ingot"
"git.dvdt.dev/david/ingot/labels"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func openTestDB(t *testing.T) *ingot.DB {
t.Helper()
db, err := ingot.Open(t.TempDir(), ingot.Options{})
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
t.Cleanup(func() { db.Close() })
return db
}
@@ -26,12 +26,20 @@ func seedDB(t *testing.T, db *ingot.DB) {
t.Helper()
app := db.Appender()
ref, err := app.Append(0, labels.FromStrings("__name__", "temp", "room", "office"), 1000, 71.3)
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
_, err = app.Append(ref, nil, 2000, 71.4)
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
_, err = app.Append(0, labels.FromStrings("__name__", "humidity", "room", "office"), 1000, 55.0)
require.NoError(t, err)
require.NoError(t, app.Commit())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if err := app.Commit(); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
func TestQueryRange(t *testing.T) {
@@ -117,12 +125,16 @@ func TestQueryRange(t *testing.T) {
rec := httptest.NewRecorder()
h.queryRange(rec, req)
assert.Equal(t, tc.wantStatus, rec.Code)
if rec.Code != tc.wantStatus {
t.Errorf("got %v, want %v", rec.Code, tc.wantStatus)
}
// Always decode — error responses produce zero-valued struct.
var resp queryRangeResponse
json.Unmarshal(rec.Body.Bytes(), &resp)
assert.Equal(t, tc.wantCount, len(resp.Data.Result))
if len(resp.Data.Result) != tc.wantCount {
t.Errorf("got %v, want %v", len(resp.Data.Result), tc.wantCount)
}
})
}
}
@@ -200,13 +212,17 @@ func TestRead(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
body, err := json.Marshal(tc.request)
require.NoError(t, err)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
req := httptest.NewRequest(tc.method, "/api/v1/read", bytes.NewReader(body))
rec := httptest.NewRecorder()
h.read(rec, req)
assert.Equal(t, tc.wantStatus, rec.Code)
if rec.Code != tc.wantStatus {
t.Errorf("got %v, want %v", rec.Code, tc.wantStatus)
}
// Always decode — error responses produce zero-valued struct.
var resp ReadResponse
@@ -215,7 +231,9 @@ func TestRead(t *testing.T) {
if len(resp.Results) > 0 {
firstResultLen = len(resp.Results[0].Timeseries)
}
assert.Equal(t, tc.wantSeries, firstResultLen)
if firstResultLen != tc.wantSeries {
t.Errorf("got %v, want %v", firstResultLen, tc.wantSeries)
}
})
}
}
@@ -267,13 +285,19 @@ func TestStatus(t *testing.T) {
rec := httptest.NewRecorder()
h.status(rec, req)
assert.Equal(t, tc.wantStatus, rec.Code)
if rec.Code != tc.wantStatus {
t.Errorf("got %v, want %v", rec.Code, tc.wantStatus)
}
// Always decode — error responses produce zero-valued struct.
var resp statusResponse
json.Unmarshal(rec.Body.Bytes(), &resp)
assert.Equal(t, tc.wantHeadSeries, resp.HeadSeries)
assert.Equal(t, tc.wantBlocks, resp.Blocks)
if resp.HeadSeries != tc.wantHeadSeries {
t.Errorf("got %v, want %v", resp.HeadSeries, tc.wantHeadSeries)
}
if resp.Blocks != tc.wantBlocks {
t.Errorf("got %v, want %v", resp.Blocks, tc.wantBlocks)
}
})
}
}