[Asterisk-code-review] StatsD: Write Testsuite tests (testsuite[master])

Tyler Cambron asteriskteam at digium.com
Tue Oct 6 15:11:06 CDT 2015


Tyler Cambron has uploaded a new change for review.

  https://gerrit.asterisk.org/1392

Change subject: StatsD: Write Testsuite tests
......................................................................

StatsD: Write Testsuite tests

Wrote the nominal and off-nominal tests that will use the StatsD
mock server to test the StatsD Dialplan application.

ASTERISK-25419
Reported By: Ashley Sanders

Change-Id: Id93dbeea53cf978461151e9002af2afe1029ce8b
---
A tests/apps/statsd/mockd.py
D tests/apps/statsd/nominal/mockd.py
M tests/apps/statsd/nominal/test-config.yaml
A tests/apps/statsd/off-nominal/empty_params/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/empty_params/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/empty_params/test-config.yaml
A tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/invalid_metric/test-config.yaml
A tests/apps/statsd/off-nominal/invalid_value/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/invalid_value/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/invalid_value/test-config.yaml
A tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/invalid_variable/test-config.yaml
A tests/apps/statsd/off-nominal/no_metric/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/no_metric/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/no_metric/test-config.yaml
A tests/apps/statsd/off-nominal/no_value/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/no_value/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/no_value/test-config.yaml
A tests/apps/statsd/off-nominal/no_variable/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/no_variable/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/no_variable/test-config.yaml
A tests/apps/statsd/off-nominal/server_unavail/configs/ast1/extensions.conf
A tests/apps/statsd/off-nominal/server_unavail/configs/ast1/statsd.conf
A tests/apps/statsd/off-nominal/server_unavail/test-config.yaml
A tests/apps/statsd/off-nominal/tests.yaml
M tests/apps/statsd/tests.yaml
29 files changed, 669 insertions(+), 100 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/92/1392/1

diff --git a/tests/apps/statsd/mockd.py b/tests/apps/statsd/mockd.py
new file mode 100644
index 0000000..50a65d2
--- /dev/null
+++ b/tests/apps/statsd/mockd.py
@@ -0,0 +1,153 @@
+'''
+Copyright (C) 2015, Digium, Inc.
+Tyler Cambron <tcambron at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import logging
+
+from twisted.internet.protocol import DatagramProtocol
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+sys.path.append("tests/apps/statsd")
+
+LOGGER = logging.getLogger(__name__)
+
+
+class MockDProtocol(DatagramProtocol):
+    '''Protocol for the Mock Server to use for receiving messages.
+    '''
+
+    def __init__(self, mockd_server):
+        '''Constructor.
+
+        Keyword Arguments:
+        mockd_server -- An instance of the mock StatsD server
+        '''
+        self.mockd_server = mockd_server
+
+    def datagramReceived(self, datagram, address):
+        '''AMI Newexten event handler
+
+        Keyword Arguments:
+        datagram -- The datagram that was received by the server
+        address -- The address that the datagram came from
+
+        Accept the datagram and send it to be checked against the config
+        '''
+        skip = 'stasis.message'
+        LOGGER.debug('Server received %s from %s' % (datagram, address))
+
+        if not skip in datagram:
+            self.mockd_server.message_received(datagram)
+
+
+class MockDServer(object):
+    '''Pluggable Module that acts as a mock StatsD server
+    '''
+
+    def __init__(self, config, test_object):
+        ''' Constructor
+
+        Keyword Arguments:
+        config -- This object's YAML derived configuration
+        test_object -- The test object it plugs onto
+        '''
+        self.config = config
+        self.test_object = test_object
+        self.packets = []
+        self.test_object.register_ami_observer(self.ami_connect)
+        self.test_object.register_stop_observer(self._stop_handler)
+        reactor.listenUDP(8080, MockDProtocol(self))
+
+    def ami_connect(self, ami):
+        '''Handles the AMI connect event.'''
+        ami.registerEvent('UserEvent', self._user_event_handler)
+
+    def check_message(self, message, is_user_event):
+        '''Checks a received message.
+
+        Keyword Arguments:
+        message -- The message to check.
+        is_user_event -- Whether or not the message was from a user event.
+        '''
+        is_correct = False
+        message_type = ""
+
+        if is_user_event:
+            message_type = 'UserEvent'
+            message = message['UserEvent']
+        else:
+            message_type = 'StatsDCommand'
+
+        for section in self.config:
+            print message
+            print section
+            print section[message_type]
+            if message in section[message_type]:
+                is_correct = True
+                break
+
+        if not is_correct:
+            LOGGER.debug('Packet not specified in configuration')
+        else:
+            LOGGER.debug('Test passed')
+
+            self.test_object.set_passed(is_correct)
+
+        return is_correct
+
+    def message_received(self, message):
+        '''Datagram message handler
+
+        Keyword Arguments:
+        message -- The datagram that was received by the server
+
+        Check the message against the config and pass the test if they match
+        '''
+        self.packets.append(message)
+
+        if self.check_message(message, False) is False:
+            self.test_object.stop_reactor()
+
+    def _user_event_handler(self, ami, event):
+        '''User Event handler
+
+    	Keyword Arguments:
+    	ami -- The ami instance that detected the user event
+    	event -- The user event that was detected
+
+    	Pass along a user event to check_message for validation
+    	'''
+        self.check_message(event, True)
+
+    def _stop_handler(self, result):
+        '''A deferred callback called as a result of the test stopping
+
+        Keyword Arguments:
+        result -- The deferred parameter passed from callback to callback
+        '''
+        LOGGER.info('Checking packets received')
+        if len(self.packets) != len(self.config):
+            LOGGER.error('Number of received packets {0} is not equal to the '
+                'number of configured packets {1}'.format(len(self.packets),
+                len(self.config)))
+            self.test_object.set_passed(False)
+            return
+
+        failed_matches = [(actual, expected) for actual, expected in
+            zip(self.packets, self.config) if actual != expected]
+
+        if len(failed_matches) != 0:
+            LOGGER.error('The following packets failed to match: {0}'
+                .format(failed_matches))
+            self.test_object.set_passed(False)
+            return
+
+        LOGGER.info('All packets matched')
+        self.test_object.set_passed(True)
+        LOGGER.debug('Test is stopping')
diff --git a/tests/apps/statsd/nominal/mockd.py b/tests/apps/statsd/nominal/mockd.py
deleted file mode 100644
index 354fae8..0000000
--- a/tests/apps/statsd/nominal/mockd.py
+++ /dev/null
@@ -1,97 +0,0 @@
-'''
-Copyright (C) 2015, Digium, Inc.
-Tyler Cambron <tcambron at digium.com>
-
-This program is free software, distributed under the terms of
-the GNU General Public License Version 2.
-'''
-
-import logging
-
-from twisted.internet.protocol import DatagramProtocol
-from twisted.internet import reactor
-
-LOGGER = logging.getLogger(__name__)
-
-
-class MockDProtocol(DatagramProtocol):
-    ''' Protocol for the Mock Server to use for receiving messages.
-    '''
-
-    def __init__(self, mockd_server):
-        ''' Constructor.
-
-        Keyword Arguments:
-        mockd_server -- An instance of the mock StatsD server
-        '''
-        self.mockd_server = mockd_server
-
-    def datagramReceived(self, datagram, address):
-        ''' AMI Newexten event handler
-
-        Keyword Arguments:
-        datagram -- The datagram that was received by the server
-        address -- The address that the datagram came from
-
-        Accept the datagram and send it to be checked against the config
-        '''
-        LOGGER.debug('Server received %s from %s' % (datagram, address))
-        self.mockd_server.message_received(datagram)
-
-
-class MockDServer(object):
-    ''' Pluggable Module that acts as a mock StatsD server
-    '''
-
-    def __init__(self, config, test_object):
-        ''' Constructor
-
-        Keyword Arguments:
-        config -- This object's YAML derived configuration
-        test_object -- The test object it plugs onto
-        '''
-        self.config = config
-        self.test_object = test_object
-        self.packets = []
-        self.test_object.register_stop_observer(self._stop_handler)
-        reactor.listenUDP(8080, MockDProtocol(self))
-
-    def message_received(self, message):
-        ''' Datagram message handler
-
-        Keyword Arguments:
-        message -- The datagram that was received by the server
-
-        Check the message against the config and pass the test if they match
-        '''
-        self.packets.append(message)
-
-        if len(self.packets) == len(self.config):
-            self.test_object.stop_reactor()
-
-    def _stop_handler(self, result):
-        ''' A deferred callback called as a result of the test stopping
-
-        Keyword Arguments:
-        result -- The deferred parameter passed from callback to callback
-        '''
-        LOGGER.info('Checking packets received')
-        if len(self.packets) != len(self.config):
-            LOGGER.error('Number of received packets {0} is not equal to the '
-                'number of configured packets {1}'.format(len(self.packets),
-                len(self.config)))
-            self.test_object.set_passed(False)
-            return
-
-        failed_matches = [(actual, expected) for actual, expected in
-            zip(self.packets, self.config) if actual != expected]
-
-        if len(failed_matches) != 0:
-            LOGGER.error('The following packets failed to match: {0}'
-                .format(failed_matches))
-            self.test_object.set_passed(False)
-            return
-
-        LOGGER.info('All packets matched')
-        self.test_object.set_passed(True)
-        LOGGER.debug('Test is stopping')
diff --git a/tests/apps/statsd/nominal/test-config.yaml b/tests/apps/statsd/nominal/test-config.yaml
index e4a851c..9243fc2 100644
--- a/tests/apps/statsd/nominal/test-config.yaml
+++ b/tests/apps/statsd/nominal/test-config.yaml
@@ -5,6 +5,7 @@
     description: |
         This test verifies that a user will be able to send statistics properly
         to StatsD through the StatsD Dialplan Application.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
 
 test-modules:
     add-test-to-search-path: 'True'
@@ -16,6 +17,9 @@
         -
             typename: 'mockd.MockDServer'
             config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
 
 test-object-config:
     asterisk-instances: 1
@@ -24,11 +28,21 @@
 
 statsd-config:
     -
-        'foo|val:2'
+        StatsDCommand: 'foo:1|g'
     -
-        'bar|val:1'
+        StatsDCommand: 'bar:2|s'
     -
-        'last|val:3'
+        StatsDCommand: 'baz:3|ms'
+    -
+        StatsDCommand: 'last:4|c'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
 
 properties:
     minversion: '13.5.0'
diff --git a/tests/apps/statsd/off-nominal/empty_params/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/empty_params/configs/ast1/extensions.conf
new file mode 100644
index 0000000..1bd8cab
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/empty_params/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD()
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/empty_params/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/empty_params/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/empty_params/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/empty_params/test-config.yaml b/tests/apps/statsd/off-nominal/empty_params/test-config.yaml
new file mode 100644
index 0000000..b337864
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/empty_params/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when no parameters are given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/extensions.conf
new file mode 100644
index 0000000..7d38fc6
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(bar,foo,2)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_metric/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_metric/test-config.yaml b/tests/apps/statsd/off-nominal/invalid_metric/test-config.yaml
new file mode 100644
index 0000000..684cb58
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_metric/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when an invalid metric type is given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_value/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/invalid_value/configs/ast1/extensions.conf
new file mode 100644
index 0000000..fee5f66
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_value/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(gauge,foo,*)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_value/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/invalid_value/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_value/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_value/test-config.yaml b/tests/apps/statsd/off-nominal/invalid_value/test-config.yaml
new file mode 100644
index 0000000..0ad4a6c
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_value/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when an invalid value is given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/extensions.conf
new file mode 100644
index 0000000..b667473
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(gauge,foo|,2)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_variable/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/invalid_variable/test-config.yaml b/tests/apps/statsd/off-nominal/invalid_variable/test-config.yaml
new file mode 100644
index 0000000..67edbb3
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/invalid_variable/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when an invalid variable name is given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_metric/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/no_metric/configs/ast1/extensions.conf
new file mode 100644
index 0000000..f3a10e8
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_metric/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(,foo,2)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_metric/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/no_metric/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_metric/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_metric/test-config.yaml b/tests/apps/statsd/off-nominal/no_metric/test-config.yaml
new file mode 100644
index 0000000..5079246
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_metric/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when a metric type is not given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_value/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/no_value/configs/ast1/extensions.conf
new file mode 100644
index 0000000..33e3ca3
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_value/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(gauge,foo,)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_value/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/no_value/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_value/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_value/test-config.yaml b/tests/apps/statsd/off-nominal/no_value/test-config.yaml
new file mode 100644
index 0000000..4060b07
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_value/test-config.yaml
@@ -0,0 +1,50 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when a value is not given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_variable/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/no_variable/configs/ast1/extensions.conf
new file mode 100644
index 0000000..ebf8c71
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_variable/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(gauge,,2)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_variable/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/no_variable/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_variable/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/no_variable/test-config.yaml b/tests/apps/statsd/off-nominal/no_variable/test-config.yaml
new file mode 100644
index 0000000..5d228a9
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/no_variable/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will fail
+        appropriately when a variable name is not given.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'InvalidParams'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/server_unavail/configs/ast1/extensions.conf b/tests/apps/statsd/off-nominal/server_unavail/configs/ast1/extensions.conf
new file mode 100644
index 0000000..b306288
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/server_unavail/configs/ast1/extensions.conf
@@ -0,0 +1,4 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,StatsD(gauge,foo,2)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/server_unavail/configs/ast1/statsd.conf b/tests/apps/statsd/off-nominal/server_unavail/configs/ast1/statsd.conf
new file mode 100644
index 0000000..6a93b1a
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/server_unavail/configs/ast1/statsd.conf
@@ -0,0 +1,8 @@
+[general]
+enabled = yes			; When set to yes, statsd support is enabled
+server = 127.0.0.1:8080	; server[:port] of statsd server to use.
+						; If not specified, the port is 8125
+;prefix =				; Prefix to prepend to all metrics
+;add_newline = no		; Append a newline to every event. This is
+						; useful if you want to run a fake statsd
+						; server using netcat (nc -lu 8125)
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/server_unavail/test-config.yaml b/tests/apps/statsd/off-nominal/server_unavail/test-config.yaml
new file mode 100644
index 0000000..ab4f0cc
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/server_unavail/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary:  |
+        Test sending statistics to a StatsD server for the StatsD Dialplan
+        Application
+    description: |
+        This test verifies that the StatsD Dialplan Application will have the
+        correct response when the StatsD server is unavailable.
+    skip: 'Skip while Asterisk StatsD Dialplan Application is being built.'
+
+test-modules:
+    add-test-to-search-path: 'True'
+    add-relative-to-search-path: ['../..']
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'mockd.MockDServer'
+            config-section: 'statsd-config'
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: 'originator-config'
+
+test-object-config:
+    asterisk-instances: 1
+    connect-ami: True
+    reactor-timeout: 15
+
+statsd-config:
+    -
+        UserEvent: 'ServerUnavailable'
+
+originator-config:
+    channel: 'Local/start at default'
+    context: default
+    exten: start
+    priority: 1
+    trigger: 'ami_connect'
+    async: True
+
+properties:
+    minversion: '13.5.0'
+    dependencies:
+        - python: 'autobahn.websocket'
+        - python: 'starpy'
+        - python: 'twisted'
+    tags:
+        - statsd
+        - apps
\ No newline at end of file
diff --git a/tests/apps/statsd/off-nominal/tests.yaml b/tests/apps/statsd/off-nominal/tests.yaml
new file mode 100644
index 0000000..c6f9214
--- /dev/null
+++ b/tests/apps/statsd/off-nominal/tests.yaml
@@ -0,0 +1,9 @@
+tests:
+    - test: 'empty_params'
+    - test: 'invalid_metric'
+    - test: 'invalid_value'
+    - test: 'invalid_variable'
+    - test: 'no_metric'
+    - test: 'no_value'
+    - test: 'no_variable'
+    - test: 'server_unavail'
diff --git a/tests/apps/statsd/tests.yaml b/tests/apps/statsd/tests.yaml
index d39f00d..abdef6c 100644
--- a/tests/apps/statsd/tests.yaml
+++ b/tests/apps/statsd/tests.yaml
@@ -1,3 +1,4 @@
 # Enter tests here in the order they should be considered for execution:
 tests:
     - test: 'nominal'
+    - dir: 'off-nominal'

-- 
To view, visit https://gerrit.asterisk.org/1392
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id93dbeea53cf978461151e9002af2afe1029ce8b
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Tyler Cambron <tcambron at digium.com>



More information about the asterisk-code-review mailing list