-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow integrations to be exported in dot format (text/vnd.graph…
…viz)
- Loading branch information
Showing
8 changed files
with
132 additions
and
0 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
36 changes: 36 additions & 0 deletions
36
lib/pact_broker/api/renderers/integrations_dot_renderer.rb
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,36 @@ | ||
module PactBroker | ||
module Api | ||
module Renderers | ||
class IntegrationsDotRenderer | ||
def initialize(integrations) | ||
@integrations = integrations | ||
end | ||
|
||
def self.call(integrations) | ||
new(integrations).call | ||
end | ||
|
||
def call | ||
"digraph { ranksep=3; ratio=auto; overlap=false; node [ shape = plaintext, fontname = Helvetica ]; | ||
#{integrations_graph} | ||
} | ||
" | ||
end | ||
|
||
private | ||
|
||
attr_reader :integrations | ||
|
||
def integrations_graph | ||
integrations | ||
.collect{ | integration| " #{escape_name(integration.consumer_name)} -> #{escape_name(integration.provider_name)}" } | ||
.join("\n") | ||
end | ||
|
||
def escape_name(name) | ||
name.gsub(" ", "_") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
require 'pact_broker/api/renderers/integrations_dot_renderer' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class Integrations < BaseResource | ||
def content_types_provided | ||
[["text/vnd.graphviz", :to_dot]] | ||
end | ||
|
||
def allowed_methods | ||
["GET", "OPTIONS"] | ||
end | ||
|
||
def to_dot | ||
PactBroker::Api::Renderers::IntegrationsDotRenderer.call(integrations) | ||
end | ||
|
||
def integrations | ||
pact_service.find_latest_pacts | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Integrations | ||
|
||
Allowed methods: `GET` | ||
|
||
Content types: `text/vnd.graphviz` | ||
|
||
A list of all the integrations (consumer/provider pairs) stored in the Pact Broker. |
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 @@ | ||
describe "Get integrations dot file" do | ||
before do | ||
TestDataBuilder.new | ||
.create_pact_with_hierarchy("Foo", "1", "Bar") | ||
end | ||
|
||
let(:path) { "/integrations" } | ||
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) } | ||
|
||
subject { get path, nil, {'HTTP_ACCEPT' => 'text/vnd.graphviz' }; last_response } | ||
|
||
it "returns a 200 OK" do | ||
expect(subject.status).to eq 200 | ||
end | ||
|
||
it "returns a dot file content type" do | ||
expect(subject.headers['Content-Type']).to eq 'text/vnd.graphviz;charset=utf-8' | ||
end | ||
|
||
it "returns dot file content" do | ||
expect(subject.body).to include "Foo -> Bar" | ||
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,4 @@ | ||
digraph { ranksep=3; ratio=auto; overlap=false; node [ shape = plaintext, fontname = Helvetica ]; | ||
Foo -> Bar | ||
Wiffle -> Foo_Thing | ||
} |
29 changes: 29 additions & 0 deletions
29
spec/lib/pact_broker/api/renderers/integrations_dot_renderer_spec.rb
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/api/renderers/integrations_dot_renderer' | ||
|
||
module PactBroker | ||
module Api | ||
module Renderers | ||
describe IntegrationsDotRenderer do | ||
|
||
# TODO work out how to handle apostrophes etc | ||
|
||
let(:integrations) do | ||
[ | ||
double('integration', consumer_name: "Foo", provider_name: "Bar"), | ||
double('integration', consumer_name: "Wiffle", provider_name: "Foo Thing") | ||
] | ||
end | ||
|
||
let(:expected_content) { load_fixture('expected.gv') } | ||
|
||
describe "#call" do | ||
subject { IntegrationsDotRenderer.call(integrations) } | ||
|
||
it "renders a dot file" do | ||
expect(subject).to eq expected_content | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |