Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Merge live tests into messenger tests
Browse files Browse the repository at this point in the history
Skip the test step if the compose certs are missing
  • Loading branch information
jbygdell committed Nov 4, 2022
1 parent fe83e68 commit d58ee62
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 50 deletions.
2 changes: 1 addition & 1 deletion dev_utils/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ services:
- "-c"
- "cd /app; echo 'Running go ${GOLANG_VERSION:-1.18} tests';
go install 2>/dev/null
&& go test -tags live -coverprofile=coverage.txt -covermode=atomic"
&& go test . -v -coverprofile=coverage.txt -covermode=atomic"
depends_on:
mq:
condition: service_healthy
Expand Down
49 changes: 0 additions & 49 deletions live_test.go

This file was deleted.

47 changes: 47 additions & 0 deletions messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

Expand All @@ -12,3 +13,49 @@ func TestBuildMqURI(t *testing.T) {
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)

assert.NotPanics(t, func() { NewAMQPMessenger(config.Broker, tlsConfig) })
}

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 := NewAMQPMessenger(config.Broker, tlsConfig)

event := Event{}
checksum := Checksum{}
event.Username = "Dummy"
checksum.Type = "md5"
checksum.Value = "123456789"
event.Checksum = []interface{}{checksum}

err = messenger.SendMessage(event)
assert.NoError(t, err)
}

0 comments on commit d58ee62

Please sign in to comment.