Skip to content

Instantly share code, notes, and snippets.

💭
Intermittently coding

Beth Skurrie bethesque

💭
Intermittently coding
Block or report user

Report or block bethesque

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bethesque
bethesque / dynamic-left-outer-join.rb
Last active Dec 20, 2019
Trying to achieve a dynamically filtered left outer join AND eager loading
View dynamic-left-outer-join.rb
require 'spec_helper'
require 'sequel'
DATABASE = Sequel::Model.db
DATABASE.drop_table(:orders) rescue nil
DATABASE.drop_table(:order_lines) rescue nil
DATABASE.drop_table(:customers) rescue nil
DATABASE.create_table(:customers) do
@bethesque
bethesque / a_readme.md
Last active Dec 16, 2019
Using Pact with non-HTTP services
View a_readme.md

When you declare a request and response using the traditional Pact DSL, ("uponReceiving" and "willRespondWith") you're building a structure that has three purposes -

  1. it provides the concrete example request and response used in the tests
  2. it specifies the contents of the contract which...
  3. defines how to validate the the actual request/response against the expected request/response

The three different uses of this structure are hidden from you when using HTTP Pact because the mock service handles numbers 1 & 2 in the consumer tests, and the verification task handles number 3 for you in the provider tests. When using Pact in a non-HTTP scenario, there is no nice neat protocol layer to inject the code to do this for you, so you have to explicitly do each step.

The file expected_data_from_collector.rb declares an object graph using the Pact DSL. This is going to be used to create the concrete example and the contract. This could be declared inline, but for easier maintenance, and to allow the contr

@bethesque
bethesque / test.rb
Last active Aug 14, 2019
synchronous message
View test.rb
some_provider.given("a thing", "foo" => "bar")
.and("another thing", "blah" => "blah")
.upon_receiving("some message")
.with(
contents: {"the" => "contents"},
metadata: {"some" => "info"})
.will_respond_with(
contents: {"the" => "response"},
metadata: {"some" => "other info"}
)
@bethesque
bethesque / index.md
Last active Jul 31, 2019
Using pact with providers that have their own providers
View index.md

Eg. A -> B -> C

A more find grained view of this intergration might go:

|------------------A Codebase------------------||------------------B Codebase------------------||--------C Codebase---...
 A UI -> A Controller -> B Service -> B Client -> B API -> B Controller -> CService -> CClient -> C API etc...  
                                           |---A/B pact------------------------?
                                           |---A/B pact------------------------------------?
@bethesque
bethesque / migrate.rb
Last active Nov 26, 2018
Migrate pacts from one pact broker to another
View migrate.rb
# Note: this does not migrate the tags
require 'faraday'
require 'json'
source_host = 'http://some-pact-broker'
destination_host = 'http://localhost:9292'
latest_pacts_response = JSON.parse(Faraday.get("#{source_host}/pacts/latest").body)
pact_hrefs = latest_pacts_response['pacts'].collect{ | pact | pact['_links']['self'][1]['href'] }
@bethesque
bethesque / 1.sh
Last active Jul 10, 2018
HTTP requests to ruby mock server
View 1.sh
You will need ruby or the standalone mock service to run these examples.
$ gem install pact-mock_service
@bethesque
bethesque / bethtest.rb
Last active Jan 9, 2018
Making a request to a server with a self signed certificate
View bethtest.rb
require 'openssl'
require 'uri'
require 'net/http'
uri = URI('https://self-signed.badssl.com')
downloaded_cert_path = '/tmp/downloaded_cert.pem'
puts `openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -text`
command = "openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -outform PEM > #{downloaded_cert_path}"
puts command
@bethesque
bethesque / caveats.txt
Last active May 5, 2017
Moderately dirty hack to order pact versions by date instead of version in the pact broker
View caveats.txt
This will sort based on the date that the consumer application version resource is created.
If the pact for that version is updated, the sorting will not consider the date of the updated content.
@bethesque
bethesque / reverse_proxy.rb
Created Jul 8, 2015
Debug pact-provider-proxy
View reverse_proxy.rb
# pact-provider-proxy/vendor/rack-reverse-proxy/lib/rack/reverse_proxy.rb
require 'net/http'
require 'net/https'
require "rack-proxy"
require "rack/reverse_proxy_matcher"
require "rack/exception"
module Rack
class ReverseProxy
@bethesque
bethesque / hipster-batch-in-ruby.md
Last active May 2, 2016
A way to write a hipster batch microservice in Ruby
View hipster-batch-in-ruby.md
  1. Identify the steps in the high level process

    eg.

    • Step 1: Download CSV files from box
    • Step 2: Convert CSV to JSON
    • Step 3: Upload JSON and CSV files to S3
  2. Create modules for each of those steps. In our use case, the top level process matches a pattern called "ETL" or "Extract, Transform, Load", so we used those names.

You can’t perform that action at this time.