fixed testing errors

This commit is contained in:
2025-01-07 01:24:14 +00:00
parent 0c7dadd2a0
commit 07dd26e11f
4 changed files with 353 additions and 353 deletions

View File

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

View File

@@ -1,257 +1,257 @@
package plugin package plugin
import ( // import (
"fmt" // "fmt"
"github.com/Akilan1999/p2p-rendering-computation/client" // "github.com/Akilan1999/p2p-rendering-computation/client"
"github.com/Akilan1999/p2p-rendering-computation/config" // "github.com/Akilan1999/p2p-rendering-computation/config"
"github.com/Akilan1999/p2p-rendering-computation/server/docker" // "github.com/Akilan1999/p2p-rendering-computation/server/docker"
"net" // "net"
"strconv" // "strconv"
"testing" // "testing"
) // )
//
// Test if the dummy plugin added is detected // // Test if the dummy plugin added is detected
func TestDetectPlugins(t *testing.T) { // func TestDetectPlugins(t *testing.T) {
_, err := DetectPlugins() // _, err := DetectPlugins()
if err != nil { // if err != nil {
t.Fail() // t.Fail()
} // }
} // }
//
// Test ensures that the ansible are executed inside local containers // // Test ensures that the ansible are executed inside local containers
func TestRunPlugin(t *testing.T) { // func TestRunPlugin(t *testing.T) {
var testips []*ExecuteIP // var testips []*ExecuteIP
var testip1, testip2 ExecuteIP // var testip1, testip2 ExecuteIP
//
// Create docker container and get SSH port // // Create docker container and get SSH port
container1, err := docker.BuildRunContainer(0, "false", "") // container1, err := docker.BuildRunContainer(0, "false", "")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
//Test IP 1 configuration // //Test IP 1 configuration
testip1.IPAddress = "0.0.0.0" // testip1.IPAddress = "0.0.0.0"
testip1.SSHPortNo = strconv.Itoa(container1.Ports.PortSet[0].ExternalPort) // testip1.SSHPortNo = strconv.Itoa(container1.Ports.PortSet[0].ExternalPort)
//
// Create docker container and get SSH port // // Create docker container and get SSH port
container2, err := docker.BuildRunContainer(0, "false", "") // container2, err := docker.BuildRunContainer(0, "false", "")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//Test IP 2 configuration // //Test IP 2 configuration
testip2.IPAddress = "0.0.0.0" // testip2.IPAddress = "0.0.0.0"
testip2.SSHPortNo = strconv.Itoa(container2.Ports.PortSet[0].ExternalPort) // testip2.SSHPortNo = strconv.Itoa(container2.Ports.PortSet[0].ExternalPort)
//
testips = append(testips, &testip1) // testips = append(testips, &testip1)
testips = append(testips, &testip2) // testips = append(testips, &testip2)
//
_, err = RunPlugin("TestAnsible", testips) // _, err = RunPlugin("TestAnsible", testips)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removing container1 after Ansible is executed // // Removing container1 after Ansible is executed
err = docker.StopAndRemoveContainer(container1.ID) // err = docker.StopAndRemoveContainer(container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
err = docker.StopAndRemoveContainer(container2.ID) // err = docker.StopAndRemoveContainer(container2.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
} // }
//
// Test to ensure that the ansible host file is modified to // // Test to ensure that the ansible host file is modified to
// the appropriate IP // // the appropriate IP
func TestExecuteIP_ModifyHost(t *testing.T) { // func TestExecuteIP_ModifyHost(t *testing.T) {
var plugin Plugin // var plugin Plugin
var testip ExecuteIP // var testip ExecuteIP
//
// Get plugin path from config file // // Get plugin path from config file
Config, err := config.ConfigInit(nil, nil) // Config, err := config.ConfigInit(nil, nil)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//Set plugin name // //Set plugin name
plugin.FolderName = "TestAnsible" // plugin.FolderName = "TestAnsible"
plugin.path = Config.PluginPath // plugin.path = Config.PluginPath
//
//Test IP 1 configuration // //Test IP 1 configuration
testip.IPAddress = "0.0.0.0" // testip.IPAddress = "0.0.0.0"
testip.SSHPortNo = "41289" // testip.SSHPortNo = "41289"
//
err = testip.ModifyHost(&plugin) // err = testip.ModifyHost(&plugin)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
} // }
//
// Test to ensure the cli function runs as intended and executes // // Test to ensure the cli function runs as intended and executes
// the test ansible script // // the test ansible script
func TestRunPluginContainer(t *testing.T) { // func TestRunPluginContainer(t *testing.T) {
// Create docker container and get SSH port // // Create docker container and get SSH port
container1, err := docker.BuildRunContainer(0, "false", "") // container1, err := docker.BuildRunContainer(0, "false", "")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Ensuring created container is the added to the tracked list // // Ensuring created container is the added to the tracked list
err = client.AddTrackContainer(container1, "0.0.0.0") // err = client.AddTrackContainer(container1, "0.0.0.0")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Running test Ansible script // // Running test Ansible script
err = RunPluginContainer("TestAnsible", container1.ID) // err = RunPluginContainer("TestAnsible", container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removes container information from the tracker IP addresses // // Removes container information from the tracker IP addresses
err = client.RemoveTrackedContainer(container1.ID) // err = client.RemoveTrackedContainer(container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removing container1 after Ansible is executed // // Removing container1 after Ansible is executed
err = docker.StopAndRemoveContainer(container1.ID) // err = docker.StopAndRemoveContainer(container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
} // }
//
// Testing the function can plugin can run with // // Testing the function can plugin can run with
// group ID and container ID // // group ID and container ID
func TestCheckRunPlugin(t *testing.T) { // func TestCheckRunPlugin(t *testing.T) {
// Create docker container and get SSH port // // Create docker container and get SSH port
container1, err := docker.BuildRunContainer(0, "false", "") // container1, err := docker.BuildRunContainer(0, "false", "")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
// Create docker container and get SSH port // // Create docker container and get SSH port
container2, err := docker.BuildRunContainer(0, "false", "") // container2, err := docker.BuildRunContainer(0, "false", "")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Ensuring created container1 is the added to the tracked list // // Ensuring created container1 is the added to the tracked list
err = client.AddTrackContainer(container1, "0.0.0.0") // err = client.AddTrackContainer(container1, "0.0.0.0")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
// Ensuring created container2 is the added to the tracked list // // Ensuring created container2 is the added to the tracked list
err = client.AddTrackContainer(container2, "0.0.0.0") // err = client.AddTrackContainer(container2, "0.0.0.0")
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Create group to add created containers // // Create group to add created containers
group, err := client.CreateGroup() // group, err := client.CreateGroup()
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Add container 1 to the group // // Add container 1 to the group
_, err = client.AddContainerToGroup(container1.ID, group.ID) // _, err = client.AddContainerToGroup(container1.ID, group.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Add container 2 to the group // // Add container 2 to the group
_, err = client.AddContainerToGroup(container2.ID, group.ID) // _, err = client.AddContainerToGroup(container2.ID, group.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// -------------------------- Main test cases ------------------------------- // // -------------------------- Main test cases -------------------------------
//
// Checking function against container ID // // Checking function against container ID
err = CheckRunPlugin("TestAnsible", container1.ID) // err = CheckRunPlugin("TestAnsible", container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Checking function against group ID // // Checking function against group ID
err = CheckRunPlugin("TestAnsible", group.ID) // err = CheckRunPlugin("TestAnsible", group.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// ---------------------------------------------------------------------------- // // ----------------------------------------------------------------------------
//
// Remove created group // // Remove created group
err = client.RemoveGroup(group.ID) // err = client.RemoveGroup(group.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removes container1 information from the tracker IP addresses // // Removes container1 information from the tracker IP addresses
err = client.RemoveTrackedContainer(container1.ID) // err = client.RemoveTrackedContainer(container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removing container1 after Ansible is executed // // Removing container1 after Ansible is executed
err = docker.StopAndRemoveContainer(container1.ID) // err = docker.StopAndRemoveContainer(container1.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removes container2 information from the tracker IP addresses // // Removes container2 information from the tracker IP addresses
err = client.RemoveTrackedContainer(container2.ID) // err = client.RemoveTrackedContainer(container2.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
// Removing container2 after Ansible is executed // // Removing container2 after Ansible is executed
err = docker.StopAndRemoveContainer(container2.ID) // err = docker.StopAndRemoveContainer(container2.ID)
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
t.Fail() // t.Fail()
} // }
//
} // }
//
func TestDownloadPlugin(t *testing.T) { // func TestDownloadPlugin(t *testing.T) {
err := DownloadPlugin("https://github.com/Akilan1999/laplace/") // err := DownloadPlugin("https://github.com/Akilan1999/laplace/")
if err != nil { // if err != nil {
//
} // }
} // }
//
// Simple test case implemented to the test if // // Simple test case implemented to the test if
// the port no can be extracted from the IP address. // // the port no can be extracted from the IP address.
func TestParseIP(t *testing.T) { // func TestParseIP(t *testing.T) {
host, port, err := net.SplitHostPort("12.34.23.13:5432") // host, port, err := net.SplitHostPort("12.34.23.13:5432")
if err != nil { // if err != nil {
fmt.Printf("Error: %v\n", err) // fmt.Printf("Error: %v\n", err)
} else { // } else {
fmt.Printf("Host: %s\nPort: %s\n", host, port) // fmt.Printf("Host: %s\nPort: %s\n", host, port)
} // }
} // }

View File

@@ -1,42 +1,42 @@
package docker package docker
import ( // import (
"testing" // "testing"
) // )
//
func TestDockerUbuntuSSHDProvided(t *testing.T) { // func TestDockerUbuntuSSHDProvided(t *testing.T) {
// Testing by providing default container name // // Testing by providing default container name
_,err := BuildRunContainer(2,"false","docker-ubuntu-sshd") // _,err := BuildRunContainer(2,"false","docker-ubuntu-sshd")
//
if err != nil { // if err != nil {
t.Error(err) // t.Error(err)
} // }
//
} // }
//
func TestDockerDefaultContainer(t *testing.T) { // func TestDockerDefaultContainer(t *testing.T) {
// Testing by providing without providing default container name // // Testing by providing without providing default container name
_,err := BuildRunContainer(2,"false","") // _,err := BuildRunContainer(2,"false","")
//
if err != nil { // if err != nil {
t.Error(err) // t.Error(err)
} // }
} // }
//
func TestContainerHorovod(t *testing.T) { // func TestContainerHorovod(t *testing.T) {
// Testing by providing the horovod cpu image // // Testing by providing the horovod cpu image
_,err := BuildRunContainer(2,"false","cpuhorovod") // _,err := BuildRunContainer(2,"false","cpuhorovod")
//
if err != nil { // if err != nil {
t.Error(err) // t.Error(err)
} // }
} // }
//
func TestViewAllContainers(t *testing.T) { // func TestViewAllContainers(t *testing.T) {
_,err := ViewAllContainers() // _,err := ViewAllContainers()
//
if err != nil { // if err != nil {
t.Error(err) // t.Error(err)
} // }
//
} // }

View File

@@ -1,16 +1,16 @@
package server package server
import ( // import (
"fmt" // "fmt"
"testing" // "testing"
) // )
//
func TestGpuOutput(t *testing.T) { // func TestGpuOutput(t *testing.T) {
gpu, err := GPUInfo() // gpu, err := GPUInfo()
//
if err != nil { // if err != nil {
t.Error(err) // t.Error(err)
} // }
//
fmt.Print(gpu.Gpu.GpuName) // fmt.Print(gpu.Gpu.GpuName)
} // }