tka: created a shared testing library for Chonk

This patch creates a set of tests that should be true for all implementations of Chonk and CompactableChonk, which we can share with the SQLite implementation in corp.

It includes all the existing tests, plus a test for LastActiveAncestor which was in corp but not in oss.

Updates https://github.com/tailscale/corp/issues/33465

Signed-off-by: Alex Chan <alexc@tailscale.com>
This commit is contained in:
Alex Chan
2025-10-17 15:06:55 +01:00
committed by Alex Chan
parent c961d58091
commit 4673992b96
3 changed files with 322 additions and 200 deletions
+53
View File
@@ -0,0 +1,53 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package chonktest
import (
"testing"
"tailscale.com/tka"
"tailscale.com/util/must"
)
func TestImplementsChonk(t *testing.T) {
for _, tt := range []struct {
name string
newChonk func(t *testing.T) tka.Chonk
}{
{
name: "Mem",
newChonk: func(t *testing.T) tka.Chonk {
return &tka.Mem{}
},
},
{
name: "FS",
newChonk: func(t *testing.T) tka.Chonk {
return must.Get(tka.ChonkDir(t.TempDir()))
},
},
} {
t.Run(tt.name, func(t *testing.T) {
RunChonkTests(t, tt.newChonk)
})
}
}
func TestImplementsCompactableChonk(t *testing.T) {
for _, tt := range []struct {
name string
newChonk func(t *testing.T) tka.CompactableChonk
}{
{
name: "FS",
newChonk: func(t *testing.T) tka.CompactableChonk {
return must.Get(tka.ChonkDir(t.TempDir()))
},
},
} {
t.Run(tt.name, func(t *testing.T) {
RunCompactableChonkTests(t, tt.newChonk)
})
}
}