Skip to content

Commit

Permalink
fixed tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Oct 13, 2017
1 parent 050f288 commit 7ac3e7e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
6 changes: 3 additions & 3 deletions dogstatsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ class Reporter(threading.Thread):
"""

def __init__(self, interval, metrics_aggregator, api_host, api_key=None,
use_watchdog=False, event_chunk_size=None):
use_watchdog=False, event_chunk_size=None, hostname=None):
threading.Thread.__init__(self)
self.interval = int(interval)
self.finished = threading.Event()
self.metrics_aggregator = metrics_aggregator
self.flush_count = 0
self.log_count = 0
self.hostname = get_hostname()
self.hostname = hostname or get_hostname()

self.watchdog = None
if use_watchdog:
Expand Down Expand Up @@ -617,7 +617,7 @@ def init5(agent_config=None, use_watchdog=False, use_forwarder=False, args=None)
)

# Start the reporting thread.
reporter = Reporter(interval, aggregator, target, api_key, use_watchdog, event_chunk_size)
reporter = Reporter(interval, aggregator, target, api_key, use_watchdog, event_chunk_size, hostname)

# NOTICE: when `non_local_traffic` is passed we need to bind to any interface on the box. The forwarder uses
# Tornado which takes care of sockets creation (more than one socket can be used at once depending on the
Expand Down
8 changes: 4 additions & 4 deletions tests/core/fixtures/config/bad.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[Main]

# The host of the Datadog intake server to send agent data to
# The host of the Datadog intake server to send agent data to
dd_url: https://app.datadoghq.com

# The Datadog api key to associate your agent's data with your organization.
# Can be found here:
# The Datadog api key to associate your agent's data with your organization.
# Can be found here:
# https://app.datadoghq.com/account/settings
api_key: 1234
api_key: 0123456789abcdefghijklmnopqrstuv

# Force the hostname to whatever you want.
#hostname: mymachine.mydomain
Expand Down
2 changes: 1 addition & 1 deletion tests/core/fixtures/config/multiple_apikeys.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com
# The Datadog api key to associate your agent's data with your organization.
# Can be found here:
# https://app.datadoghq.com/account/settings
api_key: 1234, 5678 , 901
api_key: 0123456789abcdefghijklmnopqrstuv, 123456789abcdefghijklmnopqrstuv0 , 23456789abcdefghijklmnopqrstuv01
2 changes: 1 addition & 1 deletion tests/core/fixtures/config/multiple_endpoints.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com, https://app.example.com, https://app.example.
# The Datadog api key to associate your agent's data with your organization.
# Can be found here:
# https://app.datadoghq.com/account/settings
api_key: 1234,5678, 901
api_key: 0123456789abcdefghijklmnopqrstuv,123456789abcdefghijklmnopqrstuv0 , 23456789abcdefghijklmnopqrstuv01
2 changes: 1 addition & 1 deletion tests/core/fixtures/config/multiple_endpoints_bad.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com, https://app.example.com
# The Datadog api key to associate your agent's data with your organization.
# Can be found here:
# https://app.datadoghq.com/account/settings
api_key: 1234, 5678, 901
api_key: 0123456789abcdefghijklmnopqrstuv, 123456789abcdefghijklmnopqrstuv0 , 23456789abcdefghijklmnopqrstuv01
2 changes: 1 addition & 1 deletion tests/core/fixtures/config/one_endpoint.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dd_url: https://app.datadoghq.com
# The Datadog api key to associate your agent's data with your organization.
# Can be found here:
# https://app.datadoghq.com/account/settings
api_key: 1234
api_key: 0123456789abcdefghijklmnopqrstuv
16 changes: 8 additions & 8 deletions tests/core/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ def testWhiteSpaceConfig(self):
agentConfig = self.get_config('bad.conf')

self.assertEquals(agentConfig["dd_url"], "https://app.datadoghq.com")
self.assertEquals(agentConfig["api_key"], "1234")
self.assertEquals(agentConfig["api_key"], "0123456789abcdefghijklmnopqrstuv")
self.assertEquals(agentConfig["nagios_log"], "/var/log/nagios3/nagios.log")
self.assertEquals(agentConfig["graphite_listen_port"], 17126)
self.assertTrue("statsd_metric_namespace" in agentConfig)

def test_one_endpoint(self):
agent_config = self.get_config('one_endpoint.conf')
self.assertEquals(agent_config["dd_url"], "https://app.datadoghq.com")
self.assertEquals(agent_config["api_key"], "1234")
endpoints = {'https://app.datadoghq.com': ['1234']}
self.assertEquals(agent_config["api_key"], "0123456789abcdefghijklmnopqrstuv")
endpoints = {'https://app.datadoghq.com': ['0123456789abcdefghijklmnopqrstuv']}
self.assertEquals(agent_config['endpoints'], endpoints)

def test_multiple_endpoints(self):
agent_config = self.get_config('multiple_endpoints.conf')
self.assertEquals(agent_config["dd_url"], "https://app.datadoghq.com")
self.assertEquals(agent_config["api_key"], "1234")
self.assertEquals(agent_config["api_key"], "0123456789abcdefghijklmnopqrstuv")
endpoints = {
'https://app.datadoghq.com': ['1234'],
'https://app.example.com': ['5678', '901']
'https://app.datadoghq.com': ['0123456789abcdefghijklmnopqrstuv'],
'https://app.example.com': ['123456789abcdefghijklmnopqrstuv0', '23456789abcdefghijklmnopqrstuv01']
}
self.assertEquals(agent_config['endpoints'], endpoints)
with self.assertRaises(AssertionError):
Expand All @@ -69,9 +69,9 @@ def test_multiple_endpoints(self):
def test_multiple_apikeys(self):
agent_config = self.get_config('multiple_apikeys.conf')
self.assertEquals(agent_config["dd_url"], "https://app.datadoghq.com")
self.assertEquals(agent_config["api_key"], "1234")
self.assertEquals(agent_config["api_key"], "0123456789abcdefghijklmnopqrstuv")
endpoints = {
'https://app.datadoghq.com': ['1234', '5678', '901']
'https://app.datadoghq.com': ['0123456789abcdefghijklmnopqrstuv', '123456789abcdefghijklmnopqrstuv0', '23456789abcdefghijklmnopqrstuv01']
}
self.assertEquals(agent_config['endpoints'], endpoints)

Expand Down
6 changes: 5 additions & 1 deletion tests/core/test_dogstatsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_init5(self, s):
cfg = defaultdict(str)
cfg['non_local_traffic'] = True
cfg['use_dogstatsd'] = True
cfg['api_key'] = "0123456789abcdefghijklmnopqrstuv"
cfg['hostname'] = "hostname"

init5(cfg)

Expand All @@ -51,7 +53,7 @@ def test_init5(self, s):
@mock.patch('dogstatsd.get_config_path')
def test_init6(self, gcp):
cfg = defaultdict(str)
cfg['api_key'] = "deadbeeffeebdaed"
cfg['api_key'] = "0123456789abcdefghijklmnopqrstuv"
cfg['use_dogstatsd'] = True
cfg['dogstatsd6_enable'] = True
cfg['dogstatsd6_stats_port'] = 5050
Expand All @@ -67,6 +69,8 @@ def test_init_with_so_rcvbuf(self, s):
cfg = defaultdict(str)
cfg['use_dogstatsd'] = True
cfg['statsd_so_rcvbuf'] = '1024'
cfg['api_key'] = "0123456789abcdefghijklmnopqrstuv"
cfg['hostname'] = "hostname"

init5(cfg)

Expand Down

0 comments on commit 7ac3e7e

Please sign in to comment.