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
d40abebd
Commit
d40abebd
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
GNMI Transport and PND tests complete
parent
7eeef8ef
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/gnmi_transport_test.go
+19
-14
19 additions, 14 deletions
nucleus/gnmi_transport_test.go
nucleus/principalNetworkDomain_test.go
+63
-46
63 additions, 46 deletions
nucleus/principalNetworkDomain_test.go
with
82 additions
and
60 deletions
nucleus/gnmi_transport_test.go
+
19
−
14
View file @
d40abebd
...
...
@@ -35,13 +35,6 @@ func testSetupGnmi() {
Encoding
:
gpb
.
Encoding_PROTO
,
}
transport
=
&
Gnmi
{
SetNode
:
nil
,
RespChan
:
make
(
chan
*
gpb
.
SubscribeResponse
),
config
:
gnmiConfig
,
client
:
&
mocks
.
GNMIClient
{},
}
startGnmiTarget
=
make
(
chan
string
)
stopGnmiTarget
=
make
(
chan
bool
)
go
targetRunner
()
...
...
@@ -56,13 +49,22 @@ func targetRunner() {
}
}
var
transport
*
Gnmi
func
mockTransport
()
Gnmi
{
return
Gnmi
{
SetNode
:
nil
,
RespChan
:
make
(
chan
*
gpb
.
SubscribeResponse
),
config
:
gnmiConfig
,
client
:
&
mocks
.
GNMIClient
{},
}
}
var
gnmiConfig
*
gnmi
.
Config
var
startGnmiTarget
chan
string
var
stopGnmiTarget
chan
bool
var
mockContext
=
mock
.
MatchedBy
(
func
(
ctx
context
.
Context
)
bool
{
return
true
})
func
TestGnmi_Capabilities
(
t
*
testing
.
T
)
{
transport
:=
mockTransport
()
capabilityResponse
:=
&
gpb
.
CapabilityResponse
{
SupportedModels
:
nil
,
SupportedEncodings
:
[]
gpb
.
Encoding
{
gpb
.
Encoding_PROTO
,
gpb
.
Encoding_JSON_IETF
,
gpb
.
Encoding_JSON
},
...
...
@@ -93,7 +95,7 @@ func TestGnmi_Capabilities(t *testing.T) {
}{
{
name
:
"mock"
,
fields
:
fields
{
transport
:
transport
},
fields
:
fields
{
transport
:
&
transport
},
args
:
args
{
endpoint
:
gnmiConfig
.
Addr
,
runEndpoint
:
false
,
...
...
@@ -151,6 +153,7 @@ func TestGnmi_Close(t *testing.T) {
}
func
TestGnmi_Get
(
t
*
testing
.
T
)
{
transport
:=
mockTransport
()
getRequest
:=
&
gpb
.
GetRequest
{
Prefix
:
nil
,
Path
:
nil
,
...
...
@@ -201,14 +204,14 @@ func TestGnmi_Get(t *testing.T) {
},
{
name
:
"mock"
,
fields
:
fields
{
transport
:
transport
},
fields
:
fields
{
transport
:
&
transport
},
args
:
args
{},
want
:
getResponse
,
wantErr
:
false
,
},
{
name
:
"endpoint"
,
fields
:
fields
{
transport
:
transport
},
fields
:
fields
{
transport
:
&
transport
},
args
:
args
{
runEndpoint
:
true
,
},
...
...
@@ -237,6 +240,7 @@ func TestGnmi_Get(t *testing.T) {
}
func
TestGnmi_GetConfig
(
t
*
testing
.
T
)
{
transport
:=
mockTransport
()
type
fields
struct
{
transport
*
Gnmi
}
...
...
@@ -247,7 +251,7 @@ func TestGnmi_GetConfig(t *testing.T) {
}{
{
name
:
"default"
,
fields
:
fields
{
transport
:
transport
},
fields
:
fields
{
transport
:
&
transport
},
want
:
gnmiConfig
,
},
}
...
...
@@ -455,6 +459,7 @@ func TestGnmi_get(t *testing.T) {
}
func
TestGnmi_getWithRequest
(
t
*
testing
.
T
)
{
transport
:=
mockTransport
()
reqFullNode
:=
&
gpb
.
GetRequest
{}
reqInterfacesWildcard
:=
&
gpb
.
GetRequest
{}
respFullNode
:=
&
gpb
.
GetResponse
{}
...
...
@@ -504,7 +509,7 @@ func TestGnmi_getWithRequest(t *testing.T) {
}{
{
name
:
"getFullNode"
,
fields
:
fields
{
transport
:
transport
},
fields
:
fields
{
transport
:
&
transport
},
args
:
args
{
request
:
reqFullNode
,
},
...
...
@@ -513,7 +518,7 @@ func TestGnmi_getWithRequest(t *testing.T) {
},
{
name
:
"getInterfacesWildcard"
,
fields
:
fields
{
transport
:
transport
},
fields
:
fields
{
transport
:
&
transport
},
args
:
args
{
request
:
reqInterfacesWildcard
,
},
...
...
This diff is collapsed.
Click to expand it.
nucleus/principalNetworkDomain_test.go
+
63
−
46
View file @
d40abebd
...
...
@@ -22,33 +22,36 @@ func testSetupPnd() {
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
defaultPnd
=
&
pndImplementation
{
name
:
"default"
,
description
:
"default test pnd"
,
sbi
:
map
[
string
]
SouthboundInterface
{
"default"
:
&
OpenConfig
{}},
devices
:
map
[
uuid
.
UUID
]
*
Device
{},
}
deviceWithMockTransport
=
&
Device
{
func
mockDevice
()
Device
{
return
Device
{
GoStruct
:
nil
,
SBI
:
&
OpenConfig
{},
Config
:
DeviceConfig
{
Uuid
:
mdid
,
Address
:
""
,
Username
:
""
,
Password
:
""
,
Address
:
"
mock://localhost
"
,
Username
:
"
mock
"
,
Password
:
"
mock
"
,
},
Transport
:
&
mocks
.
Transport
{},
}
}
var
defaultPnd
*
pndImplementation
func
freshPnd
()
pndImplementation
{
return
pndImplementation
{
name
:
"default"
,
description
:
"default test pnd"
,
sbi
:
map
[
string
]
SouthboundInterface
{
"default"
:
&
OpenConfig
{}},
devices
:
map
[
uuid
.
UUID
]
*
Device
{},
}
}
var
did
uuid
.
UUID
var
mdid
uuid
.
UUID
var
deviceWithMockTransport
*
Device
func
TestNewPND
(
t
*
testing
.
T
)
{
pnd
:=
freshPnd
()
type
args
struct
{
name
string
description
string
...
...
@@ -66,7 +69,7 @@ func TestNewPND(t *testing.T) {
description
:
"default test pnd"
,
sbi
:
&
OpenConfig
{},
},
want
:
defaultP
nd
,
want
:
&
p
nd
,
},
}
for
_
,
tt
:=
range
tests
{
...
...
@@ -115,16 +118,17 @@ func Test_pndImplementation_AddDevice(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
err
:=
defaultPnd
.
AddDevice
(
tt
.
args
.
device
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
pnd
:=
freshPnd
()
if
err
:=
pnd
.
AddDevice
(
tt
.
args
.
device
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"AddDevice() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
_
,
ok
:=
defaultP
nd
.
devices
[
did
]
_
,
ok
:=
p
nd
.
devices
[
did
]
if
!
ok
{
t
.
Errorf
(
"AddDevice() Device %v not in device store %v"
,
tt
.
args
.
device
,
defaultP
nd
.
devices
)
tt
.
args
.
device
,
p
nd
.
devices
)
}
delete
(
pnd
.
devices
,
did
)
})
delete
(
defaultPnd
.
devices
,
did
)
}
}
...
...
@@ -141,16 +145,17 @@ func Test_pndImplementation_AddSbi(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
err
:=
defaultPnd
.
AddSbi
(
tt
.
args
.
sbi
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
pnd
:=
freshPnd
()
if
err
:=
pnd
.
AddSbi
(
tt
.
args
.
sbi
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"AddSbi() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
_
,
ok
:=
defaultP
nd
.
GetSBIs
()[
tt
.
args
.
sbi
.
SbiIdentifier
()]
_
,
ok
:=
p
nd
.
GetSBIs
()[
tt
.
args
.
sbi
.
SbiIdentifier
()]
if
!
ok
{
t
.
Errorf
(
"AddSbi() SBI %v not in device store %v"
,
tt
.
args
.
sbi
,
defaultP
nd
.
GetSBIs
())
tt
.
args
.
sbi
,
p
nd
.
GetSBIs
())
}
delete
(
pnd
.
sbi
,
tt
.
args
.
sbi
.
SbiIdentifier
())
})
delete
(
defaultPnd
.
sbi
,
tt
.
args
.
sbi
.
SbiIdentifier
())
}
}
...
...
@@ -175,12 +180,13 @@ func Test_pndImplementation_ContainsDevice(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
defaultPnd
.
devices
[
tt
.
args
.
uuid
]
=
tt
.
args
.
device
if
got
:=
defaultPnd
.
ContainsDevice
(
tt
.
args
.
uuid
);
got
!=
tt
.
want
{
pnd
:=
freshPnd
()
pnd
.
devices
[
did
]
=
tt
.
args
.
device
if
got
:=
pnd
.
ContainsDevice
(
tt
.
args
.
uuid
);
got
!=
tt
.
want
{
t
.
Errorf
(
"ContainsDevice() = %v, want %v"
,
got
,
tt
.
want
)
}
delete
(
pnd
.
devices
,
did
)
})
delete
(
defaultPnd
.
devices
,
did
)
}
}
...
...
@@ -222,7 +228,8 @@ func Test_pndImplementation_GetDescription(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
defaultPnd
.
GetDescription
();
got
!=
tt
.
want
{
pnd
:=
freshPnd
()
if
got
:=
pnd
.
GetDescription
();
got
!=
tt
.
want
{
t
.
Errorf
(
"GetDescription() = %v, want %v"
,
got
,
tt
.
want
)
}
})
...
...
@@ -238,7 +245,8 @@ func Test_pndImplementation_GetName(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
defaultPnd
.
GetName
();
got
!=
tt
.
want
{
pnd
:=
freshPnd
()
if
got
:=
pnd
.
GetName
();
got
!=
tt
.
want
{
t
.
Errorf
(
"GetName() = %v, want %v"
,
got
,
tt
.
want
)
}
})
...
...
@@ -246,15 +254,16 @@ func Test_pndImplementation_GetName(t *testing.T) {
}
func
Test_pndImplementation_GetSBIs
(
t
*
testing
.
T
)
{
pnd
:=
freshPnd
()
tests
:=
[]
struct
{
name
string
want
map
[
string
]
SouthboundInterface
}{
{
name
:
"default"
,
want
:
defaultP
nd
.
sbi
},
{
name
:
"default"
,
want
:
p
nd
.
sbi
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
defaultP
nd
.
GetSBIs
();
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
if
got
:=
p
nd
.
GetSBIs
();
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"GetSBIs() = %v, want %v"
,
got
,
tt
.
want
)
}
})
...
...
@@ -275,6 +284,7 @@ func Test_pndImplementation_MarshalDevice(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
pnd
:=
freshPnd
()
d
:=
&
Device
{
GoStruct
:
&
openconfig
.
Device
{},
SBI
:
nil
,
...
...
@@ -286,8 +296,8 @@ func Test_pndImplementation_MarshalDevice(t *testing.T) {
},
Transport
:
nil
,
}
_
=
defaultP
nd
.
addDevice
(
d
)
got
,
err
:=
defaultP
nd
.
MarshalDevice
(
tt
.
args
.
uuid
)
_
=
p
nd
.
addDevice
(
d
)
got
,
err
:=
p
nd
.
MarshalDevice
(
tt
.
args
.
uuid
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"MarshalDevice() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
...
...
@@ -295,6 +305,7 @@ func Test_pndImplementation_MarshalDevice(t *testing.T) {
if
got
!=
tt
.
want
{
t
.
Errorf
(
"MarshalDevice() got = %v, want %v"
,
got
,
tt
.
want
)
}
delete
(
pnd
.
devices
,
did
)
})
}
}
...
...
@@ -312,14 +323,15 @@ func Test_pndImplementation_RemoveDevice(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
pnd
:=
freshPnd
()
d
:=
&
Device
{
Config
:
DeviceConfig
{
Uuid
:
did
}}
_
=
defaultP
nd
.
addDevice
(
d
)
if
err
:=
defaultP
nd
.
RemoveDevice
(
tt
.
args
.
uuid
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
_
=
p
nd
.
addDevice
(
d
)
if
err
:=
p
nd
.
RemoveDevice
(
tt
.
args
.
uuid
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"RemoveDevice() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
_
,
ok
:=
defaultP
nd
.
devices
[
did
]
_
,
ok
:=
p
nd
.
devices
[
did
]
if
ok
{
t
.
Errorf
(
"RemoveDevice() device %v still in device store %v"
,
d
,
defaultP
nd
.
devices
)
t
.
Errorf
(
"RemoveDevice() device %v still in device store %v"
,
d
,
p
nd
.
devices
)
}
})
}
...
...
@@ -338,13 +350,14 @@ func Test_pndImplementation_RemoveSbi(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
_
=
defaultPnd
.
addSbi
(
&
OpenConfig
{})
if
err
:=
defaultPnd
.
RemoveSbi
(
tt
.
args
.
sbiIdentifier
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
pnd
:=
freshPnd
()
_
=
pnd
.
addSbi
(
&
OpenConfig
{})
if
err
:=
pnd
.
RemoveSbi
(
tt
.
args
.
sbiIdentifier
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"RemoveSbi() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
sbi
,
ok
:=
defaultP
nd
.
sbi
[
tt
.
args
.
sbiIdentifier
]
sbi
,
ok
:=
p
nd
.
sbi
[
tt
.
args
.
sbiIdentifier
]
if
ok
{
t
.
Errorf
(
"RemoveDevice() SBI %v still in SBI store %v"
,
sbi
,
defaultP
nd
.
sbi
)
t
.
Errorf
(
"RemoveDevice() SBI %v still in SBI store %v"
,
sbi
,
p
nd
.
sbi
)
}
})
}
...
...
@@ -382,16 +395,18 @@ func Test_pndImplementation_Request(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
deviceWithMockTransport
:=
mockDevice
()
pnd
:=
freshPnd
()
tr
:=
deviceWithMockTransport
.
Transport
.
(
*
mocks
.
Transport
)
tr
.
On
(
"Get"
,
mockContext
,
mock
.
Anything
)
.
Return
(
mock
.
Anything
,
tt
.
args
.
rErr
)
tr
.
On
(
"ProcessResponse"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
tt
.
args
.
rErr
)
_
=
defaultP
nd
.
addDevice
(
deviceWithMockTransport
)
if
err
:=
defaultP
nd
.
Request
(
tt
.
args
.
uuid
,
tt
.
args
.
path
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
_
=
p
nd
.
addDevice
(
&
deviceWithMockTransport
)
if
err
:=
p
nd
.
Request
(
tt
.
args
.
uuid
,
tt
.
args
.
path
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Request() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
delete
(
pnd
.
devices
,
mdid
)
})
}
delete
(
defaultPnd
.
devices
,
mdid
)
}
func
Test_pndImplementation_RequestAll
(
t
*
testing
.
T
)
{
...
...
@@ -417,7 +432,7 @@ func Test_pndImplementation_RequestAll(t *testing.T) {
{
name
:
"error"
,
args
:
args
{
uuid
:
uuid
.
UUID
{}
,
uuid
:
did
,
path
:
""
,
rErr
:
errors
.
New
(
"deliberate test fail"
),
},
...
...
@@ -426,14 +441,16 @@ func Test_pndImplementation_RequestAll(t *testing.T) {
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
deviceWithMockTransport
:=
mockDevice
()
pnd
:=
freshPnd
()
tr
:=
deviceWithMockTransport
.
Transport
.
(
*
mocks
.
Transport
)
tr
.
On
(
"Get"
,
mockContext
,
mock
.
Anything
)
.
Return
(
mock
.
Anything
,
tt
.
args
.
rErr
)
tr
.
On
(
"ProcessResponse"
,
mock
.
Anything
,
mock
.
Anything
,
mock
.
Anything
)
.
Return
(
tt
.
args
.
rErr
)
_
=
defaultP
nd
.
addDevice
(
deviceWithMockTransport
)
if
err
:=
defaultP
nd
.
RequestAll
(
tt
.
args
.
path
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
_
=
p
nd
.
addDevice
(
&
deviceWithMockTransport
)
if
err
:=
p
nd
.
RequestAll
(
tt
.
args
.
path
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"RequestAll() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
delete
(
pnd
.
devices
,
mdid
)
})
delete
(
defaultPnd
.
devices
,
mdid
)
}
}
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