This is to fix nose as it seems to require all tests to be sitting at the root project level. Addresses GitHub #17 Change-Id: Ia50c45c20e5300d17cdb13283ba1c1e9783f739f
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""
|
|
Copyright 2013 Rackspace
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
"""
|
|
from unittest import TestCase
|
|
|
|
from cafe.resources.rsyslog.client import RSyslogClient, MessageHandler
|
|
|
|
|
|
class TestSyslogClient(TestCase):
|
|
DEFAULT_SD_DICT = {
|
|
'meniscus': {
|
|
'token': 'test-token',
|
|
'tenant': 'test-tenant'
|
|
}
|
|
}
|
|
|
|
SAMPLE_SD_DICT = {
|
|
'origin': {
|
|
'software': 'cloudcafe-rsyslog'
|
|
}
|
|
}
|
|
|
|
def setUp(self):
|
|
self.client = RSyslogClient(default_sd=self.DEFAULT_SD_DICT)
|
|
self.client.connect()
|
|
|
|
def tearDown(self):
|
|
self.client.close()
|
|
|
|
def test_conversion_between_sd_dict_to_syslog_str(self):
|
|
result = MessageHandler.sd_dict_to_syslog_str(self.SAMPLE_SD_DICT)
|
|
self.assertEqual(result, '[origin software="cloudcafe-rsyslog"]')
|
|
|
|
def test_send_basic_message(self):
|
|
result = self.client.send(priority=1, msg='bam',
|
|
sd=self.SAMPLE_SD_DICT)
|
|
|
|
# A socket should return None if it was successful.
|
|
self.assertIsNone(result)
|