test: gate go-libraries integration tests behind -tags=integration
Assisted-by: GLM 5.2
This commit is contained in:
@@ -50,3 +50,118 @@ func TestArrayLen(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestElemSizeFor(t *testing.T) {
|
||||
tests := []struct {
|
||||
typ string
|
||||
want int
|
||||
}{
|
||||
{"[]byte", 1}, {"[]uint8", 1}, {"[]int8", 1},
|
||||
{"[]uint16", 2}, {"[]int16", 2},
|
||||
{"[]uint32", 4}, {"[]int32", 4}, {"[]float32", 4},
|
||||
{"[]uint64", 8}, {"[]int64", 8}, {"[]float64", 8},
|
||||
{"[]unknown", 8},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := elemSizeFor(tt.typ); got != tt.want {
|
||||
t.Errorf("elemSizeFor(%q) = %d, want %d", tt.typ, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualBytes(t *testing.T) {
|
||||
if !equalBytes([]byte{1, 2, 3}, []byte{1, 2, 3}) {
|
||||
t.Error("expected equal")
|
||||
}
|
||||
if equalBytes([]byte{1, 2}, []byte{1, 2, 3}) {
|
||||
t.Error("different length: expected not equal")
|
||||
}
|
||||
if equalBytes([]byte{1, 2, 3}, []byte{1, 2, 4}) {
|
||||
t.Error("different content: expected not equal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParamsSize(t *testing.T) {
|
||||
sig := funcSig{
|
||||
name: "test",
|
||||
params: []param{{name: "a", typ: "[]byte"}, {name: "b", typ: "int"}},
|
||||
results: []param{{name: "n", typ: "int"}},
|
||||
}
|
||||
if got := paramsSize(sig); got != 32 {
|
||||
t.Errorf("paramsSize = %d, want 32 (24 for slice + 8 for int)", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockCount(t *testing.T) {
|
||||
k := loadBasic(t)
|
||||
n, err := k.BlockCount("sum")
|
||||
if err != nil {
|
||||
t.Fatalf("BlockCount(sum): %v", err)
|
||||
}
|
||||
if n < 2 {
|
||||
t.Errorf("sum: expected at least 2 blocks, got %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFillBuffer(t *testing.T) {
|
||||
t.Run("zero", func(t *testing.T) {
|
||||
// fillBuffer("zero") is a no-op — relies on make already zeroing.
|
||||
buf := make([]byte, 16)
|
||||
fillBuffer(buf, "zero")
|
||||
for _, b := range buf {
|
||||
if b != 0 {
|
||||
t.Error("zero pattern: make should produce zeroed buffer")
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("ones", func(t *testing.T) {
|
||||
buf := make([]byte, 16)
|
||||
fillBuffer(buf, "ones")
|
||||
for _, b := range buf {
|
||||
if b != 0xFF {
|
||||
t.Error("ones pattern should fill with 0xFF")
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("seq", func(t *testing.T) {
|
||||
buf := make([]byte, 256)
|
||||
fillBuffer(buf, "seq")
|
||||
for i, b := range buf {
|
||||
if b != byte(i) {
|
||||
t.Errorf("seq[%d] = %d, want %d", i, b, i)
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("hex", func(t *testing.T) {
|
||||
buf := make([]byte, 6)
|
||||
fillBuffer(buf, "deadbeef")
|
||||
want := []byte{0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD}
|
||||
for i, b := range buf {
|
||||
if b != want[i] {
|
||||
t.Errorf("hex[%d] = %02x, want %02x", i, b, want[i])
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFuzzFuncChecked(t *testing.T) {
|
||||
k := loadBasic(t)
|
||||
sig := funcSig{
|
||||
name: "sum",
|
||||
params: []param{{name: "data", typ: "[]int64"}},
|
||||
results: []param{{name: "r", typ: "int64"}},
|
||||
}
|
||||
result := k.FuzzFuncChecked("sum", sig, 10, 0)
|
||||
if !result.OK() {
|
||||
t.Errorf("FuzzFuncChecked(sum): %s", result)
|
||||
}
|
||||
// Test with non-existent function — should report failure.
|
||||
result = k.FuzzFuncChecked("nope", sig, 10, 0)
|
||||
if result.OK() {
|
||||
t.Error("FuzzFuncChecked(nope): expected failure")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user