datadog-sdk-testing 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c74227db510a81eea5631e7c0662c75877555dc3
4
+ data.tar.gz: ae7bd7b68c6ad64cc41b09d587495ae3be1a26c0
5
+ SHA512:
6
+ metadata.gz: 174b4496355eef80152159b344a655476e78cf6207018b0ea0aa9c49e1360afcf9709833bdb3bc43daab35e59dd76f0474aff1be3df0b1f950b34b92b3a7c947
7
+ data.tar.gz: 3bd3194d905f302cb0609ee35fc0c47e1c1df2db1429376b0c335bf713607b0fd7d60d22e6a61df2c14fedcfa7a27bec4072d1bd90b8d371504def0b0a86057f
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2015, Datadog <info@datadoghq.com>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of Datadog nor the
12
+ names of its contributors may be used to endorse or promote products
13
+ derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,30 @@
1
+ # datadog-sdk-testing
2
+ Gem repo providing Integration SDK testing/scaffolding facilities (unpublished).
3
+
4
+ ## usage
5
+ This gem essentially just provides a set of rake tasks to help you get up and running with integration testing and scaffolding. We expect to use this gem in `integrations-core` and `integrations-extras`.
6
+
7
+ To use the tasks in this gem just add a Rakefile to the relevant project with these contents:
8
+
9
+ ```
10
+ #!/usr/bin/env rake
11
+
12
+ require 'rake'
13
+
14
+ unless ENV['CI']
15
+ rakefile_dir = File.dirname(__FILE__)
16
+ ENV['TRAVIS_BUILD_DIR'] = rakefile_dir
17
+ ENV['INTEGRATIONS_DIR'] = File.join(rakefile_dir, 'embedded')
18
+ ENV['PIP_CACHE'] = File.join(rakefile_dir, '.cache/pip')
19
+ ENV['VOLATILE_DIR'] = '/tmp/integration-sdk-testing'
20
+ ENV['CONCURRENCY'] = ENV['CONCURRENCY'] || '2'
21
+ ENV['NOSE_FILTER'] = 'not windows'
22
+ ENV['RUN_VENV'] = 'true'
23
+ ENV['SDK_TESTING'] = 'true'
24
+ end
25
+
26
+ ENV['SDK_HOME'] = File.dirname(__FILE__)
27
+
28
+ spec = Gem::Specification.find_by_name 'datadog-sdk-testing'
29
+ load "#{spec.gem_dir}/lib/tasks/sdk.rake"
30
+ ```
@@ -0,0 +1,32 @@
1
+ # Skeleton Integration
2
+
3
+ ## Overview
4
+
5
+ Get metrics from skeleton service in real time to:
6
+
7
+ * Visualize and monitor skeleton states
8
+ * Be notified about skeleton failovers and events.
9
+
10
+ ## Installation
11
+
12
+ Install the `dd-check-skeleton` package manually or with your favorite configuration manager
13
+
14
+ ## Configuration
15
+
16
+ Edit the `skeleton.yaml` file to point to your server and port, set the masters to monitor
17
+
18
+ ## Validation
19
+
20
+ When you run `datadog-agent info` you should see something like the following:
21
+
22
+ Checks
23
+ ======
24
+
25
+ skeleton
26
+ -----------
27
+ - instance #0 [OK]
28
+ - Collected 39 metrics, 0 events & 7 service checks
29
+
30
+ ## Compatibility
31
+
32
+ The skeleton check is compatible with all major platforms
@@ -0,0 +1,17 @@
1
+ # stdlib
2
+
3
+ # 3rd party
4
+
5
+ # project
6
+ from checks import AgentCheck
7
+
8
+ EVENT_TYPE = SOURCE_TYPE_NAME = 'skeleton'
9
+
10
+
11
+ class SkeletonCheck(AgentCheck):
12
+
13
+ def __init__(self, name, init_config, agentConfig, instances=None):
14
+ AgentCheck.__init__(self, name, init_config, agentConfig, instances)
15
+
16
+ def check(self, instance):
17
+ pass
@@ -0,0 +1,69 @@
1
+ require 'ci/common'
2
+
3
+ def skeleton_version
4
+ ENV['FLAVOR_VERSION'] || '2.4.12'
5
+ end
6
+
7
+ def skeleton_rootdir
8
+ "#{ENV['INTEGRATIONS_DIR']}/skeleton_#{skeleton_version}"
9
+ end
10
+
11
+ namespace :ci do
12
+ namespace :skeleton do |flavor|
13
+ task before_install: ['ci:common:before_install']
14
+
15
+ task install: ['ci:common:install'] do
16
+ use_venv = in_venv
17
+ install_requirements('skeleton/requirements.txt',
18
+ "--cache-dir #{ENV['PIP_CACHE']}",
19
+ "#{ENV['VOLATILE_DIR']}/ci.log", use_venv)
20
+ # sample docker usage
21
+ # sh %(docker create -p XXX:YYY --name skeleton source/skeleton)
22
+ # sh %(docker start skeleton)
23
+ end
24
+
25
+ task before_script: ['ci:common:before_script']
26
+
27
+ task :script, [:mocked] => ['ci:common:script'] do |_, attr|
28
+ ci_home = File.dirname(__FILE__)
29
+ mocked = attr[:mocked] || false
30
+ this_provides = [
31
+ 'skeleton'
32
+ ]
33
+ Rake::Task['ci:common:run_tests'].invoke(this_provides, ci_home, mocked)
34
+ end
35
+
36
+ task before_cache: ['ci:common:before_cache']
37
+
38
+ task cleanup: ['ci:common:cleanup']
39
+ # sample cleanup task
40
+ # task cleanup: ['ci:common:cleanup'] do
41
+ # sh %(docker stop skeleton)
42
+ # sh %(docker rm skeleton)
43
+ # end
44
+
45
+ task :execute, :mocked do |_, attr|
46
+ mocked = attr[:mocked] || false
47
+ exception = nil
48
+ begin
49
+ if not mocked
50
+ %w(before_install install before_script).each do |u|
51
+ Rake::Task["#{flavor.scope.path}:#{u}"].invoke
52
+ end
53
+ end
54
+ Rake::Task["#{flavor.scope.path}:script"].invoke(mocked)
55
+ Rake::Task["#{flavor.scope.path}:before_cache"].invoke
56
+ rescue => e
57
+ exception = e
58
+ puts "Failed task: #{e.class} #{e.message}".red
59
+ end
60
+ if ENV['SKIP_CLEANUP']
61
+ puts 'Skipping cleanup, disposable environments are great'.yellow
62
+ else
63
+ puts 'Cleaning up'
64
+ Rake::Task["#{flavor.scope.path}:cleanup"].invoke
65
+ end
66
+ raise exception if exception
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ init_config:
2
+
3
+ instances:
4
+ - host: localhost
5
+ port: 26379
6
+ tags: ['custom:tag']
@@ -0,0 +1,10 @@
1
+ {
2
+ "maintainer": "help@datadoghq.com",
3
+ "manifest_version": "0.1.0",
4
+ "max_agent_version": "6.0.0",
5
+ "min_agent_version": "5.6.3",
6
+ "name": "skeleton",
7
+ "short_description": "skeleton description.",
8
+ "support": "contrib",
9
+ "version": "0.1.0"
10
+ }
File without changes
@@ -0,0 +1 @@
1
+ # integration pip requirements
@@ -0,0 +1,34 @@
1
+ # stdlib
2
+ from nose.plugins.attrib import attr
3
+
4
+ # 3p
5
+
6
+ # project
7
+ from tests.checks.common import AgentCheckTest
8
+
9
+
10
+ instance = {
11
+ 'host': 'localhost',
12
+ 'port': 26379,
13
+ 'password': 'datadog-is-devops-best-friend'
14
+ }
15
+
16
+
17
+ # NOTE: Feel free to declare multiple test classes if needed
18
+
19
+ @attr(requires='skeleton', mock=False) # set mock to True if appropriate
20
+ class TestSkeleton(AgentCheckTest):
21
+ """Basic Test for skeleton integration."""
22
+ CHECK_NAME = 'skeleton'
23
+
24
+ def test_check(self):
25
+ """
26
+ Testing Skeleton check.
27
+ """
28
+ self.load_check({}, {})
29
+
30
+ # run your actual tests...
31
+
32
+ self.assertTrue(True)
33
+ # Raises when COVERAGE=true and coverage < 100%
34
+ self.coverage_report()
@@ -0,0 +1,215 @@
1
+ require 'colorize'
2
+ require 'httparty'
3
+ require 'socket'
4
+ require 'time'
5
+ require 'timeout'
6
+
7
+ # Colors don't work on Appveyor
8
+ String.disable_colorization = true if Gem.win_platform?
9
+
10
+
11
+ def check_env
12
+ abort 'SDK_HOME env variable must be defined in your Rakefile to used this gem.' unless ENV['SDK_HOME']
13
+ end
14
+
15
+ def sleep_for(secs)
16
+ puts "Sleeping for #{secs}s".blue
17
+ sleep(secs)
18
+ end
19
+
20
+ def section(name)
21
+ timestamp = Time.now.utc.iso8601
22
+ puts ''
23
+ puts "[#{timestamp}] >>>>>>>>>>>>>> #{name} STAGE".black.on_white
24
+ puts ''
25
+ end
26
+
27
+ def in_venv
28
+ ENV['RUN_VENV'] && ENV['RUN_VENV'] == 'true' ? true : false
29
+ end
30
+
31
+ def install_requirements(req_file, pip_options = nil, output = nil, use_venv = nil)
32
+ pip_command = use_venv ? "#{ENV['SDK_HOME']}/venv/bin/pip" : 'pip'
33
+ redirect_output = output ? "2>&1 >> #{output}" : ''
34
+ pip_options = '' if pip_options.nil?
35
+ File.exist?(req_file) && File.open(req_file, 'r') do |f|
36
+ f.each_line do |line|
37
+ line.strip!
38
+ unless line.empty? || line.start_with?('#')
39
+ sh %(#{pip_command} install #{line} #{pip_options} #{redirect_output}\
40
+ || echo 'Unable to install #{line}' #{redirect_output})
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_files(sdk_dir)
47
+ Dir.glob(File.join(sdk_dir, '**/test_*.py')).reject do |path|
48
+ !%r{#{sdk_dir}/embedded/.*$}.match(path).nil? || !%r{#{sdk_dir}\/venv\/.*$}.match(path).nil?
49
+ end
50
+ end
51
+
52
+ def integration_tests(ci_dir)
53
+ sdk_dir = File.join(ci_dir, '..')
54
+ integrations = []
55
+ untested = []
56
+ testable = []
57
+ test_files(sdk_dir).each do |check|
58
+ integration_name = /test_((\w|_)+).py$/.match(check)[1]
59
+ integrations.push(integration_name)
60
+ if Dir.exist?(File.join(sdk_dir, integration_name))
61
+ testable.push(check)
62
+ else
63
+ untested.push(check)
64
+ end
65
+ end
66
+ [testable, untested]
67
+ end
68
+
69
+ # helper class to wait for TCP/HTTP services to boot
70
+ class Wait
71
+ DEFAULT_TIMEOUT = 10
72
+
73
+ def self.check_port(port)
74
+ Timeout.timeout(0.5) do
75
+ begin
76
+ s = TCPSocket.new('localhost', port)
77
+ s.close
78
+ return true
79
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
80
+ return false
81
+ end
82
+ end
83
+ rescue Timeout::Error
84
+ return false
85
+ end
86
+
87
+ def self.check_url(url)
88
+ Timeout.timeout(0.5) do
89
+ begin
90
+ r = HTTParty.get(url)
91
+ return (200...300).cover? r.code
92
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
93
+ return false
94
+ end
95
+ end
96
+ rescue Timeout::Error
97
+ return false
98
+ end
99
+
100
+ def self.check_file(file_path)
101
+ File.exist?(file_path)
102
+ end
103
+
104
+ def self.check(smth)
105
+ if smth.is_a? Integer
106
+ check_port smth
107
+ elsif smth.include? 'http'
108
+ check_url smth
109
+ else
110
+ check_file smth
111
+ end
112
+ end
113
+
114
+ def self.for(smth, max_timeout = DEFAULT_TIMEOUT)
115
+ start_time = Time.now
116
+ status = false
117
+ n = 1
118
+ puts "Trying #{smth}"
119
+ loop do
120
+ puts n.to_s
121
+ status = check(smth)
122
+ break if status || Time.now > start_time + max_timeout
123
+ n += 1
124
+ sleep 0.25
125
+ end
126
+ raise "Still not up after #{max_timeout}s" unless status
127
+ puts 'Found!'
128
+ status
129
+ end
130
+ end
131
+
132
+ namespace :ci do
133
+ namespace :common do
134
+ task :before_install do |t|
135
+ section('BEFORE_INSTALL')
136
+ # We use tempdir on Windows, no need to create it
137
+ sh %(mkdir -p #{ENV['VOLATILE_DIR']}) unless Gem.win_platform?
138
+ t.reenable
139
+ end
140
+
141
+ task :install do |t|
142
+ section('INSTALL')
143
+ use_venv = in_venv
144
+ pip_command = use_venv ? 'venv/bin/pip' : 'pip'
145
+ sh %(#{'python -m ' if Gem.win_platform?}#{pip_command} install --upgrade pip setuptools)
146
+ install_requirements('requirements.txt',
147
+ "--cache-dir #{ENV['PIP_CACHE']}",
148
+ "#{ENV['VOLATILE_DIR']}/ci.log", use_venv)
149
+ install_requirements('requirements-opt.txt',
150
+ "--upgrade --cache-dir #{ENV['PIP_CACHE']}",
151
+ "#{ENV['VOLATILE_DIR']}/ci.log", use_venv)
152
+ install_requirements('requirements-test.txt',
153
+ "--cache-dir #{ENV['PIP_CACHE']}",
154
+ "#{ENV['VOLATILE_DIR']}/ci.log", use_venv)
155
+ t.reenable
156
+ end
157
+
158
+ task :before_script do |t|
159
+ section('BEFORE_SCRIPT')
160
+ t.reenable
161
+ end
162
+
163
+ task :script do |t|
164
+ section('SCRIPT')
165
+ t.reenable
166
+ end
167
+
168
+ task :before_cache do |t|
169
+ section('BEFORE_CACHE')
170
+ t.reenable
171
+ end
172
+
173
+ task :cleanup do |t|
174
+ section('CLEANUP')
175
+ t.reenable
176
+ end
177
+
178
+ task :run_tests, [:flavor, :cihome, :mocked] do |t, attr|
179
+ flavors = attr[:flavor]
180
+ cihome = attr[:cihome]
181
+ mocked = attr[:mocked] || false
182
+ filter = ENV['NOSE_FILTER'] || '1'
183
+ nose_command = in_venv ? 'venv/bin/nosetests' : 'nosetests'
184
+
185
+ mock_filter = mocked ? "mock" : "not mock"
186
+ nose = if flavors.include?('default')
187
+ "(not requires) and #{filter} and #{mock_filter}"
188
+ else
189
+ "(requires in ['#{flavors.join("','")}']) and #{filter} and #{mock_filter}"
190
+ end
191
+
192
+ tests_directory, = integration_tests(cihome)
193
+ unless flavors.include?('default')
194
+ tests_directory = tests_directory.reject do |test|
195
+ /.*#{flavors}.*$/.match(test).nil?
196
+ end
197
+ end
198
+ # Rake on Windows doesn't support setting the var at the beginning of the
199
+ # command
200
+ path = ''
201
+ unless Gem.win_platform?
202
+ # FIXME: make the other filters than param configurable
203
+ # For integrations that cannot be easily installed in a
204
+ # separate dir we symlink stuff in the rootdir
205
+ path = %(PATH="#{ENV['INTEGRATIONS_DIR']}/bin:#{ENV['PATH']}" )
206
+ end
207
+ tests_directory.each do |testdir|
208
+ sh %(#{path}#{nose_command} -s -v -A "#{nose}" #{testdir})
209
+ end
210
+ t.reenable
211
+ end
212
+
213
+ task execute: [:before_install, :install, :before_script, :script]
214
+ end
215
+ end
@@ -0,0 +1,67 @@
1
+ require 'rake'
2
+
3
+ require 'ci/common'
4
+ require 'bundler'
5
+
6
+ namespace :ci do
7
+ namespace :default do |flavor|
8
+ task before_install: ['ci:common:before_install']
9
+
10
+ task :coverage do
11
+ check_env
12
+ testable, untested = integration_tests(File.dirname(__FILE__))
13
+ total_checks = (untested + testable).length
14
+ unless untested.empty?
15
+ puts "Untested checks (#{untested.length}/#{total_checks})".red
16
+ puts '-----------------------'.red
17
+ untested.each { |check_name| puts check_name.red }
18
+ puts ''
19
+ end
20
+ end
21
+
22
+ task install: ['ci:common:install']
23
+
24
+ task before_script: ['ci:common:before_script']
25
+
26
+ task lint: ['rubocop'] do
27
+ check_env
28
+ sh %(flake8 #{ENV['SDK_HOME']})
29
+ sh %(find #{ENV['SDK_HOME']} -name '*.py' -not\
30
+ \\( -path '*.cache*' -or -path '*embedded*' -or -path '*venv*' -or -path '*.git*' \\)\
31
+ | xargs -n 1 pylint --rcfile=#{ENV['SDK_HOME']}/.pylintrc)
32
+ end
33
+
34
+ task :requirements do
35
+ check_env
36
+ gem_home = Bundler.rubygems.find_name('datadog-sdk-testing').first.full_gem_path
37
+ sh "#{gem_home}/lib/tasks/ci/hooks/pre-commit.py"
38
+ end
39
+
40
+ task script: ['ci:common:script', :coverage, :lint] do
41
+ check_env
42
+ Rake::Task['ci:common:run_tests'].invoke(['default'])
43
+ end
44
+
45
+ task cleanup: ['ci:common:cleanup']
46
+
47
+ task :execute do
48
+ exception = nil
49
+ begin
50
+ %w(before_install install before_script
51
+ script).each do |t|
52
+ Rake::Task["#{flavor.scope.path}:#{t}"].invoke
53
+ end
54
+ rescue => e
55
+ exception = e
56
+ puts "Failed task: #{e.class} #{e.message}".red
57
+ end
58
+ if ENV['SKIP_CLEANUP']
59
+ puts 'Skipping cleanup, disposable environments are great'.yellow
60
+ else
61
+ puts 'Cleaning up'
62
+ Rake::Task["#{flavor.scope.path}:cleanup"].invoke
63
+ end
64
+ raise exception if exception
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python
2
+
3
+ import fnmatch
4
+ import os
5
+ import sys
6
+
7
+ OK = 0
8
+ ERR = 1
9
+
10
+ def get_files(fname):
11
+ matches = []
12
+ for root, dirnames, filenames in os.walk('.'):
13
+ for filename in fnmatch.filter(filenames, fname):
14
+ matches.append(os.path.join(root, filename))
15
+
16
+ return matches
17
+
18
+
19
+ def process_requirements(reqs, fname):
20
+ SPECIFIERS = ['==', '!=' '<=', '>=', '<', '>']
21
+
22
+ print "processing... {}".format(fname)
23
+ with open(fname) as f:
24
+ content = f.readlines()
25
+
26
+ for line in content:
27
+ line = "".join(line.split())
28
+ for specifier in SPECIFIERS:
29
+ idx = line.find(specifier)
30
+ if idx < 0:
31
+ continue
32
+
33
+ req = line[:idx]
34
+ specifier = line[idx:]
35
+
36
+ if req in reqs and reqs[req][0] != specifier:
37
+ # version mismatch
38
+ print "There's a version mismatch with {req} " \
39
+ " {spec} and {prev_spec} defined in {src}.".format(
40
+ req=req,
41
+ spec=specifier,
42
+ prev_spec=reqs[req][0],
43
+ src=reqs[req][1]
44
+ )
45
+ sys.exit(ERR)
46
+ elif req not in reqs:
47
+ reqs[req] = (specifier, fname)
48
+ break
49
+
50
+
51
+ requirements = {}
52
+ files = get_files('requirements.txt')
53
+
54
+ for f in files:
55
+ process_requirements(requirements, f)
56
+
57
+ print "No requirement version conflicts found. Looking good... ;)"
58
+ for req, spec in requirements.iteritems():
59
+ print "{req}{spec} first found in {fname}".format(
60
+ req=req,
61
+ spec=spec[0],
62
+ fname=spec[1]
63
+ )
64
+
65
+ sys.exit(OK)
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env rake
2
+ # encoding: utf-8
3
+ # 3p
4
+ require 'rake/clean'
5
+ require 'rubocop/rake_task'
6
+ require 'bundler'
7
+
8
+ # Flavored Travis CI jobs
9
+ require 'ci/default'
10
+ Rake.add_rakelib './ci/'
11
+
12
+ CLOBBER.include '**/*.pyc'
13
+
14
+ desc 'Setup a development environment for the SDK'
15
+ task 'setup_env' do
16
+ check_env
17
+ `mkdir -p #{ENV['SDK_HOME']}/venv`
18
+ `wget -q -O #{ENV['SDK_HOME']}/venv/virtualenv.py https://raw.github.com/pypa/virtualenv/1.11.6/virtualenv.py`
19
+ `python #{ENV['SDK_HOME']}/venv/virtualenv.py --no-site-packages --no-pip --no-setuptools #{ENV['SDK_HOME']}/venv/`
20
+ `wget -q -O #{ENV['SDK_HOME']}/venv/ez_setup.py https://bootstrap.pypa.io/ez_setup.py`
21
+ `#{ENV['SDK_HOME']}/venv/bin/python #{ENV['SDK_HOME']}/venv/ez_setup.py`
22
+ `wget -q -O #{ENV['SDK_HOME']}/venv/get-pip.py https://bootstrap.pypa.io/get-pip.py`
23
+ `#{ENV['SDK_HOME']}/venv/bin/python #{ENV['SDK_HOME']}/venv/get-pip.py`
24
+ # these files should be part of the SDK repos (integrations-{core, extra}
25
+ `venv/bin/pip install -r #{ENV['SDK_HOME']}/requirements.txt` if File.exist?('requirements.txt')
26
+ `venv/bin/pip install -r #{ENV['SDK_HOME']}/requirements-test.txt` if File.exist?('requirements-test.txt')
27
+ # These deps are not really needed, so we ignore failures
28
+ ENV['PIP_COMMAND'] = "#{ENV['SDK_HOME']}/venv/bin/pip"
29
+ `git clone https://github.com/DataDog/dd-agent.git #{ENV['SDK_HOME']}/embedded/dd-agent`
30
+ # install agent core dependencies
31
+ `#{ENV['SDK_HOME']}/venv/bin/pip install -r #{ENV['SDK_HOME']}/embedded/dd-agent/requirements.txt`
32
+ `echo "#{ENV['SDK_HOME']}/embedded/dd-agent/" > #{ENV['SDK_HOME']}/venv/lib/python2.7/site-packages/datadog-agent.pth`
33
+ end
34
+
35
+ desc 'Clean development environment for the SDK (remove!)'
36
+ task 'clean_env' do
37
+ check_env
38
+ input = ''
39
+ print "Are you sure you want to delete the SDK environment (y/n)? "
40
+ input = STDIN.gets.chomp
41
+ case input.upcase
42
+ when "Y"
43
+ `rm -rf #{ENV['SDK_HOME']}/venv` if File.directory?("#{ENV['SDK_HOME']}/venv")
44
+ `rm -rf #{ENV['SDK_HOME']}/embedded` if File.directory?("#{ENV['SDK_HOME']}/embedded")
45
+ puts "virtual environment, agent source removed."
46
+ when "N"
47
+ puts "aborting the task..."
48
+ end
49
+ end
50
+
51
+ desc 'Setup git hooks'
52
+ task 'setup_hooks' do
53
+ check_env
54
+ gem_home = Bundler.rubygems.find_name('datadog-sdk-testing').first.full_gem_path
55
+ sh "ln -sf #{gem_home}/lib/tasks/ci/hooks/pre-commit.py #{ENV['SDK_HOME']}}/.git/hooks/pre-commit"
56
+ end
57
+
58
+ desc 'Pull latest agent code'
59
+ task 'pull_latest_agent' do
60
+ check_env
61
+ `cd #{ENV['SDK_HOME']}/embedded/dd-agent && git fetch -p && git pull && cd -`
62
+ end
63
+
64
+ namespace :test do
65
+ desc 'cProfile tests, then run pstats'
66
+ task 'profile:pstats' => ['test:profile'] do
67
+ check_env
68
+ sh 'python -m pstats stats.dat'
69
+ end
70
+
71
+ desc 'Display test coverage for checks'
72
+ task 'coverage' => 'ci:default:coverage'
73
+ end
74
+
75
+ RuboCop::RakeTask.new(:rubocop) do |t|
76
+ t.patterns = ['ci/**/*.rb', 'Gemfile', 'Rakefile']
77
+ end
78
+
79
+ desc 'Lint the code through pylint'
80
+ task 'lint' => ['ci:default:lint'] do
81
+ end
82
+
83
+ desc 'Find requirements conflicts'
84
+ task 'requirements' => ['ci:default:requirements'] do
85
+ end
86
+
87
+ namespace :generate do
88
+ desc 'Setup a development environment for the SDK'
89
+ task :skeleton, :option do |_, args|
90
+ check_env
91
+ puts "generating skeleton files for #{args[:option]}"
92
+ gem_home = Bundler.rubygems.find_name('datadog-sdk-testing').first.full_gem_path
93
+ capitalized = args[:option].capitalize
94
+ sh "mkdir -p #{ENV['SDK_HOME']}/ci"
95
+ sh "mkdir -p #{ENV['SDK_HOME']}/#{args[:option]}"
96
+ sh "cp #{gem_home}/lib/config/ci/skeleton.rake #{ENV['SDK_HOME']}/ci/#{args[:option]}.rake"
97
+ sh "cp #{gem_home}/lib/config/manifest.json #{ENV['SDK_HOME']}/#{args[:option]}/manifest.json"
98
+ sh "cp #{gem_home}/lib/config/check.py #{ENV['SDK_HOME']}/#{args[:option]}/check.py"
99
+ sh "cp #{gem_home}/lib/config/test_skeleton.py #{ENV['SDK_HOME']}/#{args[:option]}/test_#{args[:option]}.py"
100
+ sh "cp #{gem_home}/lib/config/metadata.csv #{ENV['SDK_HOME']}/#{args[:option]}/metadata.csv"
101
+ sh "cp #{gem_home}/lib/config/requirements.txt #{ENV['SDK_HOME']}/#{args[:option]}/requirements.txt"
102
+ sh "cp #{gem_home}/lib/config/README.md #{ENV['SDK_HOME']}/#{args[:option]}/README.md"
103
+ sh "find #{ENV['SDK_HOME']}/#{args[:option]} -type f -exec sed -i '' \"s/skeleton/#{args[:option]}/g\" {} \\;"
104
+ sh "find #{ENV['SDK_HOME']}/#{args[:option]} -type f -exec sed -i '' \"s/Skeleton/#{capitalized}/g\" {} \\;"
105
+ sh "sed -i '' \"s/skeleton/#{args[:option]}/g\" #{ENV['SDK_HOME']}/ci/#{args[:option]}.rake"
106
+ sh "sed -i '' \"s/Skeleton/#{capitalized}/g\" #{ENV['SDK_HOME']}/ci/#{args[:option]}.rake"
107
+ sh "git add #{ENV['SDK_HOME']}/ci/#{args[:option]}.rake"
108
+ sh "git add #{ENV['SDK_HOME']}/#{args[:option]}/*"
109
+
110
+ new_file = "#{ENV['SDK_HOME']}/circle.yml.new"
111
+ File.open(new_file, 'w') do |fo|
112
+ File.foreach("#{ENV['SDK_HOME']}/circle.yml") do |line|
113
+ fo.puts " - rake ci:run[#{args[:option]}]" if line =~ /bundle\ exec\ rake\ requirements/
114
+ fo.puts line
115
+ end
116
+ end
117
+ File.delete("#{ENV['SDK_HOME']}/circle.yml")
118
+ File.rename(new_file, "#{ENV['SDK_HOME']}/circle.yml")
119
+
120
+ new_file = "#{ENV['SDK_HOME']}/.travis.yml.new"
121
+ File.open(new_file, 'w') do |fo|
122
+ File.foreach("#{ENV['SDK_HOME']}/.travis.yml") do |line|
123
+ fo.puts " - rake ci:run[#{args[:option]}]" if line =~ /bundle\ exec\ rake\ requirements/
124
+ fo.puts line
125
+ end
126
+ end
127
+ File.delete("#{ENV['SDK_HOME']}/.travis.yml")
128
+ File.rename(new_file, "#{ENV['SDK_HOME']}/.travis.yml")
129
+ end
130
+ end
131
+
132
+ namespace :ci do
133
+ desc 'Run integration tests'
134
+ task :run, [:flavor, :mocked] do |_, args|
135
+ check_env
136
+ puts 'Assuming you are running these tests locally' unless ENV['TRAVIS']
137
+ flavor = args[:flavor] || ENV['TRAVIS_FLAVOR'] || 'default'
138
+ mocked = args[:mocked] || false
139
+ flavors = flavor.split(',')
140
+ flavors.each do |f|
141
+ Rake::Task["ci:#{f}:execute"].invoke(mocked)
142
+ end
143
+ end
144
+
145
+ desc 'Run mock tests'
146
+ task :run_mocks, [:flavor] do |_, args|
147
+ check_env
148
+ Rake::Task["ci:run"].invoke(args[:flavor], true)
149
+ end
150
+ end
151
+
152
+ task default: ['lint', 'ci:run']
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datadog-sdk-testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jaime Fullaondo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Datadog Integration SDK testing/scaffolding gem
14
+ email: jaime.fullaondo@datadoghq.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/config/README.md
22
+ - lib/config/check.py
23
+ - lib/config/ci/skeleton.rake
24
+ - lib/config/conf.yaml.example
25
+ - lib/config/manifest.json
26
+ - lib/config/metadata.csv
27
+ - lib/config/requirements.txt
28
+ - lib/config/test_skeleton.py
29
+ - lib/tasks/ci/common.rb
30
+ - lib/tasks/ci/default.rb
31
+ - lib/tasks/ci/hooks/pre-commit.py
32
+ - lib/tasks/sdk.rake
33
+ homepage: http://rubygems.org/gems/datadog-sdk-testing
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib/tasks/
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.4.6
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Datadog Integration SDK testing/scaffolding facilities.
57
+ test_files: []