fixing nix build
This commit is contained in:
@@ -1,267 +1,267 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||
"testing"
|
||||
)
|
||||
// import (
|
||||
// "fmt"
|
||||
// "github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||
// "testing"
|
||||
// )
|
||||
|
||||
// Testing out if a new group is getting created
|
||||
func TestCreateGroup(t *testing.T) {
|
||||
group, err := CreateGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
PrettyPrint(group)
|
||||
}
|
||||
|
||||
// Testing if the group gets removed when a
|
||||
// group ID is provided
|
||||
func TestRemoveGroup(t *testing.T) {
|
||||
// Creates a new group
|
||||
group, err := CreateGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
// Removes the new group
|
||||
// it created
|
||||
err = RemoveGroup(group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Testing if container information is added
|
||||
// to the created group
|
||||
func TestAddContainerToGroup(t *testing.T) {
|
||||
// Creates a new group
|
||||
group, err := CreateGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Creating and adding the container to the
|
||||
// tracked list
|
||||
container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Testing the AddTrackContainer Function and adding the first container created
|
||||
err = AddTrackContainer(container1, "0.0.0.0")
|
||||
if err != nil {
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Adds container information to the group
|
||||
Group, err := AddContainerToGroup(container1.ID, group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
PrettyPrint(Group)
|
||||
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removing container 1 from the tracked list
|
||||
err = RemoveTrackedContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removes the new group
|
||||
// it created
|
||||
err = RemoveGroup(group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Testing if the container information is removed from the group
|
||||
func TestGroup_RemoveContainerGroup(t *testing.T) {
|
||||
// Creates a new group
|
||||
group, err := CreateGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Creating and adding the container to the
|
||||
// tracked list
|
||||
container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Testing the AddTrackContainer Function and adding the first container created
|
||||
err = AddTrackContainer(container1, "0.0.0.0")
|
||||
if err != nil {
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Adds container information to the group
|
||||
Group, err := AddContainerToGroup(container1.ID, group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println("Container added")
|
||||
PrettyPrint(Group)
|
||||
|
||||
// Removing docker container from the group
|
||||
Group, err = RemoveContainerGroup(container1.ID, group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println("Container removed")
|
||||
PrettyPrint(Group)
|
||||
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removing container 1 from the tracked list
|
||||
err = RemoveTrackedContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removes the new group
|
||||
// it created
|
||||
err = RemoveGroup(group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Testing that container are removed from all
|
||||
// created groups
|
||||
// Scenario:
|
||||
// - Create 2 groups
|
||||
// - Add Container information to each group
|
||||
// - Remove Container information from each group
|
||||
func TestGroups_RemoveContainerGroups(t *testing.T) {
|
||||
// Creates a new group
|
||||
group, err := CreateGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
// Created another group assigned to variable group 1
|
||||
group1, err := CreateGroup()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Creating and adding the container to the
|
||||
// tracked list
|
||||
container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Testing the AddTrackContainer Function and adding the first container created
|
||||
err = AddTrackContainer(container1, "0.0.0.0")
|
||||
if err != nil {
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Adds container information to the group
|
||||
Group, err := AddContainerToGroup(container1.ID, group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println("Container added")
|
||||
PrettyPrint(Group)
|
||||
|
||||
// Adds container information to the group
|
||||
Group1, err := AddContainerToGroup(container1.ID, group1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println("Container added")
|
||||
PrettyPrint(Group1)
|
||||
|
||||
// Removing docker container from the group
|
||||
err = RemoveContainerGroups(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removing container 1 from the tracked list
|
||||
err = RemoveTrackedContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removes the new group
|
||||
// it created
|
||||
err = RemoveGroup(group.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removes the new group
|
||||
// it created
|
||||
err = RemoveGroup(group1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
// // Testing out if a new group is getting created
|
||||
// func TestCreateGroup(t *testing.T) {
|
||||
// group, err := CreateGroup()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// PrettyPrint(group)
|
||||
// }
|
||||
//
|
||||
// // Testing if the group gets removed when a
|
||||
// // group ID is provided
|
||||
// func TestRemoveGroup(t *testing.T) {
|
||||
// // Creates a new group
|
||||
// group, err := CreateGroup()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// // Removes the new group
|
||||
// // it created
|
||||
// err = RemoveGroup(group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Testing if container information is added
|
||||
// // to the created group
|
||||
// func TestAddContainerToGroup(t *testing.T) {
|
||||
// // Creates a new group
|
||||
// group, err := CreateGroup()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Creating and adding the container to the
|
||||
// // tracked list
|
||||
// container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Testing the AddTrackContainer Function and adding the first container created
|
||||
// err = AddTrackContainer(container1, "0.0.0.0")
|
||||
// if err != nil {
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Adds container information to the group
|
||||
// Group, err := AddContainerToGroup(container1.ID, group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// PrettyPrint(Group)
|
||||
//
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removing container 1 from the tracked list
|
||||
// err = RemoveTrackedContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removes the new group
|
||||
// // it created
|
||||
// err = RemoveGroup(group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // Testing if the container information is removed from the group
|
||||
// func TestGroup_RemoveContainerGroup(t *testing.T) {
|
||||
// // Creates a new group
|
||||
// group, err := CreateGroup()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Creating and adding the container to the
|
||||
// // tracked list
|
||||
// container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Testing the AddTrackContainer Function and adding the first container created
|
||||
// err = AddTrackContainer(container1, "0.0.0.0")
|
||||
// if err != nil {
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Adds container information to the group
|
||||
// Group, err := AddContainerToGroup(container1.ID, group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println("Container added")
|
||||
// PrettyPrint(Group)
|
||||
//
|
||||
// // Removing docker container from the group
|
||||
// Group, err = RemoveContainerGroup(container1.ID, group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println("Container removed")
|
||||
// PrettyPrint(Group)
|
||||
//
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removing container 1 from the tracked list
|
||||
// err = RemoveTrackedContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removes the new group
|
||||
// // it created
|
||||
// err = RemoveGroup(group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Testing that container are removed from all
|
||||
// // created groups
|
||||
// // Scenario:
|
||||
// // - Create 2 groups
|
||||
// // - Add Container information to each group
|
||||
// // - Remove Container information from each group
|
||||
// func TestGroups_RemoveContainerGroups(t *testing.T) {
|
||||
// // Creates a new group
|
||||
// group, err := CreateGroup()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// // Created another group assigned to variable group 1
|
||||
// group1, err := CreateGroup()
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Creating and adding the container to the
|
||||
// // tracked list
|
||||
// container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Testing the AddTrackContainer Function and adding the first container created
|
||||
// err = AddTrackContainer(container1, "0.0.0.0")
|
||||
// if err != nil {
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Adds container information to the group
|
||||
// Group, err := AddContainerToGroup(container1.ID, group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println("Container added")
|
||||
// PrettyPrint(Group)
|
||||
//
|
||||
// // Adds container information to the group
|
||||
// Group1, err := AddContainerToGroup(container1.ID, group1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println("Container added")
|
||||
// PrettyPrint(Group1)
|
||||
//
|
||||
// // Removing docker container from the group
|
||||
// err = RemoveContainerGroups(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removing container 1 from the tracked list
|
||||
// err = RemoveTrackedContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removes the new group
|
||||
// // it created
|
||||
// err = RemoveGroup(group.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removes the new group
|
||||
// // it created
|
||||
// err = RemoveGroup(group1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,120 +1,120 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||
"testing"
|
||||
)
|
||||
// import (
|
||||
// "fmt"
|
||||
// "github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||
// "testing"
|
||||
// )
|
||||
|
||||
// Tests a scenario where the container are getting tracked
|
||||
func TestAddTrackContainer(t *testing.T) {
|
||||
// Create docker container and get SSH port
|
||||
container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
// Testing the AddTrackContainer Function
|
||||
err = AddTrackContainer(container1, "0.0.0.0")
|
||||
if err != nil {
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Testing the remove container function
|
||||
// NOTE: This test can also be considered as a whole flow on the process of
|
||||
// tracked containers
|
||||
func TestRemoveTrackedContainer(t *testing.T) {
|
||||
container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
container2, err := docker.BuildRunContainer(0, "false", "")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Testing the AddTrackContainer Function and adding the first container created
|
||||
err = AddTrackContainer(container1, "0.0.0.0")
|
||||
if err != nil {
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Testing the AddTrackContainer Function and the adding the second container created
|
||||
err = AddTrackContainer(container2, "0.0.0.0")
|
||||
if err != nil {
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container2.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
// Killing docker container created
|
||||
err = docker.StopAndRemoveContainer(container2.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removing container 1 from the tracked list
|
||||
err = RemoveTrackedContainer(container1.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Removing container 2 from the tracked list
|
||||
err = RemoveTrackedContainer(container2.ID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Test function that checks if the ID belongs to
|
||||
// a group or container running
|
||||
func TestCheckID(t *testing.T) {
|
||||
id := "grp123"
|
||||
checkID, err := CheckID(id)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Fail()
|
||||
}
|
||||
if checkID == "group" {
|
||||
fmt.Println("pass")
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
// // Tests a scenario where the container are getting tracked
|
||||
// func TestAddTrackContainer(t *testing.T) {
|
||||
// // Create docker container and get SSH port
|
||||
// container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// // Testing the AddTrackContainer Function
|
||||
// err = AddTrackContainer(container1, "0.0.0.0")
|
||||
// if err != nil {
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Testing the remove container function
|
||||
// // NOTE: This test can also be considered as a whole flow on the process of
|
||||
// // tracked containers
|
||||
// func TestRemoveTrackedContainer(t *testing.T) {
|
||||
// container1, err := docker.BuildRunContainer(0, "false", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// container2, err := docker.BuildRunContainer(0, "false", "")
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Testing the AddTrackContainer Function and adding the first container created
|
||||
// err = AddTrackContainer(container1, "0.0.0.0")
|
||||
// if err != nil {
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Testing the AddTrackContainer Function and the adding the second container created
|
||||
// err = AddTrackContainer(container2, "0.0.0.0")
|
||||
// if err != nil {
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container2.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// // Killing docker container created
|
||||
// err = docker.StopAndRemoveContainer(container2.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removing container 1 from the tracked list
|
||||
// err = RemoveTrackedContainer(container1.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
//
|
||||
// // Removing container 2 from the tracked list
|
||||
// err = RemoveTrackedContainer(container2.ID)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Test function that checks if the ID belongs to
|
||||
// // a group or container running
|
||||
// func TestCheckID(t *testing.T) {
|
||||
// id := "grp123"
|
||||
// checkID, err := CheckID(id)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// t.Fail()
|
||||
// }
|
||||
// if checkID == "group" {
|
||||
// fmt.Println("pass")
|
||||
// } else {
|
||||
// t.Fail()
|
||||
// }
|
||||
// }
|
||||
|
||||
40
default.nix
40
default.nix
@@ -1,22 +1,20 @@
|
||||
{ nixpkgs ? import <nixpkgs> { } }:
|
||||
{ pkgs ? (
|
||||
let
|
||||
inherit (builtins) fetchTree fromJSON readFile;
|
||||
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
|
||||
in
|
||||
import (fetchTree nixpkgs.locked) {
|
||||
overlays = [
|
||||
(import "${fetchTree gomod2nix.locked}/overlay.nix")
|
||||
];
|
||||
}
|
||||
)
|
||||
}:
|
||||
|
||||
let
|
||||
pkgs = [
|
||||
nixpkgs.go
|
||||
nixpkgs.tmux
|
||||
nixpkgs.docker
|
||||
nixpkgs.vim
|
||||
];
|
||||
|
||||
in
|
||||
nixpkgs.stdenv.mkDerivation {
|
||||
name = "env";
|
||||
buildInputs = pkgs;
|
||||
pure-eval = true;
|
||||
shellHook =
|
||||
''
|
||||
make
|
||||
export P2PRC=$PWD
|
||||
export PATH=$PWD:$PATH
|
||||
'';
|
||||
}
|
||||
pkgs.buildGoApplication {
|
||||
pname = "P2PRC";
|
||||
version = "2.0.0";
|
||||
pwd = ./.;
|
||||
src = ./.;
|
||||
modules = ./gomod2nix.toml;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
|
||||
in
|
||||
{
|
||||
packages.default = callPackage ./. {
|
||||
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
|
||||
};
|
||||
# packages.default = callPackage ./. {
|
||||
# inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
|
||||
# };
|
||||
|
||||
packages.default = pkgs.callPackage ./. { };
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
|
||||
@@ -1,77 +1,76 @@
|
||||
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()
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user