mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
package printer
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/xgadget-lab/nexttrace/ipgeo"
|
|
"github.com/xgadget-lab/nexttrace/trace"
|
|
"github.com/xgadget-lab/nexttrace/util"
|
|
)
|
|
|
|
func TestPrintTraceRouteNav(t *testing.T) {
|
|
PrintTraceRouteNav(util.DomainLookUp("1.1.1.1", false), "1.1.1.1", "dataOrigin")
|
|
}
|
|
|
|
var testGeo = &ipgeo.IPGeoData{
|
|
Asnumber: "TestAsnumber",
|
|
Country: "TestCountry",
|
|
Prov: "TestProv",
|
|
City: "TestCity",
|
|
District: "TestDistrict",
|
|
Owner: "TestOwner",
|
|
Isp: "TestIsp",
|
|
}
|
|
|
|
var testResult = &trace.Result{
|
|
Hops: [][]trace.Hop{
|
|
{
|
|
{
|
|
Success: true,
|
|
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
|
Hostname: "test",
|
|
TTL: 0,
|
|
RTT: 10 * time.Millisecond,
|
|
Error: nil,
|
|
Geo: testGeo,
|
|
},
|
|
{
|
|
Success: true,
|
|
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
|
Hostname: "test",
|
|
TTL: 0,
|
|
RTT: 10 * time.Millisecond,
|
|
Error: nil,
|
|
Geo: testGeo,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
Success: false,
|
|
Address: nil,
|
|
Hostname: "",
|
|
TTL: 0,
|
|
RTT: 0,
|
|
Error: errors.New("test error"),
|
|
Geo: nil,
|
|
},
|
|
{
|
|
Success: true,
|
|
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
|
Hostname: "test",
|
|
TTL: 0,
|
|
RTT: 10 * time.Millisecond,
|
|
Error: nil,
|
|
Geo: nil,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
Success: true,
|
|
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
|
Hostname: "test",
|
|
TTL: 0,
|
|
RTT: 0,
|
|
Error: nil,
|
|
Geo: &ipgeo.IPGeoData{},
|
|
},
|
|
{
|
|
Success: true,
|
|
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
|
Hostname: "",
|
|
TTL: 0,
|
|
RTT: 10 * time.Millisecond,
|
|
Error: nil,
|
|
Geo: testGeo,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
// func TestTraceroutePrinter(t *testing.T) {
|
|
// TraceroutePrinter(testResult)
|
|
// }
|
|
|
|
func TestTracerouteTablePrinter(t *testing.T) {
|
|
TracerouteTablePrinter(testResult)
|
|
}
|
|
|
|
func TestRealtimePrinter(t *testing.T) {
|
|
RealtimePrinter(testResult, 0)
|
|
// RealtimePrinter(testResult, 1)
|
|
// RealtimePrinter(testResult, 2)
|
|
}
|