platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPublishTransportRuntimeObservabilitySnapshotChanged(t *testing.T) {
|
||||
withTransportPolicyMutationTestPaths(t)
|
||||
|
||||
prevEvents := events
|
||||
events = newEventBus(32)
|
||||
t.Cleanup(func() {
|
||||
events = prevEvents
|
||||
})
|
||||
|
||||
prevEgress := egressIdentitySWR
|
||||
egressIdentitySWR = newEgressIdentityService(1)
|
||||
t.Cleanup(func() {
|
||||
egressIdentitySWR = prevEgress
|
||||
})
|
||||
|
||||
if err := saveTransportClientsState(transportClientsState{
|
||||
Version: transportStateVersion,
|
||||
Items: []TransportClient{
|
||||
{
|
||||
ID: "sb-one",
|
||||
Kind: TransportClientSingBox,
|
||||
Enabled: true,
|
||||
IfaceID: "edge-a",
|
||||
Iface: "tun-edge0",
|
||||
RoutingTable: "agvpn_if_edge_a",
|
||||
Status: TransportClientUp,
|
||||
Health: TransportClientHealth{
|
||||
LastCheck: "2026-03-16T12:11:00Z",
|
||||
LatencyMS: 44,
|
||||
},
|
||||
},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("save clients state: %v", err)
|
||||
}
|
||||
if err := saveTransportInterfacesState(transportInterfacesState{
|
||||
Version: transportStateVersion,
|
||||
Items: []TransportInterface{
|
||||
{
|
||||
ID: "edge-a",
|
||||
Name: "Edge A",
|
||||
Mode: TransportInterfaceModeDedicated,
|
||||
RuntimeIface: "tun-edge",
|
||||
},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("save interfaces state: %v", err)
|
||||
}
|
||||
if err := saveTransportPolicyState(TransportPolicyState{
|
||||
Version: transportStateVersion,
|
||||
Revision: 3,
|
||||
Intents: []TransportPolicyIntent{
|
||||
{SelectorType: "domain", SelectorValue: "example.org", ClientID: "sb-one"},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("save policy state: %v", err)
|
||||
}
|
||||
if err := saveTransportPolicyCompilePlan(TransportPolicyCompilePlan{
|
||||
PolicyRevision: 3,
|
||||
InterfaceCount: 1,
|
||||
RuleCount: 1,
|
||||
Interfaces: []TransportPolicyCompileInterface{
|
||||
{IfaceID: "edge-a", RuleCount: 1, ClientIDs: []string{"sb-one"}},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("save policy plan: %v", err)
|
||||
}
|
||||
|
||||
egressIdentitySWR.mu.Lock()
|
||||
egressIdentitySWR.entries["transport:sb-one"] = &egressIdentityEntry{
|
||||
item: EgressIdentity{
|
||||
Scope: "transport:sb-one",
|
||||
Source: "transport",
|
||||
SourceID: "sb-one",
|
||||
IP: "198.51.100.77",
|
||||
CountryCode: "FR",
|
||||
},
|
||||
}
|
||||
egressIdentitySWR.mu.Unlock()
|
||||
|
||||
publishTransportRuntimeObservabilitySnapshotChanged(
|
||||
"transport_client_state_changed",
|
||||
[]string{"sb-one"},
|
||||
nil,
|
||||
)
|
||||
|
||||
evs := events.since(0)
|
||||
if len(evs) != 1 {
|
||||
t.Fatalf("expected one event, got %d", len(evs))
|
||||
}
|
||||
if evs[0].Kind != "transport_runtime_snapshot_changed" {
|
||||
t.Fatalf("unexpected event kind: %#v", evs[0])
|
||||
}
|
||||
payload, ok := evs[0].Data.(TransportRuntimeObservabilityChangedEvent)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected event payload type: %T", evs[0].Data)
|
||||
}
|
||||
if payload.Reason != "transport_client_state_changed" {
|
||||
t.Fatalf("unexpected event reason: %#v", payload)
|
||||
}
|
||||
if len(payload.ClientIDs) != 1 || payload.ClientIDs[0] != "sb-one" {
|
||||
t.Fatalf("unexpected client ids: %#v", payload)
|
||||
}
|
||||
if len(payload.IfaceIDs) != 1 || payload.IfaceIDs[0] != "edge-a" {
|
||||
t.Fatalf("unexpected iface ids: %#v", payload)
|
||||
}
|
||||
if payload.Count != len(payload.Items) || payload.Count < 2 {
|
||||
t.Fatalf("unexpected snapshot payload: %#v", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveTransportRuntimeObservabilityEventIfaceIDsUsesExplicitFallback(t *testing.T) {
|
||||
items := []TransportRuntimeObservabilityItem{
|
||||
{
|
||||
IfaceID: "edge-a",
|
||||
ClientID: "sb-one",
|
||||
ClientIDs: []string{"sb-one", "dnstt-one"},
|
||||
},
|
||||
}
|
||||
ifaceIDs := resolveTransportRuntimeObservabilityEventIfaceIDs(
|
||||
items,
|
||||
[]string{"deleted-client"},
|
||||
[]string{"edge-z", "edge-a"},
|
||||
)
|
||||
if len(ifaceIDs) != 2 || ifaceIDs[0] != "edge-z" || ifaceIDs[1] != "edge-a" {
|
||||
t.Fatalf("unexpected iface ids: %#v", ifaceIDs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user