-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added tests for utils/analytics #2952
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4d4da6
Added tests for os_prefix_ci
mansimarkaur 2660f5a
Added tests for report and report_event
mansimarkaur a4d8d7b
Added tests for report_build_error
mansimarkaur 59f3c66
Used ENV.delete to remove set ENV vars
mansimarkaur 413d35b
Added clear_anonymous_os_prefix_ci_cache
mansimarkaur db28126
Used clear_anonymous_os_prefix_ci_cache to remove @anonymous_os_prefi…
mansimarkaur 1dd7e9d
Modified clear_anonymous_os_prefix_ci_cache
mansimarkaur File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require "utils/analytics" | ||
require "formula_installer" | ||
|
||
describe Utils::Analytics do | ||
describe "::os_prefix_ci" do | ||
context "when anonymous_os_prefix_ci is not set" do | ||
before(:each) do | ||
described_class.clear_anonymous_os_prefix_ci_cache | ||
end | ||
|
||
it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do | ||
stub_const("HOMEBREW_PREFIX", "blah") | ||
expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") | ||
end | ||
|
||
it "includes CI when ENV['CI'] is set" do | ||
ENV["CI"] = "true" | ||
expect(described_class.os_prefix_ci).to include("CI") | ||
end | ||
|
||
it "does not include prefix when HOMEBREW_PREFIX is /usr/local" do | ||
stub_const("HOMEBREW_PREFIX", "/usr/local") | ||
expect(described_class.os_prefix_ci).not_to include("non-/usr/local") | ||
end | ||
end | ||
end | ||
|
||
describe "::report_event" do | ||
let(:f) { formula { url "foo-1.0" } } | ||
let(:options) { FormulaInstaller.new(f).display_options(f) } | ||
let(:action) { "#{f.full_name} #{options}".strip } | ||
|
||
context "when ENV vars is set" do | ||
it "returns nil when HOMEBREW_NO_ANALYTICS is true" do | ||
ENV["HOMEBREW_NO_ANALYTICS"] = "true" | ||
expect(described_class.report_event("install", action)).to be_nil | ||
end | ||
|
||
it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do | ||
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true" | ||
expect(described_class.report_event("install", action)).to be_nil | ||
end | ||
|
||
it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do | ||
ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") | ||
ENV.delete("HOMEBREW_NO_ANALYTICS") | ||
ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" | ||
expect(described_class.report_event("install", action)).to be_nil | ||
end | ||
end | ||
end | ||
|
||
describe "::report_build_error" do | ||
context "when tap is installed" do | ||
let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } | ||
let(:f) { formula { url "foo-1.0" } } | ||
|
||
it "reports event if BuildError raised for a formula with a public remote repository" do | ||
allow_any_instance_of(Tap).to receive(:custom_remote?).and_return(false) | ||
expect(described_class).to respond_to(:report_event) | ||
described_class.report_build_error(err) | ||
end | ||
|
||
it "does not report event if BuildError raised for a formula with a private remote repository" do | ||
expect(described_class.report_build_error(err)).to be_nil | ||
end | ||
end | ||
|
||
context "when formula does not have a tap" do | ||
let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } | ||
let(:f) { double(Formula, name: "foo", path: "blah", tap: nil) } | ||
|
||
it "does not report event if BuildError is raised" do | ||
expect(described_class.report_build_error(err)).to be_nil | ||
end | ||
end | ||
|
||
context "when tap for a formula is not installed" do | ||
let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } | ||
let(:f) { double(Formula, name: "foo", path: "blah", tap: CoreTap.instance) } | ||
|
||
it "does not report event if BuildError is raised" do | ||
allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) | ||
expect(described_class.report_build_error(err)).to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure this gets restored at the end of the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENV is already reset automatically after every test, so, it will get restored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍