Skip to content
Snippets Groups Projects
Commit 6bb83ce0 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

test channels for each event

parent b1f8135b
No related branches found
No related tags found
1 merge request!691Resolve "Implement integration tests for applications"
Pipeline #178352 failed
...@@ -17,10 +17,13 @@ const localhost = "127.0.0.1" ...@@ -17,10 +17,13 @@ const localhost = "127.0.0.1"
// Application is an example for a sdn application. // Application is an example for a sdn application.
type Application struct { type Application struct {
eventService event.ServiceInterface eventService event.ServiceInterface
stopChannel chan os.Signal stopChannel chan os.Signal
grpcClientConn *grpc.ClientConn grpcClientConn *grpc.ClientConn
eventChannel chan event.Event addEventChannel chan event.Event
updateEventChannel chan event.Event
deleteEventChannel chan event.Event
subscribeEventChannel chan event.Event
} }
func NewApplication(ctx context.Context, grpcClientConn *grpc.ClientConn, controllerAddress string, topics []event.Topic, rabbitMQAddress string) *Application { func NewApplication(ctx context.Context, grpcClientConn *grpc.ClientConn, controllerAddress string, topics []event.Topic, rabbitMQAddress string) *Application {
...@@ -44,10 +47,13 @@ func NewApplication(ctx context.Context, grpcClientConn *grpc.ClientConn, contro ...@@ -44,10 +47,13 @@ func NewApplication(ctx context.Context, grpcClientConn *grpc.ClientConn, contro
} }
return &Application{ return &Application{
eventService: eventService, eventService: eventService,
stopChannel: make(chan os.Signal, 1), stopChannel: make(chan os.Signal, 1),
grpcClientConn: grpcClientConn, grpcClientConn: grpcClientConn,
eventChannel: make(chan event.Event, 1), addEventChannel: make(chan event.Event, 1),
updateEventChannel: make(chan event.Event, 1),
deleteEventChannel: make(chan event.Event, 1),
subscribeEventChannel: make(chan event.Event, 1),
} }
} }
...@@ -75,7 +81,22 @@ func (a *Application) Run(eventTypeCallbackTuples []event.TypeToCallbackTuple) { ...@@ -75,7 +81,22 @@ func (a *Application) Run(eventTypeCallbackTuples []event.TypeToCallbackTuple) {
<-forever <-forever
} }
func (a *Application) callback(event *event.Event) { func (a *Application) addCallback(event *event.Event) {
logrus.Infof("Incoming Event: EntityID: %v, ID: %v, PathsAndValues: %v, Type: %v", event.EntityID, event.ID, event.PathsAndValuesMap, event.Type) logrus.Infof("Incoming Event: EntityID: %v, ID: %v, PathsAndValues: %v, Type: %v", event.EntityID, event.ID, event.PathsAndValuesMap, event.Type)
a.eventChannel <- *event a.addEventChannel <- *event
}
func (a *Application) updateCallback(event *event.Event) {
logrus.Infof("Incoming Event: EntityID: %v, ID: %v, PathsAndValues: %v, Type: %v", event.EntityID, event.ID, event.PathsAndValuesMap, event.Type)
a.updateEventChannel <- *event
}
func (a *Application) deleteCallback(event *event.Event) {
logrus.Infof("Incoming Event: EntityID: %v, ID: %v, PathsAndValues: %v, Type: %v", event.EntityID, event.ID, event.PathsAndValuesMap, event.Type)
a.deleteEventChannel <- *event
}
func (a *Application) subscribeCallback(event *event.Event) {
logrus.Infof("Incoming Event: EntityID: %v, ID: %v, PathsAndValues: %v, Type: %v", event.EntityID, event.ID, event.PathsAndValuesMap, event.Type)
a.subscribeEventChannel <- *event
} }
...@@ -74,19 +74,19 @@ func TestMain(m *testing.M) { ...@@ -74,19 +74,19 @@ func TestMain(m *testing.M) {
eventTypeCallbackTuples := []event.TypeToCallbackTuple{ eventTypeCallbackTuples := []event.TypeToCallbackTuple{
{ {
Type: event.Add, Type: event.Add,
Callback: application.callback, Callback: application.addCallback,
}, },
{ {
Type: event.Update, Type: event.Update,
Callback: application.callback, Callback: application.updateCallback,
}, },
{ {
Type: event.Delete, Type: event.Delete,
Callback: application.callback, Callback: application.deleteCallback,
}, },
{ {
Type: event.Subscribe, Type: event.Subscribe,
Callback: application.callback, Callback: application.subscribeCallback,
}, },
} }
go application.Run(eventTypeCallbackTuples) go application.Run(eventTypeCallbackTuples)
...@@ -97,9 +97,9 @@ func TestMain(m *testing.M) { ...@@ -97,9 +97,9 @@ func TestMain(m *testing.M) {
// a user and updates it because of the login. After then only logins are done, no user creations. // a user and updates it because of the login. After then only logins are done, no user creations.
// This means that this will block after trying once, because the two attempts to read from eventChannel. // This means that this will block after trying once, because the two attempts to read from eventChannel.
_ = <-application.eventChannel _ = <-application.addEventChannel
_ = <-application.eventChannel _ = <-application.addEventChannel
_ = <-application.eventChannel _ = <-application.updateEventChannel
m.Run() m.Run()
} }
...@@ -142,14 +142,14 @@ func TestNetworkElementAddAndSubscribeEvent(t *testing.T) { ...@@ -142,14 +142,14 @@ func TestNetworkElementAddAndSubscribeEvent(t *testing.T) {
} }
// check if events are available and correct type and content // check if events are available and correct type and content
addEvent := <-application.eventChannel addEvent := <-application.addEventChannel
assert.Equal(t, event.Add.String(), addEvent.Type) assert.Equal(t, event.Add.String(), addEvent.Type)
assert.Equal(t, mneID, addEvent.EntityID.String()) assert.Equal(t, mneID, addEvent.EntityID.String())
subscribeEvent := <-application.eventChannel subscribeEvent := <-application.subscribeEventChannel
assert.Equal(t, event.Subscribe.String(), subscribeEvent.Type) assert.Equal(t, event.Subscribe.String(), subscribeEvent.Type)
subscribeEvent = <-application.eventChannel subscribeEvent = <-application.subscribeEventChannel
assert.Equal(t, event.Subscribe.String(), subscribeEvent.Type) assert.Equal(t, event.Subscribe.String(), subscribeEvent.Type)
} }
...@@ -192,7 +192,7 @@ func TestUserAddAndUpdateEvent(t *testing.T) { ...@@ -192,7 +192,7 @@ func TestUserAddAndUpdateEvent(t *testing.T) {
} }
// check if event is available and correct type // check if event is available and correct type
addEvent := <-application.eventChannel addEvent := <-application.addEventChannel
assert.Equal(t, event.Add.String(), addEvent.Type) assert.Equal(t, event.Add.String(), addEvent.Type)
assert.Equal(t, userID, addEvent.EntityID.String()) assert.Equal(t, userID, addEvent.EntityID.String())
...@@ -203,7 +203,7 @@ func TestUserAddAndUpdateEvent(t *testing.T) { ...@@ -203,7 +203,7 @@ func TestUserAddAndUpdateEvent(t *testing.T) {
t.FailNow() t.FailNow()
} }
updateEvent := <-application.eventChannel updateEvent := <-application.updateEventChannel
assert.Equal(t, event.Update.String(), updateEvent.Type) assert.Equal(t, event.Update.String(), updateEvent.Type)
assert.Equal(t, userID, updateEvent.EntityID.String()) assert.Equal(t, userID, updateEvent.EntityID.String())
} }
...@@ -239,7 +239,7 @@ func TestRoleAddAndDeleteEvent(t *testing.T) { ...@@ -239,7 +239,7 @@ func TestRoleAddAndDeleteEvent(t *testing.T) {
t.FailNow() t.FailNow()
} }
addEvent := <-application.eventChannel addEvent := <-application.addEventChannel
assert.Equal(t, event.Add.String(), addEvent.Type) assert.Equal(t, event.Add.String(), addEvent.Type)
assert.Equal(t, roleID, addEvent.EntityID.String()) assert.Equal(t, roleID, addEvent.EntityID.String())
...@@ -250,7 +250,7 @@ func TestRoleAddAndDeleteEvent(t *testing.T) { ...@@ -250,7 +250,7 @@ func TestRoleAddAndDeleteEvent(t *testing.T) {
t.FailNow() t.FailNow()
} }
deleteEvent := <-application.eventChannel deleteEvent := <-application.deleteEventChannel
assert.Equal(t, event.Delete.String(), deleteEvent.Type) assert.Equal(t, event.Delete.String(), deleteEvent.Type)
assert.Equal(t, roleID, deleteEvent.EntityID.String()) assert.Equal(t, roleID, deleteEvent.EntityID.String())
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment