1
0
forked from extern/smegmesh
smegmesh/pkg/robin/requester_test.go

76 lines
1.4 KiB
Go
Raw Normal View History

2023-11-05 19:03:58 +01:00
package robin
import (
"testing"
"github.com/tim-beatham/wgmesh/pkg/conf"
2023-11-05 19:03:58 +01:00
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
"github.com/tim-beatham/wgmesh/pkg/ipc"
"github.com/tim-beatham/wgmesh/pkg/mesh"
)
func getRequester() *IpcHandler {
return &IpcHandler{Server: ctrlserver.NewCtrlServerStub()}
}
func TestCreateMeshRepliesMeshId(t *testing.T) {
var reply string
requester := getRequester()
err := requester.CreateMesh(&ipc.NewMeshArgs{
WgArgs: ipc.WireGuardArgs{
WgPort: 500,
Endpoint: "abc.com:1234",
Role: "peer",
},
2023-11-05 19:03:58 +01:00
}, &reply)
if err != nil {
t.Error(err)
}
if len(reply) == 0 {
t.Fatalf(`reply should have been returned`)
}
}
func TestListMeshesNoMeshesListsEmpty(t *testing.T) {
var reply ipc.ListMeshReply
requester := getRequester()
err := requester.ListMeshes("", &reply)
if err != nil {
t.Error(err)
}
if len(reply.Meshes) != 0 {
t.Fatalf(`meshes should be empty`)
}
}
func TestListMeshesMeshesNotEmpty(t *testing.T) {
var reply ipc.ListMeshReply
requester := getRequester()
requester.Server.GetMeshManager().AddMesh(&mesh.AddMeshParams{
MeshId: "tim123",
MeshBytes: make([]byte, 0),
Conf: &conf.WgConfiguration{},
2023-11-05 19:03:58 +01:00
})
err := requester.ListMeshes("", &reply)
if err != nil {
t.Error(err)
}
if len(reply.Meshes) != 1 {
t.Fatalf(`only only mesh exists`)
}
if reply.Meshes[0] != "tim123" {
t.Fatalf(`meshId was %s expected %s`, reply.Meshes[0], "tim123")
}
}