-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3508888
commit f4ce410
Showing
3 changed files
with
92 additions
and
9 deletions.
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
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,23 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "dependabot/logger/formats" | ||
|
||
RSpec.describe Dependabot::Logger::BasicFormatter do | ||
describe "#call" do | ||
it "returns a formatted log line" do | ||
formatter = described_class.new | ||
log_line = formatter.call("INFO", Time.now, "progname", "msg") | ||
|
||
expect(log_line).to match(%r{\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} INFO msg\n}) | ||
end | ||
|
||
it "returns a formatted log line with only a severity" do | ||
formatter = described_class.new | ||
log_line = formatter.call("ERROR", nil, nil, nil) | ||
|
||
expect(log_line).to match(%r{\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} ERROR nil\n}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "dependabot/logger/formats" | ||
|
||
RSpec.describe Dependabot::Logger::JobFormatter do | ||
describe "#new" do | ||
it "returns a formatter when provided a job_id" do | ||
formatter = described_class.new("job_id") | ||
expect(formatter).to be_a(described_class) | ||
end | ||
|
||
it "returns a formatter when provided a nil job_id" do | ||
formatter = described_class.new(nil) | ||
expect(formatter).to be_a(described_class) | ||
end | ||
end | ||
|
||
describe "#call" do | ||
let(:job_id) { "job_id" } | ||
let(:formatter) { described_class.new(job_id) } | ||
|
||
it "returns a formatted log line with a job_id" do | ||
log_line = formatter.call("INFO", Time.now, "progname", "msg") | ||
|
||
expect(log_line).to match(%r{\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} INFO <job_job_id> msg\n}) | ||
end | ||
|
||
it "returns a formatted log line with a nil job_id" do | ||
formatter = described_class.new(nil) | ||
log_line = formatter.call("INFO", Time.now, "progname", "msg") | ||
|
||
expect(log_line).to match(%r{\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} INFO <job_unknown_id> msg\n}) | ||
end | ||
|
||
it "returns a formatted log line with only a severity" do | ||
log_line = formatter.call("ERROR", nil, nil, nil) | ||
|
||
expect(log_line).to match(%r{\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} ERROR <job_job_id> nil\n}) | ||
end | ||
|
||
it "returns a formatted log line when using the CLI" do | ||
formatter = described_class.new("cli") | ||
log_line = formatter.call("ERROR", nil, nil, nil) | ||
|
||
expect(log_line).to match(%r{\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} ERROR nil\n}) | ||
end | ||
end | ||
end |