Skip to content

Commit

Permalink
Github Actions (#112)
Browse files Browse the repository at this point in the history
* Swap to Github Actions

* update

* mix format

* add dialyzer
  • Loading branch information
samhamilton committed Aug 2, 2023
1 parent e25b838 commit ff79c38
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 25 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Elixir CI

on: push

env:
MIX_ENV: test

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
elixir: ["1.13", "1.14", "1.15"]
otp: ["25", "26"]
exclude:
- elixir: 1.13
otp: 26
- elixir: 1.14
otp: 26

steps:
- uses: actions/checkout@v3

- name: Setup elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Restore dependencies cache
uses: actions/cache@v3
id: mix-cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}

- name: Install dependencies
if: steps.mix-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Compile & error on warning
run: mix compile --warnings-as-errors

- name: Check formatting
run: mix format --check-formatted

- name: Run credo
run: mix credo --strict

- name: Retrieve PLT cache
uses: actions/cache@v3
id: plt-cache
with:
path: priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}

- name: Create PLTs
if: steps.plt-cache.outputs.cache-hit != 'true'
run: |
mkdir -p priv/plts
mix dialyzer --plt
- name: Run dialyzer
run: mix dialyzer --no-check --halt-exit-status

- name: Run tests
run: mix coveralls.github
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

7 changes: 3 additions & 4 deletions lib/soap/request/params.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmodule Soap.Request.Params do
Returns XML-like string.
"""

@spec build_body(wsdl :: map(), operation :: String.t() | atom(), params :: map() | tuple(), headers :: map()) :: String.t()
@spec build_body(wsdl :: map(), operation :: String.t() | atom(), params :: map() | tuple(), headers :: map()) ::
String.t()
def build_body(wsdl, operation, params, headers) do
with {:ok, body} <- build_soap_body(wsdl, operation, params),
{:ok, header} <- build_soap_header(wsdl, operation, headers) do
Expand Down Expand Up @@ -75,9 +76,7 @@ defmodule Soap.Request.Params do
if Map.has_key?(val_map, k) do
validate_param_attributes(val_map, k, v)
else
"Invalid SOAP message:Invalid content was found starting with element '#{k}'. One of {#{
Enum.join(Map.keys(val_map), ", ")
}} is expected."
"Invalid SOAP message:Invalid content was found starting with element '#{k}'. One of {#{Enum.join(Map.keys(val_map), ", ")}} is expected."
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/soap/wsdl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ defmodule Soap.Wsdl do

xpath(
wsdl,
~x"//#{ns("types", protocol_ns)}/#{ns("schema", schema_namespace)}/#{ns("import", schema_namespace)}[@namespace='#{
value
}']"
~x"//#{ns("types", protocol_ns)}/#{ns("schema", schema_namespace)}/#{ns("import", schema_namespace)}[@namespace='#{value}']"

Check warning on line 79 in lib/soap/wsdl.ex

View workflow job for this annotation

GitHub Actions / build (1.13, 25)

Line is too long (max is 120, was 132).

Check warning on line 79 in lib/soap/wsdl.ex

View workflow job for this annotation

GitHub Actions / build (1.14, 25)

Line is too long (max is 120, was 132).

Check warning on line 79 in lib/soap/wsdl.ex

View workflow job for this annotation

GitHub Actions / build (1.15, 25)

Line is too long (max is 120, was 132).
) ->
{string_key, %{value: value, type: :xsd}}

Expand All @@ -91,9 +89,7 @@ defmodule Soap.Wsdl do
def get_endpoint(wsdl, protocol_ns, soap_ns) do
wsdl
|> xpath(
~x"//#{ns("definitions", protocol_ns)}/#{ns("service", protocol_ns)}/#{ns("port", protocol_ns)}/#{
ns("address", soap_ns)
}/@location"s
~x"//#{ns("definitions", protocol_ns)}/#{ns("service", protocol_ns)}/#{ns("port", protocol_ns)}/#{ns("address", soap_ns)}/@location"s

Check warning on line 92 in lib/soap/wsdl.ex

View workflow job for this annotation

GitHub Actions / build (1.13, 25)

Line is too long (max is 120, was 139).

Check warning on line 92 in lib/soap/wsdl.ex

View workflow job for this annotation

GitHub Actions / build (1.14, 25)

Line is too long (max is 120, was 139).

Check warning on line 92 in lib/soap/wsdl.ex

View workflow job for this annotation

GitHub Actions / build (1.15, 25)

Line is too long (max is 120, was 139).
)
end

Expand Down
1 change: 1 addition & 0 deletions lib/soap/xsd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule Soap.Xsd do
@spec parse_from_url(String.t(), keyword()) :: {:ok, map()} | {:error, atom()}
def parse_from_url(path, opts \\ []) do
request_opts = Keyword.merge([follow_redirect: true, max_redirect: 5], opts)

case Request.get_http_client().get(path, [], request_opts) do
{:ok, %HTTPoison.Response{status_code: 404}} -> {:error, :not_found}
{:ok, %HTTPoison.Response{body: body}} -> parse_xsd(body)
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"mock": {:hex, :mock, "0.3.7", "75b3bbf1466d7e486ea2052a73c6e062c6256fb429d6797999ab02fa32f29e03", [:mix], [{:meck, "~> 0.9.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "4da49a4609e41fd99b7836945c26f373623ea968cfb6282742bcb94440cf7e5c"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"sweet_xml": {:hex, :sweet_xml, "0.7.2", "4729f997286811fabdd8288f8474e0840a76573051062f066c4b597e76f14f9f", [:mix], [], "hexpm", "6894e68a120f454534d99045ea3325f7740ea71260bc315f82e29731d570a6e8"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"xml_builder": {:hex, :xml_builder, "2.2.0", "cc5f1eeefcfcde6e90a9b77fb6c490a20bc1b856a7010ce6396f6da9719cbbab", [:mix], [], "hexpm", "9d66d52fb917565d358166a4314078d39ef04d552904de96f8e73f68f64a62c9"},
Expand Down
14 changes: 12 additions & 2 deletions test/soap/request/params_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,20 @@ defmodule Soap.Request.ParamsTest do
xml_body =
"runTransaction-template.xml"
|> Fixtures.load_xml()
|> String.replace("{{BODY}}", ~s{<test><Person id="something"><firstName>Joe</firstName><lastName>Dirt</lastName></Person></test>})
|> String.replace(
"{{BODY}}",
~s{<test><Person id="something"><firstName>Joe</firstName><lastName>Dirt</lastName></Person></test>}
)

{_, wsdl} = Wsdl.parse_from_file(Fixtures.get_file_path("wsdl/CyberSourceTransaction.wsdl"))
function_result = Params.build_body(wsdl, "runTransaction", %{test: {:Person, %{id: "something"}, %{firstName: "Joe", lastName: "Dirt"}}}, nil)

function_result =
Params.build_body(
wsdl,
"runTransaction",
%{test: {:Person, %{id: "something"}, %{firstName: "Joe", lastName: "Dirt"}}},
nil
)

assert function_result == xml_body
end
Expand Down
3 changes: 2 additions & 1 deletion test/soap/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ defmodule Soap.RequestTest do
params = {%{token: "barbaz"}, {:body, %{foo: "bar"}, "Hello John"}}

with_mock HTTPoison, post: fn _, body, _, _ -> body end do
assert Request.call(wsdl, operation, params) == String.replace(@request_with_header, "<body>", ~s{<body foo="bar">})
assert Request.call(wsdl, operation, params) ==
String.replace(@request_with_header, "<body>", ~s{<body foo="bar">})
end
end
end

0 comments on commit ff79c38

Please sign in to comment.