mirror of
https://github.com/valitydev/payproc-errors-erlang.git
synced 2024-11-06 01:25:17 +00:00
TD-312: Switch to valitydev/damsel@dac2cb5 (#1)
* Drop proprietary CI stuff * Sync with valitydev/erlang-templates@da1971c * Add CI workflow
This commit is contained in:
parent
ebbfa3775c
commit
a19e716966
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@ -0,0 +1,8 @@
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
||||
max_line_length = 120
|
3
.env
Normal file
3
.env
Normal file
@ -0,0 +1,3 @@
|
||||
OTP_VERSION=24.3.4
|
||||
REBAR_VERSION=3.18
|
||||
THRIFT_VERSION=0.14.2.3
|
38
.github/workflows/erlang-checks.yml
vendored
Normal file
38
.github/workflows/erlang-checks.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
name: Erlang CI Checks
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'epic/**'
|
||||
pull_request:
|
||||
branches: ['**']
|
||||
|
||||
jobs:
|
||||
setup:
|
||||
name: Load .env
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
otp-version: ${{ steps.otp-version.outputs.version }}
|
||||
rebar-version: ${{ steps.rebar-version.outputs.version }}
|
||||
thrift-version: ${{ steps.thrift-version.outputs.version }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- run: grep -v '^#' .env >> $GITHUB_ENV
|
||||
- id: otp-version
|
||||
run: echo "::set-output name=version::$OTP_VERSION"
|
||||
- id: rebar-version
|
||||
run: echo "::set-output name=version::$REBAR_VERSION"
|
||||
- id: thrift-version
|
||||
run: echo "::set-output name=version::$THRIFT_VERSION"
|
||||
|
||||
run:
|
||||
name: Run checks
|
||||
needs: setup
|
||||
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.3
|
||||
with:
|
||||
otp-version: ${{ needs.setup.outputs.otp-version }}
|
||||
rebar-version: ${{ needs.setup.outputs.rebar-version }}
|
||||
use-thrift: true
|
||||
thrift-version: ${{ needs.setup.outputs.thrift-version }}
|
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,12 +1,13 @@
|
||||
# general
|
||||
log
|
||||
/.rebar3/
|
||||
# Build artifacts
|
||||
/_build/
|
||||
/_checkouts/
|
||||
*~
|
||||
erl_crash.dump
|
||||
.tags*
|
||||
*.sublime-workspace
|
||||
.DS_Store
|
||||
/.idea/
|
||||
*.o
|
||||
*.beam
|
||||
*.plt
|
||||
|
||||
# Run artifacts
|
||||
erl_crash.dump
|
||||
log
|
||||
|
||||
# make stuff
|
||||
/.image.*
|
||||
Makefile.env
|
||||
|
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -1,4 +0,0 @@
|
||||
[submodule "build_utils"]
|
||||
path = build_utils
|
||||
url = git@github.com:rbkmoney/build_utils.git
|
||||
branch = master
|
17
Dockerfile.dev
Normal file
17
Dockerfile.dev
Normal file
@ -0,0 +1,17 @@
|
||||
ARG OTP_VERSION
|
||||
|
||||
FROM docker.io/library/erlang:${OTP_VERSION}
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
# Install thrift compiler
|
||||
ARG THRIFT_VERSION
|
||||
ARG TARGETARCH
|
||||
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \
|
||||
| tar -xvz -C /usr/local/bin/
|
||||
|
||||
# Set env
|
||||
ENV CHARSET=UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
|
||||
# Set runtime
|
||||
CMD ["/bin/bash"]
|
27
Jenkinsfile
vendored
27
Jenkinsfile
vendored
@ -1,27 +0,0 @@
|
||||
#!groovy
|
||||
// -*- mode: groovy -*-
|
||||
|
||||
def finalHook = {
|
||||
runStage('store CT logs') {
|
||||
archive '_build/test/logs/'
|
||||
}
|
||||
}
|
||||
|
||||
build('payproc-errors-erlang', 'docker-host', finalHook) {
|
||||
checkoutRepo()
|
||||
loadBuildUtils()
|
||||
|
||||
def pipeErlangLib
|
||||
runStage('load pipeline') {
|
||||
env.JENKINS_LIB = "build_utils/jenkins_lib"
|
||||
env.SH_TOOLS = "build_utils/sh"
|
||||
pipeErlangLib = load("${env.JENKINS_LIB}/pipeErlangLib.groovy")
|
||||
}
|
||||
|
||||
// NOTE: Parallel pipeline almost always fails because of
|
||||
// rebar3's design (it uses link for libraries, so
|
||||
// parallel runs with different profiles brake each other)
|
||||
// To prevent this use sequential pipleine here
|
||||
|
||||
pipeErlangLib.runPipe(false)
|
||||
}
|
102
Makefile
102
Makefile
@ -1,61 +1,93 @@
|
||||
REBAR := $(shell which rebar3 2>/dev/null || which ./rebar3)
|
||||
SUBMODULES = build_utils
|
||||
SUBTARGETS = $(patsubst %,%/.git,$(SUBMODULES))
|
||||
# HINT
|
||||
# Use this file to override variables here.
|
||||
# For example, to run with podman put `DOCKER=podman` there.
|
||||
-include Makefile.env
|
||||
|
||||
UTILS_PATH := build_utils
|
||||
TEMPLATES_PATH := .
|
||||
# NOTE
|
||||
# Variables specified in `.env` file are used to pick and setup specific
|
||||
# component versions, both when building a development image and when running
|
||||
# CI workflows on GH Actions. This ensures that tasks run with `wc-` prefix
|
||||
# (like `wc-dialyze`) are reproducible between local machine and CI runners.
|
||||
DOTENV := $(shell grep -v '^\#' .env)
|
||||
|
||||
# Name of the service (I don't know why is needed by build_utils!)
|
||||
SERVICE_NAME := payproc-errors-erlang
|
||||
|
||||
# Build image tag to be used
|
||||
BUILD_IMAGE_TAG := 917afcdd0c0a07bf4155d597bbba72e962e1a34a
|
||||
|
||||
CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze clean distclean check_format format
|
||||
|
||||
CALL_W_CONTAINER := $(CALL_ANYWHERE) test
|
||||
DOCKER ?= docker
|
||||
REBAR ?= rebar3
|
||||
|
||||
all: compile
|
||||
|
||||
-include $(UTILS_PATH)/make_lib/utils_container.mk
|
||||
# Development images
|
||||
|
||||
.PHONY: $(CALL_W_CONTAINER)
|
||||
DEV_IMAGE_TAG = payproc-errors-dev
|
||||
DEV_IMAGE_ID = $(file < .image.dev)
|
||||
|
||||
# CALL_ANYWHERE
|
||||
$(SUBTARGETS): %/.git: %
|
||||
git submodule update --init $<
|
||||
touch $@
|
||||
.PHONY: dev-image clean-dev-image wc-shell test
|
||||
|
||||
submodules: $(SUBTARGETS)
|
||||
dev-image: .image.dev
|
||||
|
||||
rebar-update:
|
||||
$(REBAR) update
|
||||
.image.dev: Dockerfile.dev .env
|
||||
$(DOCKER) build . -f Dockerfile.dev --tag $(DEV_IMAGE_TAG) $(DOTENV:%=--build-arg %)
|
||||
$(DOCKER) image ls -q -f "reference=$(DEV_IMAGE_TAG)" | head -n1 > $@
|
||||
|
||||
compile: submodules rebar-update
|
||||
clean-dev-image:
|
||||
ifneq ($(DEV_IMAGE_ID),)
|
||||
$(DOCKER) image rm -f $(DEV_IMAGE_TAG)
|
||||
rm .image.dev
|
||||
endif
|
||||
|
||||
DOCKER_WC_OPTIONS := -v $(PWD):$(PWD) --workdir $(PWD)
|
||||
DOCKER_WC_EXTRA_OPTIONS ?= --rm
|
||||
DOCKER_RUN = $(DOCKER) run -t $(DOCKER_WC_OPTIONS) $(DOCKER_WC_EXTRA_OPTIONS)
|
||||
|
||||
# Utility tasks
|
||||
|
||||
wc-shell: dev-image
|
||||
$(DOCKER_RUN) --interactive --tty $(DEV_IMAGE_TAG)
|
||||
|
||||
wc-%: dev-image
|
||||
$(DOCKER_RUN) $(DEV_IMAGE_TAG) make $*
|
||||
|
||||
# Rebar tasks
|
||||
|
||||
rebar-shell:
|
||||
$(REBAR) shell
|
||||
|
||||
compile:
|
||||
$(REBAR) compile
|
||||
|
||||
xref: submodules
|
||||
xref:
|
||||
$(REBAR) xref
|
||||
|
||||
lint:
|
||||
elvis rock
|
||||
$(REBAR) lint
|
||||
|
||||
check_format:
|
||||
check-format:
|
||||
$(REBAR) fmt -c
|
||||
|
||||
dialyze:
|
||||
$(REBAR) as test dialyzer
|
||||
|
||||
release:
|
||||
$(REBAR) as prod release
|
||||
|
||||
eunit:
|
||||
$(REBAR) eunit --cover
|
||||
|
||||
common-test:
|
||||
$(REBAR) ct --cover
|
||||
|
||||
cover:
|
||||
$(REBAR) covertool generate
|
||||
|
||||
format:
|
||||
$(REBAR) fmt -w
|
||||
|
||||
dialyze: submodules
|
||||
$(REBAR) dialyzer
|
||||
|
||||
clean:
|
||||
$(REBAR) clean
|
||||
|
||||
distclean:
|
||||
$(REBAR) clean -a
|
||||
distclean: clean-build-image
|
||||
rm -rf _build
|
||||
|
||||
# CALL_W_CONTAINER
|
||||
test: submodules
|
||||
$(REBAR) ct
|
||||
test: eunit common-test
|
||||
|
||||
cover-report:
|
||||
$(REBAR) cover
|
||||
|
46
README.md
46
README.md
@ -1,2 +1,44 @@
|
||||
# payproc-errors-erlang
|
||||
Payment processing errors erlang library
|
||||
# Payproc Errors
|
||||
|
||||
A microlibrary to work with dynamic / static representation of [payproc business error](https://github.com/valitydev/damsel/blob/master/proto/payment_processing_errors.thrift) models.
|
||||
|
||||
## Building
|
||||
|
||||
To build the project, run the following command:
|
||||
|
||||
```bash
|
||||
$ make compile
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
To enter the [Erlang shell][1] with the project running, run the following command:
|
||||
|
||||
```bash
|
||||
$ make rebar-shell
|
||||
```
|
||||
|
||||
## Development environment
|
||||
|
||||
### Run in a docker container
|
||||
|
||||
You can run any of the tasks defined in the Makefile from inside of a docker container (defined in `Dockerfile.dev`) by prefixing the task name with `wc-`. To successfully build the dev container you need `Docker BuildKit` enabled. This can be accomplished by either installing [docker-buildx](https://docs.docker.com/buildx/working-with-buildx/) locally, or exporting the `DOCKER_BUILDKIT=1` environment variable.
|
||||
|
||||
#### Example
|
||||
|
||||
* This command will run the `compile` task in a docker container:
|
||||
```bash
|
||||
$ make wc-compile
|
||||
```
|
||||
#### Example
|
||||
|
||||
* This command will run the `compile` task in a docker container:
|
||||
```bash
|
||||
$ make wc-compile
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
@TODO Please write a couple of words about what your project does and how it does it.
|
||||
|
||||
[1]: http://erlang.org/doc/man/shell.html
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit f42e059d9ec93826ba4ad23232eed8ce67bd5486
|
67
elvis.config
67
elvis.config
@ -1,47 +1,16 @@
|
||||
[
|
||||
{elvis, [
|
||||
{verbose, true},
|
||||
{config, [
|
||||
#{
|
||||
dirs => ["apps/*/src"],
|
||||
dirs => ["src", "include", "test"],
|
||||
filter => "*.erl",
|
||||
ignore => ["_thrift.erl$"],
|
||||
ruleset => erl_files,
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 120, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace},
|
||||
{elvis_style, macro_module_names},
|
||||
{elvis_style, operator_spaces, #{rules => [{right, ","}, {right, "++"}, {left, "++"}]}},
|
||||
{elvis_text_style, line_length, #{limit => 120}},
|
||||
{elvis_style, nesting_level, #{level => 3}},
|
||||
{elvis_style, god_modules, #{limit => 30, ignore => [hg_client_party]}},
|
||||
{elvis_style, no_if_expression},
|
||||
{elvis_style, invalid_dynamic_call, #{ignore => [elvis]}},
|
||||
{elvis_style, used_ignored_variable},
|
||||
{elvis_style, no_behavior_info},
|
||||
{elvis_style, module_naming_convention, #{regex => "^([a-z][a-z0-9]*_?)*(_SUITE)?$"}},
|
||||
{elvis_style, function_naming_convention, #{regex => "^([a-z][a-z0-9]*_?)*$"}},
|
||||
{elvis_style, state_record_and_type},
|
||||
{elvis_style, no_spec_with_records},
|
||||
{elvis_style, dont_repeat_yourself, #{min_complexity => 15}},
|
||||
{elvis_style, no_debug_call, #{ignore => [elvis, elvis_utils]}}
|
||||
]
|
||||
},
|
||||
#{
|
||||
dirs => ["apps/*/test"],
|
||||
filter => "*.erl",
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 120, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace},
|
||||
{elvis_style, macro_module_names},
|
||||
{elvis_style, operator_spaces, #{rules => [{right, ","}, {right, "++"}, {left, "++"}]}},
|
||||
{elvis_style, nesting_level, #{level => 3}},
|
||||
{elvis_style, no_if_expression},
|
||||
{elvis_style, used_ignored_variable},
|
||||
{elvis_style, no_behavior_info},
|
||||
{elvis_style, module_naming_convention, #{regex => "^([a-z][a-z0-9]*_?)*(_SUITE)?$"}},
|
||||
{elvis_style, function_naming_convention, #{regex => "^([a-z][a-z0-9]*_?)*$"}},
|
||||
{elvis_style, no_spec_with_records},
|
||||
{elvis_style, dont_repeat_yourself, #{min_complexity => 30}}
|
||||
{elvis_style, no_if_expression, disable}
|
||||
]
|
||||
},
|
||||
#{
|
||||
@ -54,31 +23,25 @@
|
||||
filter => "elvis.config",
|
||||
ruleset => elvis_config
|
||||
},
|
||||
#{
|
||||
dirs => ["apps", "apps/*"],
|
||||
filter => "rebar.config",
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 120, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace}
|
||||
]
|
||||
},
|
||||
#{
|
||||
dirs => ["."],
|
||||
filter => "rebar.config",
|
||||
ruleset => rebar_config,
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 120, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace}
|
||||
{elvis_text_style, line_length, #{limit => 120}},
|
||||
{elvis_text_style, no_tabs},
|
||||
{elvis_text_style, no_trailing_whitespace},
|
||||
%% Temporarily disabled till regex pattern is available
|
||||
{elvis_project, no_deps_master_rebar, disable}
|
||||
]
|
||||
},
|
||||
#{
|
||||
dirs => ["apps/*/src"],
|
||||
dirs => ["src"],
|
||||
filter => "*.app.src",
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 120, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace}
|
||||
{elvis_text_style, line_length, #{limit => 120}},
|
||||
{elvis_text_style, no_tabs},
|
||||
{elvis_text_style, no_trailing_whitespace}
|
||||
]
|
||||
}
|
||||
]}
|
||||
|
33
rebar.config
33
rebar.config
@ -1,6 +1,5 @@
|
||||
% Common project erlang options.
|
||||
%% Common project erlang options.
|
||||
{erl_opts, [
|
||||
|
||||
% mandatory
|
||||
debug_info,
|
||||
warnings_as_errors,
|
||||
@ -23,21 +22,24 @@
|
||||
% bin_opt_info
|
||||
% no_auto_import
|
||||
% warn_missing_spec_all
|
||||
|
||||
]}.
|
||||
|
||||
% Common project dependencies.
|
||||
{deps, [
|
||||
{damsel, {git, "git@github.com:rbkmoney/damsel.git", {branch, "release/erlang/master"}}}
|
||||
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}}
|
||||
]}.
|
||||
|
||||
%% XRef checks
|
||||
{xref_checks, [
|
||||
undefined_function_calls,
|
||||
undefined_functions,
|
||||
deprecated_functions_calls,
|
||||
deprecated_functions
|
||||
]}.
|
||||
% at will
|
||||
% {xref_warnings, true}.
|
||||
|
||||
%% Dialyzer static analyzing
|
||||
{dialyzer, [
|
||||
{warnings, [
|
||||
% mandatory
|
||||
@ -51,16 +53,31 @@
|
||||
|
||||
{profiles, [
|
||||
{test, [
|
||||
{deps, [
|
||||
{cover_enabled, true},
|
||||
{deps, []},
|
||||
{dialyzer, [
|
||||
{plt_extra_apps, [common_test]}
|
||||
]}
|
||||
]}
|
||||
]}.
|
||||
|
||||
{plugins, [
|
||||
{erlfmt, "0.8.0"}
|
||||
{project_plugins, [
|
||||
{rebar3_lint, "1.0.1"},
|
||||
{erlfmt, "1.0.0"},
|
||||
{covertool, "2.0.4"}
|
||||
]}.
|
||||
|
||||
%% Linter config.
|
||||
{elvis_output_format, colors}.
|
||||
|
||||
{erlfmt, [
|
||||
{print_width, 120},
|
||||
{files, "{src,include,test}/*.{hrl,erl}"}
|
||||
{files, ["{src,include,test}/*.{hrl,erl}", "rebar.config", "elvis.config"]}
|
||||
]}.
|
||||
|
||||
{covertool, [
|
||||
{coverdata_files, [
|
||||
"eunit.coverdata",
|
||||
"ct.coverdata"
|
||||
]}
|
||||
]}.
|
||||
|
@ -1,4 +1,4 @@
|
||||
[{<<"damsel">>,
|
||||
{git,"git@github.com:rbkmoney/damsel.git",
|
||||
{ref,"3523f3b61bfcefb05256de5b1852d9bbeca6aa86"}},
|
||||
{git,"https://github.com/valitydev/damsel.git",
|
||||
{ref,"dac2cb599499cc0701e60856f4092c9ab283eedf"}},
|
||||
0}].
|
||||
|
@ -16,7 +16,7 @@
|
||||
-export([format_raw/1]).
|
||||
|
||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_payment_processing_errors_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_payproc_error_thrift.hrl").
|
||||
|
||||
%%
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
-type static_error() :: {static_code(), static_sub_error()}.
|
||||
-type static_sub_error() ::
|
||||
{static_code(), static_sub_error()}
|
||||
| dmsl_payment_processing_errors_thrift:'GeneralFailure'().
|
||||
| dmsl_payproc_error_thrift:'GeneralFailure'().
|
||||
|
||||
-type dynamic_code() :: binary().
|
||||
-type dynamic_error() :: dmsl_domain_thrift:'Failure'().
|
||||
@ -65,7 +65,7 @@ error_to_static(Type, #domain_Failure{code = Code, sub = SDE}) ->
|
||||
|
||||
-spec sub_error_to_static(type(), dynamic_sub_error()) -> static_sub_error().
|
||||
sub_error_to_static(_, undefined) ->
|
||||
#payprocerr_GeneralFailure{};
|
||||
#payproc_error_GeneralFailure{};
|
||||
sub_error_to_static(Type, #domain_SubFailure{code = Code, sub = SDE}) ->
|
||||
to_static(Code, Type, SDE).
|
||||
|
||||
@ -76,7 +76,7 @@ to_static(Code, Type, SDE) ->
|
||||
SubType when SubType =/= undefined ->
|
||||
{StaticCode, sub_error_to_static(SubType, SDE)};
|
||||
undefined ->
|
||||
{{unknown_error, Code}, #payprocerr_GeneralFailure{}}
|
||||
{{unknown_error, Code}, #payproc_error_GeneralFailure{}}
|
||||
end.
|
||||
|
||||
-spec code_to_static(dynamic_code()) -> static_code().
|
||||
@ -99,8 +99,8 @@ error_to_dynamic(Type, SE) ->
|
||||
sub_error_to_dynamic(undefined, _) ->
|
||||
undefined;
|
||||
sub_error_to_dynamic(Type, SSE) ->
|
||||
{Code, SubType, SSE_} = to_dynamic(Type, SSE),
|
||||
#domain_SubFailure{code = Code, sub = sub_error_to_dynamic(SubType, SSE_)}.
|
||||
{Code, SubType, SSEDyn} = to_dynamic(Type, SSE),
|
||||
#domain_SubFailure{code = Code, sub = sub_error_to_dynamic(SubType, SSEDyn)}.
|
||||
|
||||
-spec code_to_dynamic(static_code()) -> dynamic_code().
|
||||
code_to_dynamic({unknown_error, Code}) ->
|
||||
@ -111,9 +111,9 @@ code_to_dynamic(Code) ->
|
||||
%%
|
||||
|
||||
-spec to_dynamic(type(), static_sub_error()) -> {dynamic_code(), type() | undefined, static_sub_error()}.
|
||||
to_dynamic(_, {Code = {unknown_error, _}, #payprocerr_GeneralFailure{}}) ->
|
||||
to_dynamic(_, {Code = {unknown_error, _}, #payproc_error_GeneralFailure{}}) ->
|
||||
{code_to_dynamic(Code), undefined, undefined};
|
||||
to_dynamic(Type, {Code, #payprocerr_GeneralFailure{}}) ->
|
||||
to_dynamic(Type, {Code, #payproc_error_GeneralFailure{}}) ->
|
||||
'GeneralFailure' = check_type(type_by_field(Code, Type)),
|
||||
{code_to_dynamic(Code), undefined, undefined};
|
||||
to_dynamic(Type, {Code, SSE}) ->
|
||||
@ -141,12 +141,12 @@ join(Code, Sub) -> [Code, $:, Sub].
|
||||
|
||||
-spec type_by_field(static_code(), type()) -> atom() | undefined.
|
||||
type_by_field(Code, Type) ->
|
||||
case [Field || Field = {Code_, _} <- struct_info(Type), Code =:= Code_] of
|
||||
case [Field || Field = {FCode, _} <- struct_info(Type), Code =:= FCode] of
|
||||
[{_, SubType}] -> SubType;
|
||||
[] -> undefined
|
||||
end.
|
||||
|
||||
-spec struct_info(atom()) -> [{atom(), atom()}].
|
||||
struct_info(Type) ->
|
||||
{struct, _, Fs} = dmsl_payment_processing_errors_thrift:struct_info(Type),
|
||||
[{FN, FT} || {_, _, {struct, _, {'dmsl_payment_processing_errors_thrift', FT}}, FN, _} <- Fs].
|
||||
{struct, _, Fs} = dmsl_payproc_error_thrift:struct_info(Type),
|
||||
[{FN, FT} || {_, _, {struct, _, {'dmsl_payproc_error_thrift', FT}}, FN, _} <- Fs].
|
||||
|
@ -1,7 +1,7 @@
|
||||
-module(payproc_errors_SUITE).
|
||||
|
||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_payment_processing_errors_thrift.hrl").
|
||||
-include_lib("damsel/include/dmsl_payproc_error_thrift.hrl").
|
||||
|
||||
-export([all/0]).
|
||||
|
||||
@ -9,12 +9,12 @@
|
||||
-export([unknown_error_test/1]).
|
||||
-export([unknown_error_atom_test/1]).
|
||||
-export([bad_static_type_test/1]).
|
||||
-export([formating_test/1]).
|
||||
-export([formatting_test/1]).
|
||||
|
||||
%%
|
||||
|
||||
-type config() :: hg_ct_helper:config().
|
||||
-type test_case_name() :: hg_ct_helper:test_case_name().
|
||||
-type config() :: [{atom(), term()}].
|
||||
-type test_case_name() :: atom().
|
||||
|
||||
-spec all() -> [test_case_name()].
|
||||
all() ->
|
||||
@ -23,54 +23,52 @@ all() ->
|
||||
unknown_error_test,
|
||||
unknown_error_atom_test,
|
||||
bad_static_type_test,
|
||||
formating_test
|
||||
formatting_test
|
||||
].
|
||||
|
||||
-spec known_error_test(config()) -> ok.
|
||||
-spec known_error_test(config()) -> _.
|
||||
known_error_test(_C) ->
|
||||
DE = #domain_Failure{
|
||||
code = <<"authorization_failed">>,
|
||||
sub = #domain_SubFailure{
|
||||
code = <<"payment_tool_rejected">>,
|
||||
code = <<"account_limit_exceeded">>,
|
||||
sub = #domain_SubFailure{
|
||||
code = <<"bank_card_rejected">>,
|
||||
code = <<"amount">>,
|
||||
sub = #domain_SubFailure{
|
||||
code = <<"cvv_invalid">>
|
||||
code = <<"monthly">>
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
SE =
|
||||
{authorization_failed,
|
||||
{payment_tool_rejected, {bank_card_rejected, {cvv_invalid, #payprocerr_GeneralFailure{}}}}},
|
||||
SE = {authorization_failed, {account_limit_exceeded, {amount, {monthly, #payproc_error_GeneralFailure{}}}}},
|
||||
DE = payproc_errors:construct('PaymentFailure', SE),
|
||||
ok = payproc_errors:match('PaymentFailure', DE, fun(SE_) when SE =:= SE_ -> ok end),
|
||||
ok = payproc_errors:match('PaymentFailure', DE, fun(E) when SE =:= E -> ok end),
|
||||
DE = payproc_errors:construct('RefundFailure', SE),
|
||||
ok = payproc_errors:match('RefundFailure', DE, fun(SE_) when SE =:= SE_ -> ok end).
|
||||
ok = payproc_errors:match('RefundFailure', DE, fun(E) when SE =:= E -> ok end).
|
||||
|
||||
-spec unknown_error_atom_test(config()) -> ok.
|
||||
-spec unknown_error_atom_test(config()) -> _.
|
||||
unknown_error_atom_test(_C) ->
|
||||
UnknownCode = <<"unknown big fucking error">>,
|
||||
DE = #domain_Failure{
|
||||
code = UnknownCode
|
||||
},
|
||||
SE = {{unknown_error, UnknownCode}, #payprocerr_GeneralFailure{}},
|
||||
SE = {{unknown_error, UnknownCode}, #payproc_error_GeneralFailure{}},
|
||||
DE = payproc_errors:construct('PaymentFailure', SE),
|
||||
ok = payproc_errors:match('PaymentFailure', DE, fun(SE_) when SE =:= SE_ -> ok end).
|
||||
ok = payproc_errors:match('PaymentFailure', DE, fun(E) when SE =:= E -> ok end).
|
||||
|
||||
-spec unknown_error_test(config()) -> ok.
|
||||
-spec unknown_error_test(config()) -> _.
|
||||
unknown_error_test(_C) ->
|
||||
UnknownCode = erlang:atom_to_binary(bad_error_code, utf8),
|
||||
DE = #domain_Failure{
|
||||
code = UnknownCode
|
||||
},
|
||||
SE = {{unknown_error, UnknownCode}, #payprocerr_GeneralFailure{}},
|
||||
SE = {{unknown_error, UnknownCode}, #payproc_error_GeneralFailure{}},
|
||||
DE = payproc_errors:construct('PaymentFailure', SE),
|
||||
ok = payproc_errors:match('PaymentFailure', DE, fun(SE_) when SE =:= SE_ -> ok end).
|
||||
ok = payproc_errors:match('PaymentFailure', DE, fun(E) when SE =:= E -> ok end).
|
||||
|
||||
-spec bad_static_type_test(config()) -> ok.
|
||||
-spec bad_static_type_test(config()) -> _.
|
||||
bad_static_type_test(_C) ->
|
||||
Bad = {qwe, #payprocerr_GeneralFailure{}},
|
||||
Bad = {qwe, #payproc_error_GeneralFailure{}},
|
||||
{'EXIT', {badarg, _}} =
|
||||
(catch payproc_errors:construct('PaymentFailure', {authorization_failed, Bad})),
|
||||
{'EXIT', {badarg, _}} =
|
||||
@ -80,16 +78,16 @@ bad_static_type_test(_C) ->
|
||||
{'EXIT', {badarg, _}} =
|
||||
(catch payproc_errors:construct('RefundFailure', {terms_violated, Bad})),
|
||||
{'EXIT', {badarg, _}} =
|
||||
(catch payproc_errors:construct('RefundFailure', {preauthorization_failed, #payprocerr_GeneralFailure{}})),
|
||||
(catch payproc_errors:construct('RefundFailure', {preauthorization_failed, #payproc_error_GeneralFailure{}})),
|
||||
{'EXIT', {badarg, _}} =
|
||||
(catch payproc_errors:construct('RefundFailure', Bad)),
|
||||
ok.
|
||||
|
||||
-spec formating_test(config()) -> ok.
|
||||
formating_test(_C) ->
|
||||
-spec formatting_test(config()) -> _.
|
||||
formatting_test(_C) ->
|
||||
SE =
|
||||
{authorization_failed,
|
||||
{payment_tool_rejected, {bank_card_rejected, {cvv_invalid, #payprocerr_GeneralFailure{}}}}},
|
||||
{payment_tool_rejected, {bank_card_rejected, {cvv_invalid, #payproc_error_GeneralFailure{}}}}},
|
||||
Type = 'PaymentFailure',
|
||||
<<"authorization_failed:payment_tool_rejected:bank_card_rejected:cvv_invalid">> =
|
||||
erlang:list_to_binary(payproc_errors:format(Type, payproc_errors:construct(Type, SE))).
|
||||
|
Loading…
Reference in New Issue
Block a user