Newer
Older
Fabian Seidl
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package integration_test_application
import (
"context"
"fmt"
"testing"
mnepb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/networkelement"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
"code.fbi.h-da.de/danet/gosdn/application-framework/event"
integration_test_utils "code.fbi.h-da.de/danet/gosdn/integration-tests/integrationTestUtils"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
)
const targetAAdress = "gnmi-target_A:7030"
const targetUserAndPW = "admin"
const pndID = "5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d"
const pluginID = "d1c269a2-6482-4010-b0d8-679dff73153b"
// The connection to the controller to use in each test.
var conn *grpc.ClientConn
// The context containing the credentials when authenticated.
var ctx context.Context
// A defaultSDN config with default/empty values.
var defaultSDNConfig string
var application *Application
func TestMain(m *testing.M) {
localConn, localCtx, err := integration_test_utils.CreateSecureConnection()
if err != nil {
fmt.Println(err.Error())
}
conn = localConn
ctx = localCtx
sndConfig, err := integration_test_utils.ExportCurrentSDNConfig(conn, ctx)
defaultSDNConfig = sndConfig
if err != nil {
fmt.Println(err.Error())
}
integration_test_utils.ApplySDNConfig(conn, ctx, defaultSDNConfig)
topics := []event.Topic{event.ManagedNetworkElement, event.User}
application = NewApplication(ctx, localConn, ":55055", topics)
eventTypeCallbackTuples := []event.TypeToCallbackTuple{
{
Type: event.Add,
Callback: application.callback,
},
{
Type: event.Update,
Callback: application.callback,
},
{
Type: event.Delete,
Callback: application.callback,
},
{
Type: event.Subscribe,
Callback: application.callback,
},
}
go application.Run(eventTypeCallbackTuples)
asdf := <-application.eventChannel
logrus.Info(asdf)
m.Run()
}
func TestAddEvent(t *testing.T) {
defer integration_test_utils.ApplySDNConfig(conn, ctx, defaultSDNConfig)
// setup required parameters
opt := &tpb.TransportOption{
Address: targetAAdress,
Username: targetUserAndPW,
Password: targetUserAndPW,
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{},
},
Tls: true,
}
addListRequest := &mnepb.AddListRequest{
Timestamp: integration_test_utils.GetTimestamp(),
Mne: []*mnepb.SetMne{
{
Address: "gnmi-target_A:7030",
Pid: pndID,
PluginId: pluginID,
MneName: "Horst",
TransportOption: opt,
},
},
Pid: pndID,
}
// setup gRPC services
mneService := mnepb.NewNetworkElementServiceClient(conn)
// add one device to the controller
_, err := mneService.AddList(ctx, addListRequest)
if err != nil {
t.Error(err)
t.FailNow()
}
// check if event is available and correct type
addEvent := <-application.eventChannel
assert.IsType(t, event.Add.String(), addEvent.Type)
}