hi all, I was able to use the libpact_ffi library ...
# libpact_ffi-users
p
hi all, I was able to use the libpact_ffi library and wrote a C interface on top of that for my erlang code to use ! What do y’all think of this as a pact client for erlang Example usage :
Copy code
%% pact-erlang (very pre-alpha phase right now)

%% Setup
PactRef = pact:create_new_pact(<<"consumer">>, <<"producer">>).
InteractionRef = pact:create_new_interaction(PactRef, <<"/users api desc">>).
pact:insert_request_path(InteractionRef, <<"GET">>, <<"/users">>).
ResponseJsonString = jsx:encode(#{auth_id => 1}).
pact:insert_response_body(InteractionRef, <<"application/json">>, ResponseJsonString).
pact:insert_response_status(InteractionRef, 200).
pact:create_mock_server(PactRef, <<"localhost">>, 1234, <<"http">>).

%% Sample test code
Users = user:get_users(),


%% Verify
assertEqual({ok, matched}, pact:verify_pact(1234)).


%% Write Pact File
pact:write_pact_file(PactRef, "/Users/priyaranjan.m/pacts", 0)

%% Cleanup test setup
pact:cleanup_pact_setup()
1. Not a DSL as other languages have implemented, but I believe very much usable any erlang user who wants to use pact features. 2. Haven’t implemented matchers implementation in a module as of now, but I believe its something that can be used manually using integrationjson.md page
And this only uses the libpact_ffi.a and the pact.h which will be fetched from pact-reference release page, purely written in erlang and C
👍 1
The C interface can also be used for elixir applications too, as elixir and erlang both support NIF
💪 1
@Matt (pactflow.io / pact-js / pact-go) this C interface will also solve the problem that you mentioned here in the pact-elixir thread https://docs.pact.io/slack/pact-elixir.html:
As long as Elixr can speak a c interface (which it obviously can, because that is what Rustler ultimately does) and you can add a c compatible library to your package (which it sounds like you can), I?d strongly encourage you move away from having the need for rust on a target machine
🙌 1
m
Nice! I can’t speak too much for the Erlang idiomatics, but if the user of the package doesn’t need additional dependencies to compile and install native deps, just to run Erlang/Elixir code, then this is worth the effort.
I would encourage making fuctions for the matchers etc., because they are so fundamental
👍 1
the
insert_<fn>
is a bit different to DSLs in the other languages, i’d encourage you to take a look at the latest .NET / JVM / JS / Go to get an idea
🆗 1
p
do you think dsl type syntax is neede here also, or only the naming that needs to change (from insert_<fn> to for example with_request()) ?
@Matt (pactflow.io / pact-js / pact-go) yes the user will not need any external dependency like rust / rustler.
🎉 1
m
I’m more interested in keeping the naming of functions similar to other languages. As the vast majority of examples out there today won’t be elixir/erlang, anybody searching for examples of how to do X might encounter e.g. JS, so it’s important they can have some familiarity as the move between languages
1