Page MenuHomePhabricator

app_test.go
No OneTemporary

app_test.go

package sshtunnel
import (
"testing"
"fmt"
)
//function
func TestEndPointString(t *testing.T) {
var testend Endpoint
testend.Host = "localhost"
testend.Port = 5555
// make a string and test what the string should be
stringWant := "localhost:5555"
returnedString := testend.String()
fmt.Printf("\nstringWant: %s\n\n", stringWant)
fmt.Printf("returnedString : %s\n\n", returnedString)
// return string == stringwant // success
}
//function
func TestEndPointParseString(t *testing.T) {
var testRemote, testRemote1 Endpoint
var testLocal, testLocal1 Endpoint
// make a string and test what the string should be
testLocal, testRemote = ParseEndpointString("5555:motherbrain.unr.edu:5555")
testLocal1, testRemote1 = ParseEndpointString("27013:motherbrain.unr.edu:27013")
fmt.Printf("Local: %s %d\n\n", testLocal.Host, testLocal.Port)
fmt.Printf("Remote: %s %d \n\n", testRemote.Host, testRemote.Port)
fmt.Printf("Local: %s %d\n\n", testLocal1.Host, testLocal1.Port)
fmt.Printf("Remote: %s %d \n\n", testRemote1.Host, testRemote1.Port)
if testLocal.Host != "localhost"{
t.Error("Invalid Local EP Hostname")
}
if testLocal.Port != 5555 {
t.Error("Invalid Local EP Port")
}
if testRemote.Host != "motherbrain.unr.edu"{
t.Error("Invalid remote EP Hostname")
}
if testRemote.Port != 5555 {
t.Error("Invalid remote EP Port")
}
////////////////////////////////////////
if testLocal1.Host != "localhost"{
t.Error("Invalid Local EP Hostname")
}
if testLocal1.Port != 27013 {
t.Error("Invalid Local EP Port")
}
if testRemote1.Host != "motherbrain.unr.edu"{
t.Error("Invalid remote EP Hostname")
}
if testRemote1.Port != 27013 {
t.Error("Invalid remote EP Port")
}
// return string == stringwant // success
}
func TestEndPointsArray(t *testing.T) {
//Input
testInput := []string{
"5555:motherbrain.unr.edu:5555",
"27013:motherbrain.unr.edu:27013",
}
fmt.Printf("Input %v \n\n", testInput)
//Anticipated output
testLocalEndpoints := [2]Endpoint{
{Host: "localhost", Port: 5555},
{Host: "localhost", Port: 27013},
};
testRemoteEndpoints := [2]Endpoint{
{Host: "motherbrain.unr.edu", Port: 5555},
{Host: "motherbrain.unr.edu", Port: 27013},
};
for r,_ := range(testLocalEndpoints){
fmt.Printf("Test Local: %v\n\n", testLocalEndpoints[r])
fmt.Printf("Test Remote: %v\n\n", testRemoteEndpoints[r])
}
// try to match the testInput with the anticipated output by passing the test,
// append the input to array
myLocalEndpoints, myRemoteEndpoints := ParseEndpointsFromArray(testInput);
//Real output
for r,_ := range(myLocalEndpoints){
fmt.Printf("Local: %v\n\n", myLocalEndpoints[r])
fmt.Printf("Remote: %v\n\n", myRemoteEndpoints[r])
}
}

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 24, 11:34 PM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15042
Default Alt Text
app_test.go (2 KB)

Event Timeline