Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
e1990167
Commit
e1990167
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
CLI test skeleton
parent
d40abebd
No related branches found
No related tags found
2 merge requests
!101
Resolve "Increase test coverage"
,
!90
Develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nucleus/cli-handling.go
+9
-28
9 additions, 28 deletions
nucleus/cli-handling.go
nucleus/cli-handling_test.go
+358
-23
358 additions, 23 deletions
nucleus/cli-handling_test.go
with
367 additions
and
51 deletions
nucleus/cli-handling.go
+
9
−
28
View file @
e1990167
...
...
@@ -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 cien
a
and server to send goSDN logs
//
CreateLogStream
creates a continuous stream between c
l
ien
t
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 current
ly
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
())
...
...
This diff is collapsed.
Click to expand it.
nucleus/cli-handling_test.go
+
358
−
23
View file @
e1990167
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
)
}
})
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment