uncommenting testing code

This commit is contained in:
2025-01-07 20:19:47 +00:00
parent 07dd26e11f
commit ea8e7d4073
10 changed files with 645 additions and 644 deletions

View File

@@ -1,46 +1,46 @@
package frp
// import (
// "fmt"
// "testing"
// "time"
// )
//
// // Testing scenario FRPServer
// func TestStartFRPServer(t *testing.T) {
// var s Server
// s.address = "127.0.0.1"
// s.port = 8808
// err := s.StartFRPServer()
// if err != nil {
// fmt.Println(err)
// t.Fail()
// }
// }
//
// // Testing scenario FRPServer and FRPClient connection
// func TestStartFRPClient(t *testing.T) {
// var s Server
// s.address = "127.0.0.1"
// s.port = 8808
// go s.StartFRPServer()
//
// time.Sleep(3 * time.Second)
//
// // Sample test client
// var c Client
// c.Server = &s
// c.ClientMappings = []ClientMapping{
// {
// LocalIP: "127.0.0.1",
// LocalPort: 22,
// RemotePort: 3301,
// },
// }
//
// err := c.StartFRPClient()
// if err != nil {
// fmt.Println(err)
// t.Fail()
// }
// }
import (
"fmt"
"testing"
"time"
)
// Testing scenario FRPServer
func TestStartFRPServer(t *testing.T) {
var s Server
s.address = "127.0.0.1"
s.port = 8808
err := s.StartFRPServer()
if err != nil {
fmt.Println(err)
t.Fail()
}
}
// Testing scenario FRPServer and FRPClient connection
func TestStartFRPClient(t *testing.T) {
var s Server
s.address = "127.0.0.1"
s.port = 8808
go s.StartFRPServer()
time.Sleep(3 * time.Second)
// Sample test client
var c Client
c.Server = &s
c.ClientMappings = []ClientMapping{
{
LocalIP: "127.0.0.1",
LocalPort: 22,
RemotePort: 3301,
},
}
err := c.StartFRPClient()
if err != nil {
fmt.Println(err)
t.Fail()
}
}

View File

@@ -1,76 +1,77 @@
package p2p
// import (
// "fmt"
// "testing"
// )
//
// func TestReadIpTable(t *testing.T) {
// json, err := ReadIpTable()
// if err != nil {
// t.Fatal(err)
// }
//
// err = json.WriteIpTable()
// if err != nil {
// t.Fatal(err)
// }
//
// err = PrintIpTable()
// if err != nil {
// t.Fatal(err)
// }
// }
//
// // Testing is a IPV6 address is returned
// func TestGetCurrentIPV6(t *testing.T) {
// res, err := GetCurrentIPV6()
//
// if err != nil {
// t.Error(err)
// }
//
// fmt.Println(res)
// }
//
// // This test ensures that the duplicate function works as intended
// func TestIpAddresses_RemoveDuplicates(t *testing.T) {
// var testduplicates IpAddresses
// var duplicateaddress1 IpAddress
// var duplicateaddress2 IpAddress
//
// duplicateaddress1.Ipv6="2001:8f8:172d:ee93:7588:ad57:c351:3309"
// duplicateaddress1.Ipv4="0.0.0.0"
//
// duplicateaddress2.Ipv6="2001:8f8:172d:ee93:7588:ad57:c351:3309"
// duplicateaddress2.Ipv4="0.0.0.0"
//
// testduplicates.IpAddress = append(testduplicates.IpAddress, duplicateaddress1)
// testduplicates.IpAddress = append(testduplicates.IpAddress, duplicateaddress2)
//
// err := testduplicates.RemoveDuplicates()
// if err != nil {
// t.Error(err)
// }
//
// if len(testduplicates.IpAddress) == 2 {
// t.Fail()
// }
//
// }
//
// func TestViewNetworkInterface(t *testing.T) {
// err := ViewNetworkInterface()
// if err != nil {
// t.Error()
// }
// }
//
// func TestIp4or6(t *testing.T) {
// // This test ensures that the ipv6 address gets detected
// test := "2001:8f8:172d:7e27:4f23:ae4:bce5:e037"
// res := Ip4or6(test)
// if res != "version 6" {
// t.Fail()
// }
//
// }
import (
"fmt"
"testing"
)
func TestReadIpTable(t *testing.T) {
json, err := ReadIpTable()
if err != nil {
t.Fatal(err)
}
err = json.WriteIpTable()
if err != nil {
t.Fatal(err)
}
err = PrintIpTable()
if err != nil {
t.Fatal(err)
}
}
// Testing is a IPV6 address is returned
func TestGetCurrentIPV6(t *testing.T) {
res, err := GetCurrentIPV6()
if err != nil {
t.Error(err)
}
fmt.Println(res)
}
// This test ensures that the duplicate function works as intended
func TestIpAddresses_RemoveDuplicates(t *testing.T) {
var testduplicates IpAddresses
var duplicateaddress1 IpAddress
var duplicateaddress2 IpAddress
duplicateaddress1.Ipv6="2001:8f8:172d:ee93:7588:ad57:c351:3309"
duplicateaddress1.Ipv4="0.0.0.0"
duplicateaddress2.Ipv6="2001:8f8:172d:ee93:7588:ad57:c351:3309"
duplicateaddress2.Ipv4="0.0.0.0"
testduplicates.IpAddress = append(testduplicates.IpAddress, duplicateaddress1)
testduplicates.IpAddress = append(testduplicates.IpAddress, duplicateaddress2)
err := testduplicates.RemoveDuplicates()
if err != nil {
t.Error(err)
}
if len(testduplicates.IpAddress) == 2 {
t.Fail()
}
}
func TestViewNetworkInterface(t *testing.T) {
err := ViewNetworkInterface()
if err != nil {
t.Error()
}
}
func TestIp4or6(t *testing.T) {
// This test ensures that the ipv6 address gets detected
test := "2001:8f8:172d:7e27:4f23:ae4:bce5:e037"
res := Ip4or6(test)
if res != "version 6" {
t.Fail()
}
}

View File

@@ -1,16 +1,16 @@
package p2p
// import (
// "testing"
// )
//
// // To run this test ip_table.json must be populated
// func TestServer_SpeedTest(t *testing.T) {
// err := LocalSpeedTestIpTable()
// if err != nil {
// t.Fatal(err)
// }
//
// //HumaidTest("http://localhost:8088/50")
// //HumaidTest("http://ipv4.download.thinkbroadband.com/50MB.zip")
// }
import (
"testing"
)
// To run this test ip_table.json must be populated
func TestServer_SpeedTest(t *testing.T) {
err := LocalSpeedTestIpTable()
if err != nil {
t.Fatal(err)
}
//HumaidTest("http://localhost:8088/50")
//HumaidTest("http://ipv4.download.thinkbroadband.com/50MB.zip")
}

View File

@@ -1,15 +1,15 @@
package p2p
// import (
// "fmt"
// "testing"
// )
//
// // Tests if the current has UPNP support
// func TestForwardUPNPPort(t *testing.T) {
// err := ForwardPort(6586)
// if err != nil {
// fmt.Println(err)
// t.Fail()
// }
// }
import (
"fmt"
"testing"
)
// Tests if the current has UPNP support
func TestForwardUPNPPort(t *testing.T) {
err := ForwardPort(6586)
if err != nil {
fmt.Println(err)
t.Fail()
}
}