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
5e5e0c6c
Commit
5e5e0c6c
authored
2 years ago
by
Fabian Seidl
Browse files
Options
Downloads
Patches
Plain Diff
added missing event publishing to routing table
parent
fd7c7a12
No related branches found
No related tags found
1 merge request
!363
Resolve "Improve security by enabling and enforcing more linting rules"
Pipeline
#110729
failed
2 years ago
Stage: build
Stage: test
Stage: analyze
Stage: integration-test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controller/topology/routing-tables/routingTableService.go
+33
-7
33 additions, 7 deletions
controller/topology/routing-tables/routingTableService.go
controller/topology/routing-tables/routingTableService_test.go
+11
-7
11 additions, 7 deletions
...oller/topology/routing-tables/routingTableService_test.go
with
44 additions
and
14 deletions
controller/topology/routing-tables/routingTableService.go
+
33
−
7
View file @
5e5e0c6c
package
routingtables
import
(
"code.fbi.h-da.de/danet/gosdn/controller/event"
eventInterfaces
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/event"
query
"code.fbi.h-da.de/danet/gosdn/controller/store"
"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
"code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
"github.com/google/uuid"
log
"github.com/sirupsen/logrus"
)
const
(
// RoutingTableEventTopic is the used topic for routing table related entity changes
RoutingTableEventTopic
=
"routingTable"
)
// Service defines a interface for a RoutingTableService
...
...
@@ -18,9 +26,10 @@ type Service interface {
// RoutingTableService is a RoutingTableService
type
RoutingTableService
struct
{
store
Store
nodeService
nodes
.
Service
portService
ports
.
Service
store
Store
nodeService
nodes
.
Service
portService
ports
.
Service
eventService
eventInterfaces
.
Service
}
// NewRoutingTableService creates a RoutingTableService
...
...
@@ -28,11 +37,13 @@ func NewRoutingTableService(
store
Store
,
nodeService
nodes
.
Service
,
portService
ports
.
Service
,
eventService
eventInterfaces
.
Service
,
)
Service
{
return
&
RoutingTableService
{
store
:
store
,
nodeService
:
nodeService
,
portService
:
portService
,
store
:
store
,
nodeService
:
nodeService
,
portService
:
portService
,
eventService
:
eventService
,
}
}
...
...
@@ -57,7 +68,12 @@ func (r *RoutingTableService) createRoutingTable(routingTable RoutingTable) (Rou
return
routingTable
,
err
}
return
routingTable
,
err
if
err
:=
r
.
eventService
.
PublishEvent
(
RoutingTableEventTopic
,
event
.
NewAddEvent
(
routingTable
.
ID
));
err
!=
nil
{
//TODO: improve error handling, maybe to sth like reconnect
log
.
Error
(
err
)
}
return
routingTable
,
nil
}
// Update updates an existing routingTable
...
...
@@ -67,6 +83,11 @@ func (r *RoutingTableService) Update(routingTable RoutingTable) error {
return
err
}
if
err
:=
r
.
eventService
.
PublishEvent
(
RoutingTableEventTopic
,
event
.
NewUpdateEvent
(
routingTable
.
ID
));
err
!=
nil
{
//TODO: improve error handling, maybe to sth like reconnect
log
.
Error
(
err
)
}
return
nil
}
...
...
@@ -77,6 +98,11 @@ func (r *RoutingTableService) Delete(routingTable RoutingTable) error {
return
err
}
if
err
:=
r
.
eventService
.
PublishEvent
(
RoutingTableEventTopic
,
event
.
NewDeleteEvent
(
routingTable
.
ID
));
err
!=
nil
{
//TODO: improve error handling, maybe to sth like reconnect
log
.
Error
(
err
)
}
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
controller/topology/routing-tables/routingTableService_test.go
+
11
−
7
View file @
5e5e0c6c
...
...
@@ -5,6 +5,7 @@ import (
"testing"
eventservice
"code.fbi.h-da.de/danet/gosdn/controller/eventService"
eventInterfaces
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/event"
query
"code.fbi.h-da.de/danet/gosdn/controller/store"
"code.fbi.h-da.de/danet/gosdn/controller/topology/nodes"
"code.fbi.h-da.de/danet/gosdn/controller/topology/ports"
...
...
@@ -85,9 +86,10 @@ func getTestStoreWithPorts(t *testing.T, portsToAdd []ports.Port) ports.Store {
func
TestNewRoutingTableService
(
t
*
testing
.
T
)
{
type
args
struct
{
store
Store
nodeService
nodes
.
Service
portService
ports
.
Service
store
Store
nodeService
nodes
.
Service
portService
ports
.
Service
eventService
eventInterfaces
.
Service
}
tests
:=
[]
struct
{
name
string
...
...
@@ -97,20 +99,22 @@ func TestNewRoutingTableService(t *testing.T) {
{
name
:
"should create a new topology service"
,
args
:
args
{
store
:
getTestStoreWithRoutingTables
(
t
,
[]
RoutingTable
{}),
nodeService
:
nodes
.
NewNodeService
(
getTestStoreWithNodes
(
t
,
[]
nodes
.
Node
{}),
eventservice
.
NewMockEventService
()),
portService
:
ports
.
NewPortService
(
getTestStoreWithPorts
(
t
,
[]
ports
.
Port
{}),
eventservice
.
NewMockEventService
()),
store
:
getTestStoreWithRoutingTables
(
t
,
[]
RoutingTable
{}),
nodeService
:
nodes
.
NewNodeService
(
getTestStoreWithNodes
(
t
,
[]
nodes
.
Node
{}),
eventservice
.
NewMockEventService
()),
portService
:
ports
.
NewPortService
(
getTestStoreWithPorts
(
t
,
[]
ports
.
Port
{}),
eventservice
.
NewMockEventService
()),
eventService
:
eventservice
.
NewMockEventService
(),
},
want
:
NewRoutingTableService
(
getTestStoreWithRoutingTables
(
t
,
[]
RoutingTable
{}),
nodes
.
NewNodeService
(
getTestStoreWithNodes
(
t
,
[]
nodes
.
Node
{}),
eventservice
.
NewMockEventService
()),
ports
.
NewPortService
(
getTestStoreWithPorts
(
t
,
[]
ports
.
Port
{}),
eventservice
.
NewMockEventService
()),
eventservice
.
NewMockEventService
(),
),
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
if
got
:=
NewRoutingTableService
(
tt
.
args
.
store
,
tt
.
args
.
nodeService
,
tt
.
args
.
portService
);
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
if
got
:=
NewRoutingTableService
(
tt
.
args
.
store
,
tt
.
args
.
nodeService
,
tt
.
args
.
portService
,
tt
.
args
.
eventService
);
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"NewNodeService() = %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