Skip to content

Add a test #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Compile [diameter](http://erlang.org/doc/man/diameter.html) .dia files in rebar3
Build
-----

$ ./rebar3 compile
./rebar3 compile

Use
---
Expand Down Expand Up @@ -52,3 +52,9 @@ The plugin will be ran on compile and clean commands or call your plugin directl
$ rebar3 diameter clean
===> Cleaning diameter compiled files...

Test
-----

This test compiles a `.dia` file for validation

./rebar3 eunit
93 changes: 93 additions & 0 deletions test/dia_tests.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
-module( dia_tests ).

-include_lib( "eunit/include/eunit.hrl" ).


compile_test_() ->
{setup,
fun () -> setup() end,
[fun () -> test_compile() end]
}.


%% Internal

diameter_basename() -> "diameter_3gpp_base".


setup() ->
{ok, Repo} = file:get_cwd(),
Branch = setup_git_branch(),
Test_target = test_target( Repo ),
setup_delete( Test_target ),
setup_create( Test_target, Repo, Branch ).

setup_create( Test_target, Repo, Branch ) ->
ok = setup_create_dia( Test_target ),
ok = setup_create_src( Test_target ),
ok = setup_create_rebar_config( Test_target, Repo, Branch ).

setup_create_dia( Test_target ) ->
Diameter_file = diameter_basename() ++ ".dia",
File = filename:join( [Test_target, "dia", Diameter_file] ),
ok = filelib:ensure_dir( File ),
{ok, _} = file:copy( filename:join( "test", Diameter_file ), File ),
ok.

setup_create_src( Test_target ) ->
App = "compile",
File = filename:join( [Test_target, "src", App ++ ".app.src"] ),
ok = filelib:ensure_dir( File ),
file:write_file( File, setup_create_src_content(App) ).

setup_create_src_content(App) ->
"
{application, " ++ App ++ ", [
{description, \"" ++ App ++ "\"},
{vsn, \"1.0\"},
{applications, [kernel,stdlib]}
]}.
".

setup_create_rebar_config( Test_target, Repo, Branch ) ->
File = filename:join( Test_target, "rebar.config" ),
ok = filelib:ensure_dir( File ),
file:write_file( File, setup_rebar_config_content(Repo, Branch) ).

setup_delete( Directory ) ->
Paths = filelib:wildcard( filename:join(Directory, "*") ),
{Directories, Files} = lists:partition( fun filelib:is_dir/1, Paths ),
[file:delete(X) || X <- Files],
[setup_delete(X) || X <- Directories],
file:del_dir( Directory ).

setup_git_branch() -> string:trim( os:cmd("git branch --show-current") ).

setup_rebar_config_content( Repo, Branch ) ->
"
{plugins, [
{rebar3_diameter_compiler, {git, \"file://" ++ Repo ++ "\", {branch, \"" ++ Branch ++ "\"}}}
]}.
{provider_hooks, [
{pre, [
{clean, {diameter, clean}},
{compile, {diameter, compile}}
]}
]}.
".


test_compile() ->
{ok, Repo} = file:get_cwd(),
Test_target = test_target( Repo ),
ok = file:set_cwd( Test_target ),
% Result = os:cmd( "DIAGNOSTIC=1 rebar3 eunit" ),
% ?debugMsg( Result ),
?assertCmd( "rebar3 eunit" ),
true = filelib:is_regular( filename:join("include", diameter_basename() ++ ".hrl") ),
true = filelib:is_regular( filename:join("src", diameter_basename() ++ ".erl") ),
file:set_cwd( Repo ).


test_target( Repo ) ->
filename:join( [Repo, "_build", "test", "lib", "rebar3_diameter_compiler", "test", "compile"] ).
73 changes: 73 additions & 0 deletions test/diameter_3gpp_base.dia
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
;;
;; %CopyrightBegin%
;;
;; Copyright Travelping GmbH 2015. All Rights Reserved.
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;
;; %CopyrightEnd%
;;

;;
;; Edits:
;;
;; - Ipv6 -> IPv6
;; - 3GPP-Charging-Id: OctetString -> Unsigned32
;; - 3GPP-User-Location-Info-Time: OctetString -> Unsigned32
;;

@id 0
@name diameter_3gpp_base
@prefix diameter_3gpp
@vendor 10415 3GPP

;; only attributes required by other applications are defined

@avp_types

3GPP-IMSI 1 UTF8String V
3GPP-Charging-Id 2 Unsigned32 V
3GPP-PDP-Type 3 Enumerated V
3GPP-CG-Address 4 OctetString V
3GPP-GPRS-Negotiated-QoS-Profile 5 UTF8String V
3GPP-SGSN-Address 6 OctetString V
3GPP-GGSN-Address 7 OctetString V
3GPP-IMSI-MCC-MNC 8 UTF8String V
3GPP-GGSN-MCC-MNC 9 UTF8String V
3GPP-NSAPI 10 OctetString V
3GPP-Session-Stop-Indicator 11 OctetString V
3GPP-Selection-Mode 12 UTF8String V
3GPP-Charging-Characteristics 13 UTF8String V
3GPP-CG-IPv6-Address 14 OctetString V
3GPP-SGSN-IPv6-Address 15 OctetString V
3GPP-GGSN-IPv6-Address 16 OctetString V
3GPP-IPv6-DNS-Servers 17 OctetString V
3GPP-SGSN-MCC-MNC 18 UTF8String V
3GPP-IMEISV 20 OctetString V
3GPP-RAT-Type 21 OctetString V
3GPP-User-Location-Info 22 OctetString V
3GPP-MS-TimeZone 23 OctetString V
3GPP-CAMEL-Charging-Info 24 OctetString V
3GPP-Packet-Filter 25 OctetString V
3GPP-Negotiated-DSCP 26 OctetString V
3GPP-Allocate-IP-Type 27 OctetString V
TWAN-Identifier 29 OctetString V
3GPP-User-Location-Info-Time 30 Unsigned32 V

@enum 3GPP-PDP-Type

IPv4 0
PPP 1
IPv6 2
IPv4v6 3
Non-IP 4