Skip to content

Commit 85b0467

Browse files
authored
Merge pull request #15 from ebengt/add_test
2 parents 9212e25 + 025887f commit 85b0467

File tree

3 files changed

+173
-1
lines changed

3 files changed

+173
-1
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Compile [diameter](http://erlang.org/doc/man/diameter.html) .dia files in rebar3
66
Build
77
-----
88

9-
$ ./rebar3 compile
9+
./rebar3 compile
1010

1111
Use
1212
---
@@ -52,3 +52,9 @@ The plugin will be ran on compile and clean commands or call your plugin directl
5252
$ rebar3 diameter clean
5353
===> Cleaning diameter compiled files...
5454

55+
Test
56+
-----
57+
58+
This test compiles a `.dia` file for validation
59+
60+
./rebar3 eunit

test/dia_tests.erl

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
-module( dia_tests ).
2+
3+
-include_lib( "eunit/include/eunit.hrl" ).
4+
5+
6+
compile_test_() ->
7+
{setup,
8+
fun () -> setup() end,
9+
[fun () -> test_compile() end]
10+
}.
11+
12+
13+
%% Internal
14+
15+
diameter_basename() -> "diameter_3gpp_base".
16+
17+
18+
setup() ->
19+
{ok, Repo} = file:get_cwd(),
20+
Branch = setup_git_branch(),
21+
Test_target = test_target( Repo ),
22+
setup_delete( Test_target ),
23+
setup_create( Test_target, Repo, Branch ).
24+
25+
setup_create( Test_target, Repo, Branch ) ->
26+
ok = setup_create_dia( Test_target ),
27+
ok = setup_create_src( Test_target ),
28+
ok = setup_create_rebar_config( Test_target, Repo, Branch ).
29+
30+
setup_create_dia( Test_target ) ->
31+
Diameter_file = diameter_basename() ++ ".dia",
32+
File = filename:join( [Test_target, "dia", Diameter_file] ),
33+
ok = filelib:ensure_dir( File ),
34+
{ok, _} = file:copy( filename:join( "test", Diameter_file ), File ),
35+
ok.
36+
37+
setup_create_src( Test_target ) ->
38+
App = "compile",
39+
File = filename:join( [Test_target, "src", App ++ ".app.src"] ),
40+
ok = filelib:ensure_dir( File ),
41+
file:write_file( File, setup_create_src_content(App) ).
42+
43+
setup_create_src_content(App) ->
44+
"
45+
{application, " ++ App ++ ", [
46+
{description, \"" ++ App ++ "\"},
47+
{vsn, \"1.0\"},
48+
{applications, [kernel,stdlib]}
49+
]}.
50+
".
51+
52+
setup_create_rebar_config( Test_target, Repo, Branch ) ->
53+
File = filename:join( Test_target, "rebar.config" ),
54+
ok = filelib:ensure_dir( File ),
55+
file:write_file( File, setup_rebar_config_content(Repo, Branch) ).
56+
57+
setup_delete( Directory ) ->
58+
Paths = filelib:wildcard( filename:join(Directory, "*") ),
59+
{Directories, Files} = lists:partition( fun filelib:is_dir/1, Paths ),
60+
[file:delete(X) || X <- Files],
61+
[setup_delete(X) || X <- Directories],
62+
file:del_dir( Directory ).
63+
64+
setup_git_branch() -> string:trim( os:cmd("git branch --show-current") ).
65+
66+
setup_rebar_config_content( Repo, Branch ) ->
67+
"
68+
{plugins, [
69+
{rebar3_diameter_compiler, {git, \"file://" ++ Repo ++ "\", {branch, \"" ++ Branch ++ "\"}}}
70+
]}.
71+
{provider_hooks, [
72+
{pre, [
73+
{clean, {diameter, clean}},
74+
{compile, {diameter, compile}}
75+
]}
76+
]}.
77+
".
78+
79+
80+
test_compile() ->
81+
{ok, Repo} = file:get_cwd(),
82+
Test_target = test_target( Repo ),
83+
ok = file:set_cwd( Test_target ),
84+
% Result = os:cmd( "DIAGNOSTIC=1 rebar3 eunit" ),
85+
% ?debugMsg( Result ),
86+
?assertCmd( "rebar3 eunit" ),
87+
true = filelib:is_regular( filename:join("include", diameter_basename() ++ ".hrl") ),
88+
true = filelib:is_regular( filename:join("src", diameter_basename() ++ ".erl") ),
89+
file:set_cwd( Repo ).
90+
91+
92+
test_target( Repo ) ->
93+
filename:join( [Repo, "_build", "test", "lib", "rebar3_diameter_compiler", "test", "compile"] ).

test/diameter_3gpp_base.dia

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
;;
2+
;; %CopyrightBegin%
3+
;;
4+
;; Copyright Travelping GmbH 2015. All Rights Reserved.
5+
;;
6+
;; Licensed under the Apache License, Version 2.0 (the "License");
7+
;; you may not use this file except in compliance with the License.
8+
;; You may obtain a copy of the License at
9+
;;
10+
;; http://www.apache.org/licenses/LICENSE-2.0
11+
;;
12+
;; Unless required by applicable law or agreed to in writing, software
13+
;; distributed under the License is distributed on an "AS IS" BASIS,
14+
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
;; See the License for the specific language governing permissions and
16+
;; limitations under the License.
17+
;;
18+
;; %CopyrightEnd%
19+
;;
20+
21+
;;
22+
;; Edits:
23+
;;
24+
;; - Ipv6 -> IPv6
25+
;; - 3GPP-Charging-Id: OctetString -> Unsigned32
26+
;; - 3GPP-User-Location-Info-Time: OctetString -> Unsigned32
27+
;;
28+
29+
@id 0
30+
@name diameter_3gpp_base
31+
@prefix diameter_3gpp
32+
@vendor 10415 3GPP
33+
34+
;; only attributes required by other applications are defined
35+
36+
@avp_types
37+
38+
3GPP-IMSI 1 UTF8String V
39+
3GPP-Charging-Id 2 Unsigned32 V
40+
3GPP-PDP-Type 3 Enumerated V
41+
3GPP-CG-Address 4 OctetString V
42+
3GPP-GPRS-Negotiated-QoS-Profile 5 UTF8String V
43+
3GPP-SGSN-Address 6 OctetString V
44+
3GPP-GGSN-Address 7 OctetString V
45+
3GPP-IMSI-MCC-MNC 8 UTF8String V
46+
3GPP-GGSN-MCC-MNC 9 UTF8String V
47+
3GPP-NSAPI 10 OctetString V
48+
3GPP-Session-Stop-Indicator 11 OctetString V
49+
3GPP-Selection-Mode 12 UTF8String V
50+
3GPP-Charging-Characteristics 13 UTF8String V
51+
3GPP-CG-IPv6-Address 14 OctetString V
52+
3GPP-SGSN-IPv6-Address 15 OctetString V
53+
3GPP-GGSN-IPv6-Address 16 OctetString V
54+
3GPP-IPv6-DNS-Servers 17 OctetString V
55+
3GPP-SGSN-MCC-MNC 18 UTF8String V
56+
3GPP-IMEISV 20 OctetString V
57+
3GPP-RAT-Type 21 OctetString V
58+
3GPP-User-Location-Info 22 OctetString V
59+
3GPP-MS-TimeZone 23 OctetString V
60+
3GPP-CAMEL-Charging-Info 24 OctetString V
61+
3GPP-Packet-Filter 25 OctetString V
62+
3GPP-Negotiated-DSCP 26 OctetString V
63+
3GPP-Allocate-IP-Type 27 OctetString V
64+
TWAN-Identifier 29 OctetString V
65+
3GPP-User-Location-Info-Time 30 Unsigned32 V
66+
67+
@enum 3GPP-PDP-Type
68+
69+
IPv4 0
70+
PPP 1
71+
IPv6 2
72+
IPv4v6 3
73+
Non-IP 4

0 commit comments

Comments
 (0)