mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-09-12 06:55:34 +00:00
test(db): add extractFromNode
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/MeshCore-Beacon/beacon-server/internal/api"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestExtractFromNode_Found(t *testing.T) {
|
||||
a, b, c := uuid.New(), uuid.New(), uuid.New()
|
||||
hops := []api.RouteHop{
|
||||
{NodeID: a},
|
||||
{NodeID: b},
|
||||
{NodeID: c},
|
||||
}
|
||||
result := extractFromNode(hops, b)
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("expected 2 hops, got %d", len(result))
|
||||
}
|
||||
if result[0].NodeID != b {
|
||||
t.Errorf("expected first hop to be b, got %s", result[0].NodeID)
|
||||
}
|
||||
if result[1].NodeID != c {
|
||||
t.Errorf("expected second hop to be c, got %s", result[1].NodeID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractFromNode_FirstNode(t *testing.T) {
|
||||
a, b := uuid.New(), uuid.New()
|
||||
hops := []api.RouteHop{{NodeID: a}, {NodeID: b}}
|
||||
result := extractFromNode(hops, a)
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("expected 2 hops, got %d", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractFromNode_NotFound(t *testing.T) {
|
||||
a, b := uuid.New(), uuid.New()
|
||||
hops := []api.RouteHop{{NodeID: a}}
|
||||
result := extractFromNode(hops, b)
|
||||
// not found returns full slice
|
||||
if len(result) != 1 {
|
||||
t.Fatalf("expected full slice returned, got %d hops", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractFromNode_Empty(t *testing.T) {
|
||||
result := extractFromNode(nil, uuid.New())
|
||||
if len(result) != 0 {
|
||||
t.Errorf("expected empty result for nil hops")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user