diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0e37f194d..ad37267dc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,8 +27,6 @@ # automatically load any shared examples or contexts Dir['./spec/support/**/*.rb'].sort.each { |f| require f } -analytics_config = nil - FIXTURES_DIR = File.join(__dir__, 'fixtures') EMPTY_MODULE_ROOT = File.join(FIXTURES_DIR, 'module_root') @@ -40,39 +38,20 @@ end end -RSpec.shared_context 'stubbed analytics' do - let(:analytics) { PDK::Analytics::Client::Noop.new(logger: logger) } - - before do |example| - allow(PDK).to receive(:analytics).and_return(analytics) if example.metadata[:use_stubbed_analytics] - end -end - RSpec.configure do |c| c.define_derived_metadata do |metadata| metadata[:use_stubbed_logger] = true unless metadata.key?(:use_stubbed_logger) - metadata[:use_stubbed_analytics] = true unless metadata.key?(:use_stubbed_analytics) end c.include_context 'stubbed logger' - c.include_context 'stubbed analytics' c.before(:suite) do require 'yaml' - analytics_config = Tempfile.new('analytics.yml') - analytics_config.write(YAML.dump(disabled: true)) - analytics_config.close - ENV['PDK_ANALYTICS_CONFIG'] = analytics_config.path - end - - c.after(:suite) do - analytics_config.unlink end # This should catch any tests where we are not mocking out the actual calls to Rubygems.org c.before do allow(Gem::SpecFetcher).to receive(:fetcher).and_raise('Unmocked call to Gem::SpecFetcher.fetcher!') - ENV['PDK_DISABLE_ANALYTICS'] = 'true' end c.add_setting :root diff --git a/spec/support/mock_configuration.rb b/spec/support/mock_configuration.rb index 2fef814f0..4b4767548 100644 --- a/spec/support/mock_configuration.rb +++ b/spec/support/mock_configuration.rb @@ -1,10 +1,8 @@ RSpec.shared_context 'mock configuration' do let(:default_answer_file_content) { nil } let(:system_answers_content) { nil } - let(:analytics_config_content) { nil } let(:user_config_content) { nil } let(:system_config_content) { nil } - let(:bolt_analytics_content) { nil } let(:new_config) do PDK::Config.new.tap do |item| @@ -23,10 +21,8 @@ [ { file: PDK::AnswerFile.default_answer_file_path, content: default_answer_file_content }, { file: PDK::Config.system_answers_path, content: system_answers_content }, - { file: PDK::Config.analytics_config_path, content: analytics_config_content }, { file: PDK::Config.user_config_path, content: user_config_content }, - { file: PDK::Config.system_config_path, content: system_config_content }, - { file: '~/.puppetlabs/bolt/analytics.yaml', content: bolt_analytics_content } + { file: PDK::Config.system_config_path, content: system_config_content } ].each do |item| # If the content is nil then mock a missing file, otherwise mock a read-able file if item[:content].nil? diff --git a/spec/unit/pdk/analytics/client/google_analytics_spec.rb b/spec/unit/pdk/analytics/client/google_analytics_spec.rb deleted file mode 100644 index 92d80189d..000000000 --- a/spec/unit/pdk/analytics/client/google_analytics_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -require 'spec_helper' -require 'securerandom' -require 'httpclient' -require 'concurrent/configuration' -require 'concurrent/future' -require 'locale' -require 'pdk/analytics/client/google_analytics' - -describe PDK::Analytics::Client::GoogleAnalytics do - subject(:client) { described_class.new(options) } - - let(:options) do - { - logger: logger, - app_name: 'pdk', - app_id: 'UA-xxxx-1', - app_version: PDK::VERSION, - user_id: uuid - } - end - - let(:uuid) { SecureRandom.uuid } - let(:base_params) do - { - v: described_class::PROTOCOL_VERSION, - an: options[:app_name], - av: options[:app_version], - cid: options[:user_id], - tid: options[:app_id], - aiid: options[:app_installer], - ul: Locale.current.to_rfc, - aip: true, - cd1: os_name - } - end - let(:mock_httpclient) { instance_double(HTTPClient) } - let(:ga_url) { described_class::TRACKING_URL } - let(:executor) { Concurrent.new_io_executor } - let(:logger) { instance_double(Logger, debug: true) } - let(:os_name) { 'CentOS 7' } - - before do - allow(PDK::Analytics::Util).to receive(:fetch_os_async).and_return(instance_double(Concurrent::Future, value: os_name)) - allow(HTTPClient).to receive(:new).and_return(mock_httpclient) - allow(Concurrent).to receive(:global_io_executor).and_return(executor) - end - - describe '#screen_view' do - after do - client.finish - end - - it 'properly formats the screenview' do - params = base_params.merge(t: 'screenview', cd: 'job_run') - - expect(mock_httpclient).to receive(:post).with(ga_url, params).and_return(true) - - client.screen_view('job_run') - end - - it 'sets custom dimensions correctly' do - params = base_params.merge(t: 'screenview', cd: 'job_run', cd1: 'CentOS 7', cd2: 'text') - - expect(mock_httpclient).to receive(:post).with(ga_url, params).and_return(true) - - client.screen_view('job_run', operating_system: 'CentOS 7', output_format: 'text') - end - - it 'raises an error if an unknown custom dimension is specified' do - expect { client.screen_view('job_run', random_field: 'foo') }.to raise_error(/Unknown analytics key/) - end - end - - describe '#event' do - after do - client.finish - end - - it 'properly formats the event' do - params = base_params.merge(t: 'event', ec: 'run', ea: 'task') - - expect(mock_httpclient).to receive(:post).with(ga_url, params).and_return(true) - - client.event('run', 'task') - end - - it 'sends the event label if supplied' do - params = base_params.merge(t: 'event', ec: 'run', ea: 'task', el: 'happy') - - expect(mock_httpclient).to receive(:post).with(ga_url, params).and_return(true) - - client.event('run', 'task', label: 'happy') - end - - it 'sends the event metric if supplied' do - params = base_params.merge(t: 'event', ec: 'run', ea: 'task', ev: 12) - - expect(mock_httpclient).to receive(:post).with(ga_url, params).and_return(true) - - client.event('run', 'task', value: 12) - end - end -end diff --git a/spec/unit/pdk/analytics/client/noop_spec.rb b/spec/unit/pdk/analytics/client/noop_spec.rb deleted file mode 100644 index 0961eff3e..000000000 --- a/spec/unit/pdk/analytics/client/noop_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'spec_helper' -require 'pdk/analytics/client/noop' - -describe PDK::Analytics::Client::Noop do - subject(:client) { described_class.new(options) } - - let(:options) { { logger: instance_double(Logger, debug: true) } } - - describe '#screen_view' do - it 'does not raise an error' do - expect { client.screen_view('job_run') }.not_to raise_error - end - end - - describe '#event' do - it 'does not raise an error' do - expect { client.event('run', 'task') }.not_to raise_error - end - - context 'with a label' do - it 'does not raise an error' do - expect { client.event('run', 'task', label: 'happy') }.not_to raise_error - end - end - - context 'with a value' do - it 'does not raise an error' do - expect { client.event('run', 'task', value: 12) }.not_to raise_error - end - end - end - - describe '#finish' do - it 'does not raise an error' do - expect { client.finish }.not_to raise_error - end - end -end diff --git a/spec/unit/pdk/analytics/util_spec.rb b/spec/unit/pdk/analytics/util_spec.rb deleted file mode 100644 index ed8fef6af..000000000 --- a/spec/unit/pdk/analytics/util_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'spec_helper' -require 'concurrent/configuration' -require 'concurrent/future' -require 'facter' -require 'pdk/analytics/util' - -describe PDK::Analytics::Util do - describe '.fetch_os_async' do - subject(:result) { described_class.fetch_os_async } - - let(:executor) { Concurrent.new_io_executor } - - before do - allow(Concurrent).to receive(:global_io_executor).and_return(executor) - allow(Facter).to receive(:value).with('os').and_return(os_hash) - end - - after do - executor.shutdown - executor.wait_for_termination(0.25) - end - - context 'when facter returns a full os hash' do - let(:os_hash) { { 'name' => 'CentOS', 'release' => { 'major' => 7 } } } - - it 'returns a string with the OS name and major version' do - expect(result.value).to eq('CentOS 7') - end - end - - context 'when facter returns an os hash with incomplete release information' do - let(:os_hash) { { 'name' => 'CentOS', 'release' => {} } } - - it 'returns a string with the OS name' do - expect(result.value).to eq('CentOS') - end - end - - context 'when facter returns an os hash with no release information' do - let(:os_hash) { { 'name' => 'CentOS' } } - - it 'returns a string with the OS name' do - expect(result.value).to eq('CentOS') - end - end - - context 'when facter does not return an os hash' do - let(:os_hash) { nil } - - it 'returns unknown' do - expect(result.value).to eq('unknown') - end - end - end -end diff --git a/spec/unit/pdk/analytics_spec.rb b/spec/unit/pdk/analytics_spec.rb deleted file mode 100644 index ef010c0a4..000000000 --- a/spec/unit/pdk/analytics_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'spec_helper' -require 'securerandom' -require 'pdk/analytics' - -describe PDK::Analytics do - let(:default_config) { {} } - let(:logger) { instance_double(Logger, debug: true) } - let(:uuid) { SecureRandom.uuid } - - before do - # We use a hard override to disable analytics for tests, but that obviously - # interferes with these tests... - allow(PDK::Util::Env).to receive(:[]).with('PDK_DISABLE_ANALYTICS').and_return(nil) - end - - describe '.build_client' do - subject { described_class.build_client(options) } - - let(:options) do - { - logger: logger, - client: :google_analytics, - disabled: disabled, - user_id: uuid, - app_name: 'pdk', - app_version: PDK::VERSION, - app_id: '1' - } - end - - context 'when analytics is disabled' do - let(:disabled) { true } - - it 'returns an instance of the Noop client' do - expect(subject).to be_an_instance_of(described_class::Client::Noop) - end - end - - context 'when analytics are enabled' do - let(:disabled) { false } - - it 'returns an instance of the GoogleAnalytics client' do - expect(subject).to be_an_instance_of(described_class::Client::GoogleAnalytics) - end - - context 'when the client instantiation fails' do - before do - allow(described_class::Client::GoogleAnalytics).to receive(:new).and_raise(StandardError) - end - - it 'returns an instance of the Noop client' do - expect(subject).to be_an_instance_of(described_class::Client::Noop) - end - end - end - end -end diff --git a/spec/unit/pdk/cli/build_spec.rb b/spec/unit/pdk/cli/build_spec.rb index 0a1766517..b1753482e 100644 --- a/spec/unit/pdk/cli/build_spec.rb +++ b/spec/unit/pdk/cli/build_spec.rb @@ -19,12 +19,6 @@ expect { PDK::CLI.run(['build']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['build']) }.to exit_nonzero - end end context 'when run from inside a module' do @@ -73,13 +67,6 @@ expect(mock_metadata_obj).to receive(:interview_for_forge!) expect(mock_metadata_obj).to receive(:write!).with('metadata.json') end - - it 'submits the command to analytics' do - allow(mock_metadata_obj).to receive(:interview_for_forge!) - allow(mock_metadata_obj).to receive(:write!) - - expect(analytics).to receive(:screen_view).with('build', hash_including(output_format: 'default', ruby_version: RUBY_VERSION)) - end end context 'with --force option' do @@ -90,12 +77,6 @@ expect { PDK::CLI.run(['build'] + command_opts) }.not_to raise_error end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with('build', hash_including(cli_options: /force=true/, output_format: 'default', ruby_version: RUBY_VERSION)) - - expect { PDK::CLI.run(['build'] + command_opts) }.not_to raise_error - end end end @@ -111,10 +92,6 @@ expect(mock_metadata_obj).not_to receive(:interview_for_forge!) expect(mock_metadata_obj).not_to receive(:write!) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with('build', hash_including(output_format: 'default', ruby_version: RUBY_VERSION)) - end end context 'and provided no flags' do @@ -123,10 +100,6 @@ it 'invokes the builder with the default target directory' do expect(PDK::Module::Build).to receive(:new).with(hash_with_defaults_including('target-dir': File.join(Dir.pwd, 'pkg'))).and_return(mock_builder) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with('build', hash_including(output_format: 'default', ruby_version: RUBY_VERSION)) - end end context 'and provided with the --target-dir option' do @@ -137,10 +110,6 @@ it 'invokes the builder with the specified target directory' do expect(PDK::Module::Build).to receive(:new).with(hash_including('target-dir': '/tmp/pdk_builds')).and_return(mock_builder) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with('build', cli_options: 'target-dir=redacted', output_format: 'default', ruby_version: RUBY_VERSION) - end end context 'package already exists in the target dir' do diff --git a/spec/unit/pdk/cli/bundle_spec.rb b/spec/unit/pdk/cli/bundle_spec.rb index 952a08aa4..fa14aeea7 100644 --- a/spec/unit/pdk/cli/bundle_spec.rb +++ b/spec/unit/pdk/cli/bundle_spec.rb @@ -6,12 +6,6 @@ let(:command_result) { { exit_code: 0 } } context 'when it calls bundler successfully' do - after do - expect do - PDK::CLI.run(command_args) - end.to exit_zero - end - before do mock_command = instance_double( PDK::CLI::Exec::InteractiveCommand, @@ -33,36 +27,30 @@ end context 'and called with no arguments' do - it 'sends a "bundle" screen view to analytics' do - expect(analytics).to receive(:screen_view).with( - 'bundle', - output_format: 'default', - ruby_version: RUBY_VERSION - ) + it 'runs without an error' do + expect do + PDK::CLI.run(command_args) + end.to exit_zero end end context 'and called with a bundler subcommand that is not "exec"' do let(:command_args) { super() + ['config', 'something'] } - it 'includes only the subcommand in the screen view name sent to analytics' do - expect(analytics).to receive(:screen_view).with( - 'bundle_config', - output_format: 'default', - ruby_version: RUBY_VERSION - ) + it 'runs without an error' do + expect do + PDK::CLI.run(command_args) + end.to exit_zero end end context 'and called with the "exec" bundler subcommand' do let(:command_args) { super() + ['exec', 'rspec', 'some/path'] } - it 'includes the name of the command being executed in the screen view sent to analytics' do - expect(analytics).to receive(:screen_view).with( - 'bundle_exec_rspec', - output_format: 'default', - ruby_version: RUBY_VERSION - ) + it 'runs without an error' do + expect do + PDK::CLI.run(command_args) + end.to exit_zero end end end diff --git a/spec/unit/pdk/cli/convert_spec.rb b/spec/unit/pdk/cli/convert_spec.rb index ec2401134..759326d36 100644 --- a/spec/unit/pdk/cli/convert_spec.rb +++ b/spec/unit/pdk/cli/convert_spec.rb @@ -21,12 +21,6 @@ expect { PDK::CLI.run(['convert']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['convert']) }.to exit_nonzero - end end context 'when run inside a nested module-looking directories' do @@ -91,14 +85,6 @@ it 'invokes the converter with no template specified' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_not_including(:'template-url')) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --template-url option has been passed' do @@ -109,15 +95,6 @@ it 'invokes the converter with the user supplied template' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including('template-url': 'https://my/template')) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'template-url=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --template-ref option has been passed' do @@ -128,15 +105,6 @@ it 'invokes the converter with the user supplied template' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including('template-url': 'https://my/template', 'template-ref': '1.0.0')) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'template-url=redacted,template-ref=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --noop flag has been passed' do @@ -147,15 +115,6 @@ it 'passes the noop option through to the converter' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including(noop: true)) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'noop=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --force flag has been passed' do @@ -166,15 +125,6 @@ it 'passes the force option through to the converter' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including(force: true)) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'force=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --force and --noop flags have been passed' do @@ -183,12 +133,6 @@ expect { PDK::CLI.run(['convert', '--noop', '--force']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['convert', '--noop', '--force']) }.to exit_nonzero - end end context 'and the --skip-interview flag has been passed' do @@ -199,15 +143,6 @@ it 'passes the skip-interview option through to the converter' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including('skip-interview': true)) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'skip-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --full-interview flag has been passed' do @@ -218,15 +153,6 @@ it 'passes the full-interview option through to the converter' do expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including('full-interview': true)) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'full-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --skip-interview and --full-interview flags have been passed' do @@ -238,15 +164,6 @@ expect(logger).to receive(:info).with(a_string_matching(/Ignoring --full-interview and continuing with --skip-interview./i)) expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including('skip-interview': true, 'full-interview': false)) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'skip-interview=true,full-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --force and --full-interview flags have been passed' do @@ -258,15 +175,6 @@ expect(logger).to receive(:info).with(a_string_matching(/Ignoring --full-interview and continuing with --force./i)) expect(PDK::Module::Convert).to receive(:invoke).with(module_root, hash_including(force: true, 'full-interview': false)) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'force=true,full-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --default-template flag has been passed' do @@ -281,12 +189,6 @@ expect { PDK::CLI.run(args) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(args) }.to exit_nonzero - end end context 'without the --template-url option' do @@ -304,16 +206,6 @@ run expect(PDK.config.get(['user', 'module_defaults', 'template-url'])).to be_nil end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'convert', - cli_options: 'default-template=true,template-url=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - run - end end end end diff --git a/spec/unit/pdk/cli/env_spec.rb b/spec/unit/pdk/cli/env_spec.rb index 390ab9177..fc7db0642 100644 --- a/spec/unit/pdk/cli/env_spec.rb +++ b/spec/unit/pdk/cli/env_spec.rb @@ -24,14 +24,6 @@ end context 'and called with no arguments' do - it 'sends a "env" screen view to analytics' do - expect(analytics).to receive(:screen_view).with( - 'env', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end - it 'outputs export commands for environment variables' do output_regexes = [ /export PDK_RESOLVED_PUPPET_VERSION="\d\.\d+\.\d+"/, diff --git a/spec/unit/pdk/cli/new/class_spec.rb b/spec/unit/pdk/cli/new/class_spec.rb index cd210a366..37cee98b6 100644 --- a/spec/unit/pdk/cli/new/class_spec.rb +++ b/spec/unit/pdk/cli/new/class_spec.rb @@ -17,12 +17,6 @@ expect { PDK::CLI.run(['new', 'class', 'test_class']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'class', 'test_class']) }.to exit_nonzero - end end context 'when run from inside a module' do @@ -36,24 +30,12 @@ it 'exits non-zero and prints the `pdk new class` help' do expect { PDK::CLI.run(['new', 'class']) }.to exit_nonzero.and output(help_text).to_stdout end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'class']) }.to exit_nonzero.and output(help_text).to_stdout - end end context 'and provided an empty string as the class name' do it 'exits non-zero and prints the `pdk new class` help' do expect { PDK::CLI.run(['new', 'class', '']) }.to exit_nonzero.and output(help_text).to_stdout end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'class', '']) }.to exit_nonzero.and output(help_text).to_stdout - end end context 'and provided an invalid class name' do @@ -62,12 +44,6 @@ expect { PDK::CLI.run(['new', 'class', 'test-class']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'class', 'test-class']) }.to exit_nonzero - end end context 'and provided a valid class name' do @@ -81,16 +57,6 @@ expect(PDK::Generate::PuppetClass).to receive(:new).with(anything, 'test_class', instance_of(Hash)).and_return(generator) expect(generator).to receive(:run) end - - it 'submits the command to analytics' do - allow(PDK::Generate::PuppetClass).to receive(:new).and_return(generator) - - expect(analytics).to receive(:screen_view).with( - 'new_class', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end end end diff --git a/spec/unit/pdk/cli/new/defined_type_spec.rb b/spec/unit/pdk/cli/new/defined_type_spec.rb index 7376b1043..a76f2a618 100644 --- a/spec/unit/pdk/cli/new/defined_type_spec.rb +++ b/spec/unit/pdk/cli/new/defined_type_spec.rb @@ -15,12 +15,6 @@ it 'exits non-zero and prints the `pdk new defined_type` help' do expect { PDK::CLI.run(args) }.to exit_nonzero.and output(help_text).to_stdout end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(args) }.to exit_nonzero.and output(help_text).to_stdout - end end shared_examples 'it exits with an error' do |expected_error| @@ -29,12 +23,6 @@ expect { PDK::CLI.run(args) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(args) }.to exit_nonzero - end end context 'when not run from inside a module' do @@ -82,14 +70,6 @@ it 'generates the defined type' do expect(generator_double).to receive(:run) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'new_defined_type', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end end end diff --git a/spec/unit/pdk/cli/new/module_spec.rb b/spec/unit/pdk/cli/new/module_spec.rb index 7c155f3ea..7b168092c 100644 --- a/spec/unit/pdk/cli/new/module_spec.rb +++ b/spec/unit/pdk/cli/new/module_spec.rb @@ -11,18 +11,6 @@ expect(logger).to receive(:info).with(/Creating new module:/) PDK::CLI.run(['new', 'module']) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module']) - end end context 'and run with --skip-interview' do @@ -31,17 +19,6 @@ expect { PDK::CLI.run(['new', 'module', '--skip-interview']) }.to exit_nonzero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'new_module', - cli_options: 'skip-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['new', 'module', '--skip-interview']) }.to exit_nonzero - end end end @@ -51,20 +28,6 @@ expect { PDK::CLI.run(['new', 'module', '123test']) }.to exit_nonzero end - - # Unlike most other commands, the validation of parameters does not happen - # at the CLI layer as they can be later modified during the interview. - # FIXME - extract validation logic so module name can be validated here if - # specified - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'new_module', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['new', 'module', '123test']) }.to exit_nonzero - end end context 'when passed a valid module name' do @@ -76,18 +39,6 @@ PDK::CLI.run(['new', 'module', module_name]) end - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', module_name]) - end - context 'and a target directory' do let(:target_dir) { 'target' } @@ -96,18 +47,6 @@ expect(logger).to receive(:info).with("Creating new module: #{module_name}") PDK::CLI.run(['new', 'module', module_name, target_dir]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', module_name, target_dir]) - end end context 'and the template-url option' do @@ -118,19 +57,6 @@ expect(logger).to receive(:info).with("Creating new module: #{module_name}") PDK::CLI.run(['new', 'module', '--template-url', template_url, module_name]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - cli_options: 'template-url=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', '--template-url', template_url, module_name]) - end end context 'and the template-ref without the template-url option' do @@ -140,12 +66,6 @@ expect(PDK::Generate::Module).not_to receive(:invoke) expect { PDK::CLI.run(['new', 'module', '--template-ref', template_ref, module_name]) }.to exit_nonzero end - - it 'does not submit a command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'module', '--template-ref', template_ref, module_name]) }.to exit_nonzero - end end context 'and the license option' do @@ -156,19 +76,6 @@ expect(logger).to receive(:info).with("Creating new module: #{module_name}") PDK::CLI.run(['new', 'module', '--license', license, module_name]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - cli_options: 'license=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', '--license', license, module_name]) - end end context 'and the skip-interview flag' do @@ -177,19 +84,6 @@ expect(logger).to receive(:info).with("Creating new module: #{module_name}") PDK::CLI.run(['new', 'module', '--skip-interview', module_name]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - cli_options: 'skip-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', '--skip-interview', module_name]) - end end context 'and the full-interview flag' do @@ -198,19 +92,6 @@ expect(logger).to receive(:info).with("Creating new module: #{module_name}") PDK::CLI.run(['new', 'module', '--full-interview', module_name]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - cli_options: 'full-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', '--full-interview', module_name]) - end end context 'and the --skip-interview and --full-interview flags have been passed' do @@ -220,19 +101,6 @@ PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview', module_name]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - cli_options: 'skip-interview=true,full-interview=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview', module_name]) - end end end @@ -244,17 +112,5 @@ expect(logger).to receive(:info).with("Creating new module: #{module_name}") PDK::CLI.run(['new', 'module', module_name]) end - - it 'submits the command to analytics' do - allow(PDK::Generate::Module).to receive(:invoke) - - expect(analytics).to receive(:screen_view).with( - 'new_module', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'module', module_name]) - end end end diff --git a/spec/unit/pdk/cli/new/task_spec.rb b/spec/unit/pdk/cli/new/task_spec.rb index 0ccbbf541..a3765cdac 100644 --- a/spec/unit/pdk/cli/new/task_spec.rb +++ b/spec/unit/pdk/cli/new/task_spec.rb @@ -14,12 +14,6 @@ it 'exits non-zero and prints the `pdk new task` help' do expect { PDK::CLI.run(args) }.to exit_nonzero.and output(help_text).to_stdout end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(args) }.to exit_nonzero.and output(help_text).to_stdout - end end shared_examples 'it exits with an error' do |expected_error| @@ -28,12 +22,6 @@ expect { PDK::CLI.run(args) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(args) }.to exit_nonzero - end end context 'when not run from inside a module' do @@ -80,16 +68,6 @@ PDK::CLI.run(['new', 'task', 'test_task']) end - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'new_task', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'task', 'test_task']) - end - context 'and provided a description for the task' do let(:generator_opts) do { @@ -102,17 +80,6 @@ PDK::CLI.run(['new', 'task', 'test_task', '--description', 'test_task description']) end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'new_task', - cli_options: 'description=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - PDK::CLI.run(['new', 'task', 'test_task', '--description', 'test_task description']) - end end end end diff --git a/spec/unit/pdk/cli/new/test_spec.rb b/spec/unit/pdk/cli/new/test_spec.rb index 974405036..970cf5e08 100644 --- a/spec/unit/pdk/cli/new/test_spec.rb +++ b/spec/unit/pdk/cli/new/test_spec.rb @@ -17,12 +17,6 @@ expect { PDK::CLI.run(['new', 'test', 'my_object']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'test', 'my_object']) }.to exit_nonzero - end end context 'when run from inside a module' do @@ -39,24 +33,12 @@ it 'exits non-zero and prints the `pdk new test` help' do expect { PDK::CLI.run(['new', 'test', '--unit']) }.to exit_nonzero.and output(help_text).to_stdout end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'test', '--unit']) }.to exit_nonzero.and output(help_text).to_stdout - end end context 'and provided an empty string as the object name' do it 'exits non-zero and prints the `pdk new test` help' do expect { PDK::CLI.run(['new', 'test', '--unit', '']) }.to exit_nonzero.and output(help_text).to_stdout end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'test', '--unit', '']) }.to exit_nonzero.and output(help_text).to_stdout - end end context 'and provided an invalid object name' do @@ -69,12 +51,6 @@ expect { PDK::CLI.run(['new', 'test', '--unit', 'test-class']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'test', '--unit', 'test-class']) }.to exit_nonzero - end end context 'and provided a valid object name' do @@ -93,17 +69,6 @@ expect(PDK::Generate::PuppetClass).to receive(:new).with(anything, 'my_module::test_class', include(spec_only: true)).and_return(generator) expect(generator).to receive(:run) end - - it 'submits the command to analytics' do - allow(PDK::Generate::PuppetClass).to receive(:new).and_return(generator) - - expect(analytics).to receive(:screen_view).with( - 'new_test', - cli_options: 'unit=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the test type is not specified' do @@ -115,17 +80,6 @@ expect(PDK::Generate::PuppetClass).to receive(:new).with(anything, 'my_module::test_class', include(spec_only: true)).and_return(generator) expect(generator).to receive(:run) end - - it 'submits the command to analytics' do - allow(PDK::Generate::PuppetClass).to receive(:new).and_return(generator) - - expect(analytics).to receive(:screen_view).with( - 'new_test', - cli_options: 'unit=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end end @@ -143,12 +97,6 @@ expect { PDK::CLI.run(['new', 'test', '--unit', 'test_thing']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['new', 'test', '--unit', 'test_thing']) }.to exit_nonzero - end end end end diff --git a/spec/unit/pdk/cli/release/prep_spec.rb b/spec/unit/pdk/cli/release/prep_spec.rb index 3290b1048..4e397080d 100644 --- a/spec/unit/pdk/cli/release/prep_spec.rb +++ b/spec/unit/pdk/cli/release/prep_spec.rb @@ -13,12 +13,6 @@ expect { PDK::CLI.run(cli_args) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(cli_args) }.to exit_nonzero - end end context 'when run from inside a module' do diff --git a/spec/unit/pdk/cli/release/publish_spec.rb b/spec/unit/pdk/cli/release/publish_spec.rb index 15c3c5832..330d8f9f2 100644 --- a/spec/unit/pdk/cli/release/publish_spec.rb +++ b/spec/unit/pdk/cli/release/publish_spec.rb @@ -15,12 +15,6 @@ expect { PDK::CLI.run(cli_args) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(cli_args) }.to exit_nonzero - end end context 'when run from inside a module' do @@ -93,7 +87,6 @@ context 'when passed a forge-token via PDK_FORGE_TOKEN' do before do - allow(PDK::Util::Env).to receive(:[]).with('PDK_DISABLE_ANALYTICS').and_return(true) allow(PDK::Util::Env).to receive(:[]).with('PDK_FORGE_TOKEN').and_return('env123') end @@ -109,7 +102,6 @@ let(:cli_args) { base_cli_args << '--forge-token=cli123' } before do - allow(PDK::Util::Env).to receive(:[]).with('PDK_DISABLE_ANALYTICS').and_return(true) allow(PDK::Util::Env).to receive(:[]).with('PDK_FORGE_TOKEN').and_return('env123') end diff --git a/spec/unit/pdk/cli/test/unit_spec.rb b/spec/unit/pdk/cli/test/unit_spec.rb index 4c9e6a468..7a735a679 100644 --- a/spec/unit/pdk/cli/test/unit_spec.rb +++ b/spec/unit/pdk/cli/test/unit_spec.rb @@ -31,19 +31,6 @@ context 'when listing tests' do let(:args) { ['--list'] } - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:list).and_return([]) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - cli_options: 'list=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this(args) }.to output.to_stdout - end - context 'when no tests are found' do before do expect(PDK::Test::Unit).to receive(:list).and_return([]) @@ -79,19 +66,6 @@ context 'when listing tests with verbose' do let(:args) { ['--list', '-v'] } - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:list).and_return([]) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - cli_options: 'list=true,verbose=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this(args) }.to output.to_stdout - end - context 'when no tests are found' do before do expect(PDK::Test::Unit).to receive(:list).and_return([]) @@ -141,19 +115,6 @@ test_unit_cmd.run_this(['--clean-fixtures']) end.to exit_zero end - - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:invoke).and_return(0) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - cli_options: 'clean-fixtures=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this(['--clean-fixtures']) }.to exit_zero - end end context 'when not passed --clean-fixtures' do @@ -163,18 +124,6 @@ test_unit_cmd.run_this([]) end.to exit_zero end - - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:invoke).and_return(0) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this([]) }.to exit_zero - end end context 'when tests pass' do @@ -184,18 +133,6 @@ expect { test_unit_cmd.run_this([]) }.to exit_zero end - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:invoke).and_return(0) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this([]) }.to exit_zero - end - context 'with a format option' do before do expect(PDK::CLI::Util::OptionNormalizer).to receive(:report_formats).with(['text:results.txt']).and_return([{ method: :write_text, target: 'results.txt' }]).at_least(:twice) @@ -205,18 +142,6 @@ it do expect { test_unit_cmd.run_this(['--format=text:results.txt']) }.to exit_zero end - - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:invoke).and_return(0) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - output_format: 'text', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this(['--format=text:results.txt']) }.to exit_zero - end end context 'with specific tests passed in' do @@ -230,19 +155,6 @@ it do expect { test_unit_cmd.run_this(["--tests=#{tests}"]) }.to exit_zero end - - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:invoke).and_return(0) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - cli_options: 'tests=redacted', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this(["--tests=#{tests}"]) }.to exit_zero - end end end @@ -254,18 +166,6 @@ it do expect { test_unit_cmd.run_this([]) }.to exit_nonzero end - - it 'submits the command to analytics' do - allow(PDK::Test::Unit).to receive(:invoke).and_return(0) - - expect(analytics).to receive(:screen_view).with( - 'test_unit', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { test_unit_cmd.run_this([]) }.to exit_nonzero - end end end end @@ -301,19 +201,6 @@ test_unit_cmd.run_this(['--puppet-dev']) end.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'test_unit', - cli_options: 'puppet-dev=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect do - test_unit_cmd.run_this(['--puppet-dev']) - end.to exit_zero - end end context 'with --puppet-version' do @@ -347,18 +234,5 @@ test_unit_cmd.run_this(["--puppet-version=#{puppet_version}"]) end.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'test_unit', - cli_options: "puppet-version=#{puppet_version}", - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect do - test_unit_cmd.run_this(["--puppet-version=#{puppet_version}"]) - end.to exit_zero - end end end diff --git a/spec/unit/pdk/cli/update_spec.rb b/spec/unit/pdk/cli/update_spec.rb index 497c1c2d4..106052fde 100644 --- a/spec/unit/pdk/cli/update_spec.rb +++ b/spec/unit/pdk/cli/update_spec.rb @@ -21,12 +21,6 @@ expect { PDK::CLI.run(['update']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['update']) }.to exit_nonzero - end end context 'when run inside a nested module-looking directories' do @@ -118,16 +112,6 @@ expect(updater).to receive(:run) end - - it 'submits the command to analytics' do - allow(PDK::Module::Update).to receive(:new).with(module_root, anything).and_return(updater) - - expect(analytics).to receive(:screen_view).with( - 'update', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the module is pinned to tagged version of our template' do @@ -156,17 +140,6 @@ expect(PDK::Module::Update).to receive(:new).with(module_root, hash_including(noop: true)).and_return(updater) expect(updater).to receive(:run) end - - it 'submits the command to analytics' do - allow(PDK::Module::Update).to receive(:new).with(module_root, anything).and_return(updater) - - expect(analytics).to receive(:screen_view).with( - 'update', - cli_options: 'noop=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --force flag has been passed' do @@ -178,17 +151,6 @@ expect(PDK::Module::Update).to receive(:new).with(module_root, hash_including(force: true)).and_return(updater) expect(updater).to receive(:run) end - - it 'submits the command to analytics' do - allow(PDK::Module::Update).to receive(:new).with(module_root, anything).and_return(updater) - - expect(analytics).to receive(:screen_view).with( - 'update', - cli_options: 'force=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - end end context 'and the --force and --noop flags have been passed' do @@ -197,12 +159,6 @@ expect { PDK::CLI.run(['update', '--noop', '--force']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['update', '--noop', '--force']) }.to exit_nonzero - end end context 'and the module metadata specifies a newer PDK version' do @@ -239,12 +195,6 @@ expect { PDK::CLI.run(['update']) }.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect { PDK::CLI.run(['update']) }.to exit_nonzero - end end end end diff --git a/spec/unit/pdk/cli/validate_spec.rb b/spec/unit/pdk/cli/validate_spec.rb index 04dab051d..19f178192 100644 --- a/spec/unit/pdk/cli/validate_spec.rb +++ b/spec/unit/pdk/cli/validate_spec.rb @@ -36,16 +36,6 @@ expect { PDK::CLI.run(['validate']) }.to exit_zero end - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate']) }.to exit_zero - end - context 'with --parallel' do it 'invokes each validator with no report and no options and exits zero' do expect(PDK::Validate).to receive(:invoke_validators_by_name).with( @@ -59,17 +49,6 @@ expect { PDK::CLI.run(['validate', '--parallel']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - cli_options: 'parallel=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', '--parallel']) }.to exit_zero - end end end @@ -79,17 +58,6 @@ expect { PDK::CLI.run(['validate', '--list']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - cli_options: 'list=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', '--list']) }.to exit_zero - end end context 'when a single validator is provided as an argument' do @@ -103,16 +71,6 @@ expect { PDK::CLI.run(['validate', 'metadata']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate_metadata', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', 'metadata']) }.to exit_zero - end end context 'when multiple known validators are given as arguments' do @@ -126,16 +84,6 @@ expect { PDK::CLI.run(['validate', 'puppet,metadata']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate_metadata_puppet', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', 'puppet,metadata']) }.to exit_zero - end end context 'when unknown validators are given as arguments' do @@ -152,16 +100,6 @@ expect { PDK::CLI.run(['validate', 'puppet,bad-val']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate_puppet', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', 'puppet,bad-val']) }.to exit_zero - end end context 'when targets are provided as arguments' do @@ -177,16 +115,6 @@ expect { PDK::CLI.run(['validate', 'metadata', 'lib/', 'manifests/']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate_metadata', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', 'metadata', 'lib/', 'manifests/']) }.to exit_zero - end end context 'when targets are provided as arguments and no validators are specified' do @@ -204,16 +132,6 @@ expect { PDK::CLI.run(['validate', 'lib/', 'manifests/']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', 'lib/', 'manifests/']) }.to exit_zero - end end context 'when no report formats are specified' do @@ -223,16 +141,6 @@ expect { PDK::CLI.run(['validate']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate']) }.to exit_zero - end end context 'when a report format is specified' do @@ -242,16 +150,6 @@ expect { PDK::CLI.run(['validate', '--format', 'junit']) }.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - output_format: 'junit', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', '--format', 'junit']) }.to exit_zero - end end context 'when multiple report formats are specified' do @@ -264,18 +162,6 @@ PDK::CLI.run(['validate', '--format', 'text:stderr', '--format', 'junit:testfile.xml', '--format', 'text']) end.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - output_format: 'junit,text', - ruby_version: RUBY_VERSION - ) - - expect do - PDK::CLI.run(['validate', '--format', 'text:stderr', '--format', 'junit:testfile.xml', '--format', 'text']) - end.to exit_zero - end end context 'with --puppet-dev' do @@ -306,17 +192,6 @@ PDK::CLI.run(['validate', '--puppet-dev']) end.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - cli_options: 'puppet-dev=true', - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect { PDK::CLI.run(['validate', '--puppet-dev']) }.to exit_zero - end end context 'with both --puppet-version and --puppet-dev' do @@ -327,14 +202,6 @@ PDK::CLI.run(['validate', '--puppet-version', '4.10.10', '--puppet-dev']) end.to exit_nonzero end - - it 'does not submit the command to analytics' do - expect(analytics).not_to receive(:screen_view) - - expect do - PDK::CLI.run(['validate', '--puppet-version', '4.10.10', '--puppet-dev']) - end.to exit_nonzero - end end context 'with --puppet-version' do @@ -365,18 +232,5 @@ PDK::CLI.run(['validate', "--puppet-version=#{puppet_version}"]) end.to exit_zero end - - it 'submits the command to analytics' do - expect(analytics).to receive(:screen_view).with( - 'validate', - cli_options: "puppet-version=#{puppet_version}", - output_format: 'default', - ruby_version: RUBY_VERSION - ) - - expect do - PDK::CLI.run(['validate', "--puppet-version=#{puppet_version}"]) - end.to exit_zero - end end end diff --git a/spec/unit/pdk/cli_spec.rb b/spec/unit/pdk/cli_spec.rb index 39255887c..8dbc971c7 100644 --- a/spec/unit/pdk/cli_spec.rb +++ b/spec/unit/pdk/cli_spec.rb @@ -44,54 +44,6 @@ def deprecated_runtime? end end - context 'analytics opt-out prompt' do - before do - # Temporarily bypass suite-wide analytics disable - allow(PDK::Util::Env).to receive(:[]).and_call_original - allow(PDK::Util::Env).to receive(:[]).with('PDK_ANALYTICS_CONFIG').and_return(nil) - allow(PDK::Util::Env).to receive(:[]).with('PDK_DISABLE_ANALYTICS').and_return(nil) - - # Suppress output - allow($stdout).to receive(:puts).with(anything) - end - - context 'when analytics config does not yet exist' do - before do - allow(PDK::Config).to receive(:analytics_config_exist?).and_return(false) - end - - it 'prompts the user about analytics config' do - expect(PDK::Config).to receive(:analytics_config_interview!) - - expect { described_class.run(['--version']) }.to exit_zero - end - - context 'when PDK_DISABLE_ANALYTICS is set' do - before do - allow(PDK::Util::Env).to receive(:[]).with('PDK_DISABLE_ANALYTICS').and_return('true') - end - - it 'does not prompt the user about analytics config' do - expect(PDK::Config).not_to receive(:analytics_config_interview!) - - expect { described_class.run(['--version']) }.to exit_zero - end - end - end - - context 'when analytics config already exists' do - before do - allow(PDK::Config).to receive(:analytics_config_exist?).and_return(true) - end - - it 'does not prompt the user about analytics config' do - expect(PDK::Config).not_to receive(:analytics_config_interview!) - - expect { described_class.run(['--version']) }.to exit_zero - end - end - end - ['validate', 'test unit', 'bundle'].each do |command| context "when #{command} command used but not in a module folder" do include_context 'run outside module' @@ -129,16 +81,4 @@ def deprecated_runtime? described_class.run([]) end end - - context 'when provided an invalid subcommand' do - it 'submits an event to analytics' do - expect(analytics).to receive(:event).with( - 'CLI', 'invalid command', label: 'test acceptance --an-opt redacted redacted' - ) - - expect do - described_class.run(['test', 'acceptance', '--an-opt', 'opt-value', 'some_arg']) - end.to exit_nonzero.and output.to_stderr - end - end end diff --git a/spec/unit/pdk/config_spec.rb b/spec/unit/pdk/config_spec.rb index 063ae1076..8fd231345 100644 --- a/spec/unit/pdk/config_spec.rb +++ b/spec/unit/pdk/config_spec.rb @@ -8,8 +8,6 @@ include_context 'mock configuration' - let(:bolt_analytics_path) { '~/.puppetlabs/bolt/analytics.yaml' } - def mock_file(path, content) allow(PDK::Util::Filesystem).to receive(:file?).with(PDK::Util::Filesystem.expand_path(path)).and_return(true) allow(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(path), anything) @@ -78,7 +76,6 @@ def mock_file(path, content) end describe '.get' do - let(:bolt_analytics_content) { "---\ndisabled: true\n" } let(:system_config_content) do <<-EOT { @@ -119,8 +116,7 @@ def mock_file(path, content) end it 'traverses namespaces' do - # The analytics is a child namespace of user - expect(config.get('user', 'analytics', 'disabled')).to be(true) + expect(config.get('user', 'disabled')).to be(true) end it 'traverses setting hash values' do @@ -144,7 +140,7 @@ def mock_file(path, content) end context 'given a root name that does not exist' do - let(:names) { ['missing', 'analytics', 'disabled'] } + let(:names) { ['missing', 'disabled'] } it 'returns nil' do expect(config.get(*names)).to be_nil @@ -363,7 +359,7 @@ def project_config end context 'given a root name that does not exist' do - let(:names) { ['missing', 'analytics', 'disabled'] } + let(:names) { ['missing', 'disabled'] } it 'raises an error' do expect { config.set(names, value) }.to raise_error(ArgumentError) @@ -523,186 +519,4 @@ def project_config end end end - - describe 'user.analytics.disabled' do - context 'set' do - it 'can be set to true' do - expect { config.user_config['analytics']['disabled'] = true }.not_to raise_error - end - - it 'can be set to false' do - expect { config.user_config['analytics']['disabled'] = false }.not_to raise_error - end - - it 'can not be set to a string' do - expect { config.user_config['analytics']['disabled'] = 'no' }.to raise_error(ArgumentError) - end - end - - context 'default value' do - context 'when there is no pre-existing bolt configuration' do - it 'returns true' do - expect(config.user_config['analytics']['disabled']).to be_truthy - end - - it 'saves the disabled value to the analytics config file' do - expect(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(described_class.analytics_config_path), /disabled: true/) - config.user_config['analytics']['disabled'] - end - end - - context 'when there is a pre-existing bolt configuration' do - let(:bolt_analytics_content) { "---\ndisabled: false\n" } - - it 'returns the value from the bolt configuration' do - expect(config.user_config['analytics']['disabled']).to be_falsey - end - - it 'saves the disabled value to the analytics config file' do - expect(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(described_class.analytics_config_path), /disabled: false/) - config.user_config['analytics']['disabled'] - end - - context 'and the bolt configuration is unparsable' do - before do - allow(described_class::YAML).to receive(:new).and_call_original - allow(described_class::YAML).to receive(:new) - .with(file: PDK::Util::Filesystem.expand_path(bolt_analytics_path)) - .and_raise(described_class::LoadError) - end - - it 'returns true' do - expect(config.user_config['analytics']['disabled']).to be_truthy - end - - it 'saves the disabled value to the analytics config file' do - expect(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(described_class.analytics_config_path), /disabled: true/) - config.user_config['analytics']['disabled'] - end - end - end - end - end - - describe 'user.analytics.user-id' do - context 'set' do - it 'can be set to a string that looks like a V4 UUID' do - expect { config.user_config['analytics']['user-id'] = SecureRandom.uuid }.not_to raise_error - end - - it 'can not be set to other values' do - expect { config.user_config['analytics']['user-id'] = 'totally a UUID' }.to raise_error(ArgumentError) - end - end - - def uuid_regex(uuid) - # Depending on the YAML or JSON generator, it may, or may not have quotes - /user-id: (?:#{uuid}|'#{uuid}'|"#{uuid}")/ - end - - context 'default value' do - context 'when there is no pre-existing bolt configuration' do - it 'generates a new UUID' do - expect(SecureRandom).to receive(:uuid).and_call_original - config.user_config['analytics']['user-id'] - end - - it 'saves the UUID to the analytics config file' do - new_id = SecureRandom.uuid - expect(SecureRandom).to receive(:uuid).and_return(new_id) - # Expect that the user-id is saved to the config file - expect(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(described_class.analytics_config_path), uuid_regex(new_id)) - # ... and that it returns the new id - expect(config.user_config['analytics']['user-id']).to eq(new_id) - end - end - - context 'when there is a pre-existing bolt configuration' do - let(:uuid) { SecureRandom.uuid } - let(:bolt_analytics_content) { "---\nuser-id: #{uuid}\n" } - - it 'returns the value from the bolt configuration' do - expect(config.user_config['analytics']['user-id']).to eq(uuid) - end - - it 'saves the UUID to the analytics config file' do - # Expect that the user-id is saved to the config file - expect(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(described_class.analytics_config_path), uuid_regex(uuid)) - config.user_config['analytics']['user-id'] - end - - context 'and the bolt configuration is unparsable' do - before do - allow(described_class::YAML).to receive(:new).and_call_original - allow(described_class::YAML).to receive(:new) - .with(file: PDK::Util::Filesystem.expand_path(bolt_analytics_path)) - .and_raise(described_class::LoadError) - end - - it 'generates a new UUID' do - expect(SecureRandom).to receive(:uuid).and_call_original - config.user_config['analytics']['user-id'] - end - - it 'saves the UUID to the analytics config file' do - new_id = SecureRandom.uuid - expect(SecureRandom).to receive(:uuid).and_return(new_id) - # Expect that the user-id is saved to the config file - expect(PDK::Util::Filesystem).to receive(:write_file).with(PDK::Util::Filesystem.expand_path(described_class.analytics_config_path), uuid_regex(new_id)) - # ... and that it returns the new id - expect(config.user_config['analytics']['user-id']).to eq(new_id) - end - end - end - end - end - - describe '.analytics_config_interview!' do - before do - prompt = TTY::Prompt::Test.new - allow(TTY::Prompt).to receive(:new).and_return(prompt) - prompt.input << ("#{responses.join("\r")}\r") - prompt.input.rewind - - allow(PDK::CLI::Util).to receive(:interactive?).and_return(true) - # Mock any file writing - allow(PDK::Util::Filesystem).to receive(:write_file).with(anything, anything) - end - - context 'when the user responds yes' do - let(:responses) { ['yes'] } - - it 'sets user.analytics.disabled to false' do - described_class.analytics_config_interview! - expect(PDK.config.get(['user', 'analytics', 'disabled'])).to be_falsey - end - end - - context 'when the user responds no' do - let(:responses) { ['no'] } - - it 'sets user.analytics.disabled to true' do - described_class.analytics_config_interview! - expect(PDK.config.get(['user', 'analytics', 'disabled'])).to be_truthy - end - end - - context 'when the user just hits enter' do - let(:responses) { [''] } - - it 'sets user.analytics.disabled to false' do - described_class.analytics_config_interview! - expect(PDK.config.get(['user', 'analytics', 'disabled'])).to be_falsey - end - end - - context 'when the user cancels the interview' do - let(:responses) { ["\003"] } # \003 == Ctrl-C - - it 'sets user.analytics.disabled to true' do - described_class.analytics_config_interview! - expect(PDK.config.get(['user', 'analytics', 'disabled'])).to be_truthy - end - end - end end diff --git a/spec/unit/pdk/template_spec.rb b/spec/unit/pdk/template_spec.rb index bba801741..2fb8d197e 100644 --- a/spec/unit/pdk/template_spec.rb +++ b/spec/unit/pdk/template_spec.rb @@ -47,11 +47,6 @@ it 'yields a PDK::Template::TemplateDir' do expect { |b| described_class.with(template_uri, pdk_context, &b) }.to yield_with_args(template_dir) end - - it 'sends analytics event' do - expect(PDK.analytics).to receive(:event).with('TemplateDir', 'initialize', anything) - described_class.with(template_uri, pdk_context) {} - end end end end diff --git a/spec/unit/pdk/version_spec.rb b/spec/unit/pdk/version_spec.rb index d6a579a66..006b4b793 100644 --- a/spec/unit/pdk/version_spec.rb +++ b/spec/unit/pdk/version_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'pdk/version' -describe 'PDK version string', use_stubbed_analytics: false do +describe 'PDK version string' do it 'has major minor and patch numbers' do expect(PDK::VERSION).to match(/^[0-9]+\.[0-9]+\.[0-9]+/) end