{"id":17964785,"url":"https://github.com/greyorange-labs/pact_erlang","last_synced_at":"2025-03-30T04:30:43.516Z","repository":{"id":167746811,"uuid":"643362429","full_name":"greyorange-labs/pact_erlang","owner":"greyorange-labs","description":"Erlang version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.","archived":false,"fork":false,"pushed_at":"2024-07-12T08:03:36.000Z","size":1024,"stargazers_count":9,"open_issues_count":9,"forks_count":3,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-19T09:15:44.133Z","etag":null,"topics":["apis","contract-testing","erlang","erlang-nif","pact"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/pact_erlang/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greyorange-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-20T23:11:40.000Z","updated_at":"2024-11-19T11:29:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"d6a3a135-0fb6-4742-b3d7-4d168154a96d","html_url":"https://github.com/greyorange-labs/pact_erlang","commit_stats":null,"previous_names":["silverblaze404/pact_erlang","greyorange-labs/pact-erlang"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greyorange-labs%2Fpact_erlang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greyorange-labs%2Fpact_erlang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greyorange-labs%2Fpact_erlang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greyorange-labs%2Fpact_erlang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greyorange-labs","download_url":"https://codeload.github.com/greyorange-labs/pact_erlang/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246277352,"owners_count":20751548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apis","contract-testing","erlang","erlang-nif","pact"],"created_at":"2024-10-29T12:08:38.360Z","updated_at":"2025-03-30T04:30:43.194Z","avatar_url":"https://github.com/greyorange-labs.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pact Erlang\n=====\n\n![Build Status](https://github.com/greyorange-labs/pact_erlang/actions/workflows/erlang.yml/badge.svg?event=push)\n[![Code Coverage](https://codecov.io/gh/greyorange-labs/pact_erlang/branch/develop/graph/badge.svg?token=9F8XCB1TBR)](https://codecov.io/gh/greyorange-labs/pact_erlang)\n[![Hex Version](https://img.shields.io/hexpm/v/pact_erlang.svg)](https://hex.pm/packages/pact_erlang)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/pact_erlang/)\n[![Total Download](https://img.shields.io/hexpm/dt/pact_erlang.svg)](https://hex.pm/packages/pact_erlang)\n[![License](https://img.shields.io/hexpm/l/pact_erlang.svg)](https://github.com/greyorange-labs/pact_erlang/blob/develop/LICENSE)\n\n\nAn erlang library for contract testing using pact ffi and generating consumer pacts.\n\nThis library should be considered alpha quality. It is not yet feature complete and the API is subject to change.\n\nDocs: https://hexdocs.pm/pact_erlang \\\nChangelog: https://hexdocs.pm/pact_erlang/changelog.html\n\nBuild\n-----\n\n    $ make\n\n\nAdd pact-erlang as a dependency in your application\n---------------------------------------------------\n```\n{deps, [pact_erlang]}.\n```\n\nUsage\n-----\n\nCheck the test folder for an example end-to-end scenario including consumer and producer checks.\n\n```erlang\n%% Setup\n%% Define pact consumer and producer\nPactRef = pact:v4(\u003c\u003c\"consumer\"\u003e\u003e, \u003c\u003c\"producer\"\u003e\u003e).\n\n%% Define the interaction, returns running mock server port\n{ok, Port} = pact:interaction(PactRef,\n    #{\n        given =\u003e #{\n            state =\u003e \u003c\u003c\"a user ranjan exists\"\u003e\u003e\n        },\n        upon_receiving =\u003e \u003c\u003c\"get all users\"\u003e\u003e,\n        with_request =\u003e #{\n            method =\u003e \u003c\u003c\"GET\"\u003e\u003e,\n            path =\u003e \u003c\u003c\"/users\"\u003e\u003e\n        },\n        will_respond_with =\u003e #{\n            status =\u003e 200,\n            headers =\u003e #{\n                \u003c\u003c\"Content-Type\"\u003e\u003e =\u003e \u003c\u003c\"application/json\"\u003e\u003e\n            },\n            body =\u003e #{users =\u003e [#{user_id =\u003e 1, user_name =\u003e \u003c\u003c\"ranjan\"\u003e\u003e, age =\u003e 26}]}\n        }\n    }).\n\n\n%% test your code which calls the api\nUsers = user:get_users(\u003c\u003c\"127.0.0.1\"\u003e\u003e, Port).\n\n\n%% Verify if everything matched successfully\nassertEqual({ok, matched}, pact:verify(PactRef)).\n\n%% Should write pact file if matched, creates a new folder `pacts'\n%% and writes the pact file inside it.\npact:write(PactRef).\n\n%% Alternatively, one can override the default pacts directory path\npact:write(PactRef, \"/path/to/pacts\").\n\n%% Cleanup test setup\n%% This won't cleanup the pact files, only the pact ref you created in the test setup\npact:cleanup(PactRef).\n```\n\nMessage pacts usage\n-------------------\n\n```erlang\n\nPactRef = pact:v4(\u003c\u003c\"animal_service\"\u003e\u003e, \u003c\u003c\"weather_service\"\u003e\u003e),\n\nMessage = pact:like(#{\n    weather =\u003e #{\n        temperature =\u003e 23.0,\n        humidity =\u003e 75.5,\n        wind_speed_kmh =\u003e 29\n    },\n    timestamp =\u003e \u003c\u003c\"2024-03-14T10:22:13+05:30\"\u003e\u003e\n}),\nTestMessage = pact:msg_interaction(PactRef,\n#{\n    given =\u003e \u003c\u003c\"weather data for animals\"\u003e\u003e,\n    upon_receiving =\u003e \u003c\u003c\"a weather data message\"\u003e\u003e,\n    with_contents =\u003e Message\n}),\n#{\u003c\u003c\"contents\"\u003e\u003e := TestMessageContents} = TestMessage,\n?assertMatch(ok, animal_service:process_weather_data(TestMessageContents)),\npact:write(PactRef).\n\n```\n\n\nPact verification\n-----------------\n\n```erlang\n\nName = \u003c\u003c\"weather_service\"\u003e\u003e,\nVersion =  \u003c\u003c\"default\"\u003e\u003e,\nScheme = \u003c\u003c\"http\"\u003e\u003e,\nHost = \u003c\u003c\"localhost\"\u003e\u003e,\nPath = \u003c\u003c\"/message_pact/verify\"\u003e\u003e,\nBranch = \u003c\u003c\"develop\"\u003e\u003e,\nFilePath = \u003c\u003c\"./pacts\"\u003e\u003e,\nWrongFilePath = \u003c\u003c\"./pactss\"\u003e\u003e,\nBrokerUrl = \u003c\u003c\"http://localhost:9292/\"\u003e\u003e,\nWrongBrokerUrl = \u003c\u003c\"http://localhost:8282/\"\u003e\u003e,\nProtocol = \u003c\u003c\"message\"\u003e\u003e,\nBrokerConfigs = #{\n    broker_url =\u003e BrokerUrl,\n    broker_username =\u003e \u003c\u003c\"pact_workshop\"\u003e\u003e,\n    broker_password =\u003e \u003c\u003c\"pact_workshop\"\u003e\u003e,\n    enable_pending =\u003e 1,\n    consumer_version_selectors =\u003e thoas:encode(#{})\n},\nProviderOpts = #{\n    name =\u003e Name,\n    version =\u003e Version,\n    scheme =\u003e Scheme,\n    host =\u003e Host,\n    base_url =\u003e Path,\n    branch =\u003e Branch,\n    pact_source_opts =\u003e BrokerConfigs,\n    message_providers =\u003e #{\n        \u003c\u003c\"a weather data message\"\u003e\u003e =\u003e {weather_service, generate_message, [23.5, 20, 75.0]}\n    },\n    fallback_message_provider =\u003e {weather_service, generate_message, [24.5, 20, 93.0]},\n    protocol =\u003e Protocol\n},\n{ok, VerfierRef} = pact_verifier:start_verifier(Name, ProviderOpts),\nOutput = pact_verifier:verify(VerfierRef).\n%% or you can use the verify_v2/1 which returns logs of file and url based %% pacts\n{Output, OutputLog1, OutputLog2} = pact_verifier:verify_v2(VerfierRef)\n\n```\n\n\nMatching request path and request/response headers, and body values\n-----\n\n```erlang\n%% Alternatively, you can also match things inside each request/response\npact:interaction(PactRef,\n    #{\n        upon_receiving =\u003e \u003c\u003c\"a request to create an animal: Lazgo\"\u003e\u003e,\n        with_request =\u003e #{\n            method =\u003e \u003c\u003c\"POST\"\u003e\u003e,\n            path =\u003e \u003c\u003c\"/animals\"\u003e\u003e,\n            headers =\u003e #{\n                \u003c\u003c\"Content-Type\"\u003e\u003e =\u003e \u003c\u003c\"application/json\"\u003e\u003e\n            },\n            body =\u003e #{\n                \u003c\u003c\"name\"\u003e\u003e =\u003e pact:like(\u003c\u003c\"Lazgo\"\u003e\u003e),\n                \u003c\u003c\"type\"\u003e\u003e =\u003e pact:like(\u003c\u003c\"dog\"\u003e\u003e)\n            }\n        },\n        will_respond_with =\u003e #{\n            status =\u003e 201\n        }\n    })\n```\n\nRelease Checklist\n-----\n\n- Update version in `src/pact_erlang.app.src`\n- Update CHANGELOG.md\n- Run `rebar3 hex publish --dry-run` and make sure there are no un-intended files in included files\n- Commit files, add a git tag matching the new version, and push to remote\n- Run `rebar3 hex publish` to publish\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreyorange-labs%2Fpact_erlang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreyorange-labs%2Fpact_erlang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreyorange-labs%2Fpact_erlang/lists"}