75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package services
|
|
|
|
import (
|
|
"testing"
|
|
|
|
m "platform/web/models"
|
|
)
|
|
|
|
func TestExpandGostEdgesRejectsEmpty(t *testing.T) {
|
|
_, err := expandGostEdges(nil, 1)
|
|
if err == nil {
|
|
t.Fatal("expected error, got nil")
|
|
}
|
|
}
|
|
|
|
func TestExpandGostEdgesReusesWhenInsufficient(t *testing.T) {
|
|
edges := []*m.Edge{
|
|
{Mac: "chain-a"},
|
|
{Mac: "chain-b"},
|
|
}
|
|
|
|
result, err := expandGostEdges(edges, 5)
|
|
if err != nil {
|
|
t.Fatalf("expandGostEdges returned error: %v", err)
|
|
}
|
|
if len(result) != 5 {
|
|
t.Fatalf("unexpected edge count: %d", len(result))
|
|
}
|
|
|
|
expected := []string{"chain-a", "chain-b", "chain-a", "chain-b", "chain-a"}
|
|
for i, edge := range result {
|
|
if edge.Mac != expected[i] {
|
|
t.Fatalf("unexpected edge at %d: %s", i, edge.Mac)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEdgeFilterIsEmpty(t *testing.T) {
|
|
if !(*EdgeFilter)(nil).IsEmpty() {
|
|
t.Fatal("nil filter should be empty")
|
|
}
|
|
if (&EdgeFilter{}).IsEmpty() != true {
|
|
t.Fatal("empty filter should be empty")
|
|
}
|
|
if (&EdgeFilter{Prov: strPtr("")}).IsEmpty() != true {
|
|
t.Fatal("filter with empty province should be empty")
|
|
}
|
|
if (&EdgeFilter{City: strPtr("")}).IsEmpty() != true {
|
|
t.Fatal("filter with empty city should be empty")
|
|
}
|
|
if (&EdgeFilter{Isp: ispPtr(m.ToEdgeISP(0))}).IsEmpty() != true {
|
|
t.Fatal("filter with zero ISP should be empty")
|
|
}
|
|
if (&EdgeFilter{Isp: ispPtr(m.ToEdgeISP(99))}).IsEmpty() != true {
|
|
t.Fatal("filter with invalid ISP should be empty")
|
|
}
|
|
|
|
prov := "江苏"
|
|
if (&EdgeFilter{Prov: &prov}).IsEmpty() {
|
|
t.Fatal("filter with province should not be empty")
|
|
}
|
|
isp := m.EdgeISPTelecom
|
|
if (&EdgeFilter{Isp: &isp}).IsEmpty() {
|
|
t.Fatal("filter with valid ISP should not be empty")
|
|
}
|
|
}
|
|
|
|
func strPtr(v string) *string {
|
|
return &v
|
|
}
|
|
|
|
func ispPtr(v m.EdgeISP) *m.EdgeISP {
|
|
return &v
|
|
}
|