This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messenger_test.go
103 lines (90 loc) · 2.65 KB
/
messenger_test.go
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
package main
import (
"encoding/json"
"testing"
"github.com/google/uuid"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestBuildMqURI(t *testing.T) {
amqps := buildMqURI("localhost", "5555", "mquser", "mqpass", "/vhost", true)
assert.Equal(t, "amqps://mquser:mqpass@localhost:5555/vhost", amqps)
amqp := buildMqURI("localhost", "5555", "mquser", "mqpass", "/vhost", false)
assert.Equal(t, "amqp://mquser:mqpass@localhost:5555/vhost", amqp)
}
func TestNewAMQPMessenger(t *testing.T) {
viper.Reset()
viper.Set("server.confFile", "dev_utils/config.yaml")
config, err := NewConfig()
assert.NoError(t, err)
assert.NotNil(t, config)
tlsConfig, err := TLSConfigBroker(config)
if err != nil {
t.Log(err)
t.Skip("skip test since certificates are not present")
}
assert.NotNil(t, tlsConfig)
assert.NoError(t, err)
m, err := NewAMQPMessenger(config.Broker, tlsConfig)
assert.NoError(t, err)
assert.NotNil(t, m)
}
func TestSendMessage(t *testing.T) {
viper.Reset()
viper.Set("server.confFile", "dev_utils/config.yaml")
config, err := NewConfig()
assert.NotNil(t, config)
assert.NoError(t, err)
tlsConfig, err := TLSConfigBroker(config)
if err != nil {
t.Log(err)
t.Skip("skip test since certificates are not present")
}
assert.NotNil(t, tlsConfig)
assert.NoError(t, err)
messenger, err := NewAMQPMessenger(config.Broker, tlsConfig)
assert.NoError(t, err)
event := Event{}
checksum := Checksum{}
event.Operation = "TestSendMessage"
event.Username = "Dummy"
checksum.Type = "md5"
checksum.Value = "123456789"
event.Checksum = []interface{}{checksum}
jsonMessage, err := json.Marshal(event)
assert.NoError(t, err)
uuid, _ := uuid.NewRandom()
t.Log("uuid: ", uuid)
err = messenger.SendMessage(uuid.String(), jsonMessage)
assert.NoError(t, err)
}
func TestCreateNewChannel(t *testing.T) {
viper.Reset()
viper.Set("server.confFile", "dev_utils/config.yaml")
config, err := NewConfig()
assert.NotNil(t, config)
assert.NoError(t, err)
tlsConfig, err := TLSConfigBroker(config)
if err != nil {
t.Log(err)
t.Skip("skip test since certificates are not present")
}
assert.NotNil(t, tlsConfig)
assert.NoError(t, err)
messenger, err := NewAMQPMessenger(config.Broker, tlsConfig)
messenger.channel.Close()
assert.NoError(t, err)
event := Event{}
checksum := Checksum{}
event.Operation = "TestRecreateChannel"
event.Username = "Dummy"
checksum.Type = "md5"
checksum.Value = "123456789"
event.Checksum = []interface{}{checksum}
jsonMessage, err := json.Marshal(event)
assert.NoError(t, err)
uuid, _ := uuid.NewRandom()
t.Log("uuid: ", uuid)
err = messenger.SendMessage(uuid.String(), jsonMessage)
assert.NoError(t, err)
}