Skip to content

Instantly share code, notes, and snippets.

View bethesque's full-sized avatar
💭
Intermittently coding

Beth Skurrie bethesque

💭
Intermittently coding
View GitHub Profile
@bethesque
bethesque / index.js
Created March 31, 2022 06:02
Example of how to use Cypress and Pact together using a shared fixture
// in cypress support
const Matchers = require('@pact-foundation/pact-web').Matchers
// turn a pact definition into a cypress mock
// TODO headers, and allow safe overriding of generated fields
const toCypressInteraction = (interaction) => {
return {
method: interaction.withRequest.method,
url: Matchers.extractPayload(interaction.withRequest.path),
@bethesque
bethesque / index.md
Last active November 15, 2024 05:17
Problem solving checklist

Strategies

  • Form a mental model of the process taking place. Write it down in words or draw a diagram. Validate that each step in your model is accurate, not just the one you think is failing.
  • Another way to approach the above point - think of all the things that affect the running code, and work out which are the most likely to have an effect. Don't rule out the unexpected ones though. Think how you could test your understanding of, or rule out a problem with, each of the aspects.
    • your code (and different versions thereof)
    • other libraries (and different versions thereof)
    • application server (and different versions thereof)
    • language interpreter, compiler and/or virtual machine (and different versions thereof)
    • properties files
  • environment variables
Current definition of WIP:
No successful verifications exist for the pact content by a provider version with the specified tag.
main ref1, basePact
create branchA refA, basePact+integrationA
create branchB refB, basePact+integrationB
main provider build runs, configured to verify main pacts, and WIP pacts.
basePact (explicit), basePact+integrationA (wip), basePact+integrationB (wip) all verified successfully
basePact+integrationA and basePact+integrationB no longer WIP
@bethesque
bethesque / authorizer.js
Created February 25, 2020 03:48
API Gateway custom auth
const accountId = process.env.ACCOUNT_ID;
const region = process.env.REGION;
const basicAuthUsername = process.env.BASIC_AUTH_USERNAME;
const basicAuthPassword = process.env.BASIC_AUTH_PASSWORD;
const validateAuth = authorizationHeader => {
if (!authorizationHeader) return false;
const encodedCreds = authorizationHeader.split(" ")[1];
const plainCreds = new Buffer(encodedCreds, "base64").toString().split(":");
@bethesque
bethesque / dynamic-left-outer-join.rb
Last active December 20, 2019 01:21
Trying to achieve a dynamically filtered left outer join AND eager loading
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 / test.rb
Last active August 14, 2019 04:23
synchronous message
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 October 31, 2022 18:10
Using pact with providers that have their own providers

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 / bethtest.rb
Last active January 9, 2018 00:28
Making a request to a server with a self signed certificate
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 11:40
Moderately dirty hack to order pact versions by date instead of version in the pact broker
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 / a.md
Last active December 18, 2015 02:59
Ruby pact libraries

https://github.com/realestate-com-au/pact - rpsec specific stuff, top level, executables https://github.com/bethesque/pact-mock_service - standalone, used by javascript, starts up service, listens, writes pact, verification https://github.com/bethesque/pact-support - matching logic, domain objects https://github.com/bethesque/pact-support/blob/master/spec/pact_specification/compliance-2.0.rb - pact specification test, people might want version 3 soonish.

https://github.com/bethesque/pact-mock-service-npm - standalone package using travelling ruby https://github.com/bethesque/pact-mock_service/blob/master/tasks/package.rake - this is the task that builds the packages

https://github.com/DiUS/pact-consumer-js-dsl - the javascript DSL that wraps the ruby or standalone mock server.