Skip to content
Snippets Groups Projects
Commit e1990167 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

CLI test skeleton

parent d40abebd
No related branches found
No related tags found
2 merge requests!101Resolve "Increase test coverage",!90Develop
......@@ -58,7 +58,7 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe
return &pb.HelloReply{Message: "Hello " + in.GetName(), GoSDNInfo: "goSDN in version: DEVELOP"}, nil
}
//GetLog creates a continuous stream between ciena and server to send goSDN logs
// CreateLogStream creates a continuous stream between client and server to send goSDN logs
func (s *server) CreateLogStream(req *emptypb.Empty, stream pb.GrpcCli_CreateLogStreamServer) error {
conn := &logConnection{
stream: stream,
......@@ -138,27 +138,8 @@ func getCLIGoing(core *Core) {
}
}
// SBI specific calls, by now TAPI only
func (s *server) TAPIGetEdge(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) {
log.Info("Received: ", in.GetName())
// TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil
}
func (s *server) TAPIGetEdgeNode(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) {
log.Info("Received: ", in.GetName())
// TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil
}
func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIReply, error) {
log.Info("Received: ", in.GetName())
// TODO: Implement
return &pb.TAPIReply{Message: "Done"}, nil
}
//CreatePND creates a new PND and adds it to the principalNetworkDomain map of
//the core
// CreatePND creates a new PND and adds it to the principalNetworkDomain map of
// the core
func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.CreatePNDReply, error) {
log.Info("Received: Create a PND with the name", in.GetName())
sbi := s.core.southboundInterfaces[in.GetSbi()]
......@@ -168,8 +149,8 @@ func (s *server) CreatePND(ctx context.Context, in *pb.CreatePNDRequest) (*pb.Cr
return &pb.CreatePNDReply{Message: "Created new PND: " + id.String()}, nil
}
//GetAllPNDs is a request to get all current registered PNDs and returns a slim
//variant of PNDs and their respective devices
// GetAllPNDs is a request to get all currently registered PNDs and returns a slim
// variant of PNDs and their respective devices
func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDsReply, error) {
log.Info("Received: Get all PNDs")
var pnds []*pb.PND
......@@ -195,7 +176,7 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs
return &pb.AllPNDsReply{Pnds: pnds}, nil
}
//GetAllSBINames returns all registered SBIs from core.
// GetAllSBINames returns all registered SBIs from core.
func (s *server) GetAllSBINames(ctx context.Context, in *emptypb.Empty) (*pb.AllSBINamesReply, error) {
var sbiNames []string
for _, s := range s.core.southboundInterfaces {
......@@ -204,8 +185,8 @@ func (s *server) GetAllSBINames(ctx context.Context, in *emptypb.Empty) (*pb.All
return &pb.AllSBINamesReply{SbiNames: sbiNames}, nil
}
//AddDevice adds a new Device to a specific PND
//currently this is only working with gnmi transports
// AddDevice adds a new Device to a specific PND
// currently this is only working with gnmi transports
func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.AddDeviceReply, error) {
log.Info("Received: AddDevice")
uuidPND, err := uuid.Parse(in.UuidPND)
......@@ -241,7 +222,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err
}
//HandleDeviceGetRequest handles a GET request via pnd.Request()
// HandleDeviceGetRequest handles a GET request via pnd.Request()
func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) {
log.Info("Received: HandleDeviceGetRequest")
uuidPND, err := uuid.Parse(in.GetUuidPND())
......
package nucleus
import (
pb "code.fbi.h-da.de/cocsn/gosdn/api/proto"
"context"
"github.com/google/uuid"
"google.golang.org/protobuf/types/known/emptypb"
"reflect"
"testing"
)
func Test_buf_Write(t *testing.T) {
type args struct {
p []byte
}
tests := []struct {
name string
b buf
args args
wantN int
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotN, err := tt.b.Write(tt.args.p)
if (err != nil) != tt.wantErr {
t.Errorf("Write() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotN != tt.wantN {
t.Errorf("Write() gotN = %v, want %v", gotN, tt.wantN)
}
})
}
}
func Test_getCLIGoing(t *testing.T) {
type args struct {
core *Core
}
tests := []struct {
name string
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
})
}
}
func Test_server_AddDevice(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *pb.AddDeviceRequest
}
tests := []struct {
name string
fields fields
args args
want *pb.AddDeviceReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.AddDevice(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("AddDevice() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("AddDevice() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_server_BroadcastLog(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
log *pb.LogReply
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_ = &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
})
}
}
func Test_server_CreateLogStream(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
req *emptypb.Empty
stream pb.GrpcCli_CreateLogStreamServer
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
if err := s.CreateLogStream(tt.args.req, tt.args.stream); (err != nil) != tt.wantErr {
t.Errorf("CreateLogStream() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func Test_server_CreatePND(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *pb.CreatePNDRequest
}
tests := []struct {
name string
fields fields
args args
want *pb.CreatePNDReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.CreatePND(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("CreatePND() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("CreatePND() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_server_GetAllPNDs(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *emptypb.Empty
}
tests := []struct {
name string
fields fields
args args
want *pb.AllPNDsReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.GetAllPNDs(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("GetAllPNDs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAllPNDs() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_server_GetAllSBINames(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *emptypb.Empty
}
tests := []struct {
name string
fields fields
args args
want *pb.AllSBINamesReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.GetAllSBINames(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("GetAllSBINames() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAllSBINames() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_server_HandleDeviceGetRequest(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *pb.DeviceGetRequest
}
tests := []struct {
name string
fields fields
args args
want *pb.DeviceGetReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.HandleDeviceGetRequest(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("HandleDeviceGetRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("HandleDeviceGetRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_server_SayHello(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *pb.HelloRequest
}
tests := []struct {
name string
fields fields
args args
want *pb.HelloReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.SayHello(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("SayHello() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("SayHello() got = %v, want %v", got, tt.want)
}
})
}
}
func Test_server_Shutdown(t *testing.T) {
}
func Test_server_TAPIGetEdge(t *testing.T) {
}
func Test_server_TAPIGetEdgeNode(t *testing.T) {
}
func Test_server_TAPIGetLink(t *testing.T) {
type fields struct {
UnimplementedGrpcCliServer pb.UnimplementedGrpcCliServer
core *Core
logConnections []*logConnection
devices map[uuid.UUID]Device
}
type args struct {
ctx context.Context
in *pb.ShutdownRequest
}
tests := []struct {
name string
fields fields
args args
want *pb.ShutdownReply
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{
UnimplementedGrpcCliServer: tt.fields.UnimplementedGrpcCliServer,
core: tt.fields.core,
logConnections: tt.fields.logConnections,
devices: tt.fields.devices,
}
got, err := s.Shutdown(tt.args.ctx, tt.args.in)
if (err != nil) != tt.wantErr {
t.Errorf("Shutdown() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Shutdown() got = %v, want %v", got, tt.want)
}
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment