forked from pact-foundation/pact_broker-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: output table of verification results when present
- Loading branch information
Showing
9 changed files
with
130 additions
and
11 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,31 @@ | ||
require 'table_print' | ||
|
||
module PactBroker | ||
module Client | ||
class MatrixTextFormatter | ||
Line = Struct.new(:consumer, :consumer_version, :pact_publication_date, :provider, :provider_version, :verification_date) | ||
|
||
def self.call(matrix_lines) | ||
data = matrix_lines.collect do | line | | ||
Line.new( | ||
lookup(line, :consumer, :name), | ||
lookup(line, :consumer, :version, :number), | ||
lookup(line, :pact, :createdAt), | ||
lookup(line, :consumer, :name), | ||
lookup(line, :provider, :version, :number), | ||
lookup(line, :verification, :executedAt), | ||
) | ||
end | ||
|
||
printer = TablePrint::Printer.new(data) | ||
printer.table_print | ||
end | ||
|
||
def self.lookup line, *keys | ||
keys.reduce(line) { | line, key | line[key] } | ||
rescue NoMethodError | ||
"???" | ||
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
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,29 @@ | ||
require 'pact_broker/client/matrix_text_formatter' | ||
|
||
module PactBroker | ||
module Client | ||
describe MatrixTextFormatter do | ||
let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true) } | ||
let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') } | ||
|
||
# SublimeText removes whitespace from the end of files when you save them, | ||
# so removing trailing whitespace before comparing | ||
subject { MatrixTextFormatter.call(matrix_lines).split("\n").collect(&:strip).join("\n") } | ||
|
||
context "with valid data" do | ||
it "it has the right text" do | ||
expect(subject).to eq expected_matrix_lines | ||
end | ||
end | ||
|
||
context "with invalid data" do | ||
let(:expected_matrix_lines) { File.read('spec/support/matrix_error.txt') } | ||
let(:matrix_lines) { [{}] } | ||
|
||
it "doesn't blow up" do | ||
expect(subject).to eq expected_matrix_lines | ||
end | ||
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
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,22 @@ | ||
[ | ||
{ | ||
"consumer": { | ||
"name": "Foo", | ||
"version": { | ||
"number": "4" | ||
} | ||
}, | ||
"provider": { | ||
"name": "Bar", | ||
"version": { | ||
"number": "5" | ||
} | ||
}, | ||
"verification": { | ||
"executedAt": "2017-10-10T12:49:04+11:00" | ||
}, | ||
"pact": { | ||
"createdAt": "2017-10-10T12:49:04+11:00" | ||
} | ||
} | ||
] |
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,3 @@ | ||
CONSUMER | CONSUMER_VERSION | PACT_PUBLICATION_DATE | PROVIDER | PROVIDER_VERSION | VERIFICATION_DATE | ||
---------|------------------|---------------------------|----------|------------------|-------------------------- | ||
Foo | 4 | 2017-10-10T12:49:04+11:00 | Foo | 5 | 2017-10-10T12:49:04+11:00 |
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,3 @@ | ||
CONSUMER | CONSUMER_VERSION | PACT_PUBLICATION_DATE | PROVIDER | PROVIDER_VERSION | VERIFICATION_DATE | ||
---------|------------------|-----------------------|----------|------------------|------------------ | ||
??? | ??? | ??? | ??? | ??? | ??? |