32 lines
2.9 KiB
TypeScript
32 lines
2.9 KiB
TypeScript
import {test} from "node:test"
|
|
import assert from "node:assert/strict"
|
|
import {validateNetworkMapSnapshot} from "./network-map-response"
|
|
const server={id:1,name:"Router",host:"192.0.2.1",type:"home-router",country:"RU",enabled:true,status:null,latency:0}
|
|
test("network map requires complete envelopes and preserves zero/null",()=>{
|
|
const result=validateNetworkMapSnapshot([server],{tunnels:[],failures:[]},{probes:[]})
|
|
assert.equal(result.servers[0].latency,0);assert.equal(result.servers[0].status,null)
|
|
for(const args of [[null,{tunnels:[]},{probes:[]}],[[server],{}, {probes:[]}],[[server],{tunnels:[]},{}],[[server,server],{tunnels:[]},{probes:[]}],[[{...server,freeMemory:20,totalMemory:10}],{tunnels:[]},{probes:[]}],[[{...server,status:undefined}],{tunnels:[]},{probes:[]}]])assert.throws(()=>validateNetworkMapSnapshot(...args as [unknown,unknown,unknown]))
|
|
})
|
|
test("network map refuses partial GRE and foreign failure/probe contexts",()=>{
|
|
assert.throws(()=>validateNetworkMapSnapshot([server],{tunnels:[],failures:[{serverId:"1",error:"offline"}]},{probes:[]}),/Неполный/)
|
|
assert.throws(()=>validateNetworkMapSnapshot([server],{tunnels:[],failures:[{serverId:"2",error:"offline"}]},{probes:[]}),/неизвестному/)
|
|
const probe={id:"p",srcServerId:"1",dstServerId:"2",srcInterface:"",dstInterface:"",enabled:true,lastTxAvgMbps:null,lastRxAvgMbps:null,lastPingRttMs:null,lastPingLossPct:null,lastPingAt:null}
|
|
assert.throws(()=>validateNetworkMapSnapshot([server],{tunnels:[]},{probes:[probe]}),/неизвестному/)
|
|
})
|
|
|
|
import {networkMapFlowSchema,validateNetworkMapDns} from "./network-map-response"
|
|
test("map Flow envelope retains zeros and refuses missing metadata and contradictory totals",()=>{
|
|
const empty={"hops":[],"live":false,"rangeMinutes":5,"windowSec":300,"totalBytes":0,"namedBytes":0,"unclassifiedBytes":0,"asnLoaded":false,"countryLoaded":false,"services":[],"serviceEdges":[],"servicePaths":[],"countries":[],"countryEdges":[],"countryPaths":[],"countryServiceGroups":[],"mapServiceMinSharePct":5,"dedupApplied":false,"excludeMeshApplied":false,"excludeOverlayApplied":false}
|
|
assert.equal(networkMapFlowSchema.parse(empty).totalBytes,0)
|
|
assert.equal(networkMapFlowSchema.parse(empty).live,false)
|
|
assert.throws(()=>networkMapFlowSchema.parse({...empty,totalBytes:undefined}))
|
|
assert.throws(()=>networkMapFlowSchema.parse({...empty,namedBytes:1}))
|
|
assert.throws(()=>networkMapFlowSchema.parse({...empty,rangeMinutes:10}))
|
|
})
|
|
test("map DNS matches exactly requested names and accepts explicit unresolved null",()=>{
|
|
assert.deepEqual(validateNetworkMapDns({results:{"router.example":null}},["router.example"]),{"router.example":null})
|
|
assert.throws(()=>validateNetworkMapDns({results:{}},["router.example"]))
|
|
assert.throws(()=>validateNetworkMapDns({results:{"foreign.example":"192.0.2.1"}},["router.example"]))
|
|
assert.throws(()=>validateNetworkMapDns({results:{"router.example":"not-ip"}},["router.example"]))
|
|
})
|