Added test for getting IP with udp from prod servers.
This commit is contained in:
parent
159f4b941b
commit
ee5fcaef14
1 changed files with 53 additions and 0 deletions
53
server/udp_test.go
Normal file
53
server/udp_test.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestAddPeer tests the ability to add peers
|
||||
func TestUDPPing(t *testing.T) {
|
||||
args := makeDefaultArgs()
|
||||
args.StartUDP = false
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
} {
|
||||
{
|
||||
name: "Get the right ip from production server.",
|
||||
want: "SETME",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T){
|
||||
|
||||
toAddr := "spv16.lbry.com"
|
||||
toPort := "50001"
|
||||
|
||||
ip, err := UDPPing(toAddr, toPort)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
res, err := exec.Command("dig", "@resolver4.opendns.com", "myip.opendns.com", "+short").Output()
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
digIP := strings.TrimSpace(string(res))
|
||||
udpIP := ip.String()
|
||||
tt.want = digIP
|
||||
|
||||
got1 := udpIP
|
||||
if got1 != tt.want {
|
||||
t.Errorf("got: '%s', want: '%s'\n", got1, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue