summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2014-04-26 20:39:25 +0200
committerLinus Nordberg <linus@nordu.net>2014-04-26 20:39:25 +0200
commit9660a220392beb26b17a003a5d3f6ba0a73bb6b0 (patch)
tree8f78f4767441260bec971737f9f011f17dce1f01 /src
parent7541fa63d1546f1a434ec742627d9632dd751959 (diff)
Test adding and checking STH in sequence.
Diffstat (limited to 'src')
-rw-r--r--src/test/plop_test.erl74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/test/plop_test.erl b/src/test/plop_test.erl
index e682b28..87329c6 100644
--- a/src/test/plop_test.erl
+++ b/src/test/plop_test.erl
@@ -2,25 +2,35 @@
-include("plop.hrl").
-include_lib("eunit/include/eunit.hrl").
-adding_test_() ->
- {"Verifies startup, adding log entries and STH's.",
- {setup, % TODO: use 'foreach'
- fun start/0,
- fun stop/1,
- fun (Arg) ->
- [test_add(Arg), test_sth(Arg),
- test_add(Arg),
- test_sth(Arg)] % <-- should fail!
- end}}.
+start_stop_test_() ->
+ {"The server can be started, stopped and is regsitered",
+ {setup, fun start/0, fun stop/1, fun is_registered/1}}.
+
+%% "Entries can be added and the STH changes."
+adding_verifying_test() ->
+ Pid = start(),
+ add(),
+ sth(),
+ %% TODO: add one more and verify that the STH changes
+ %% add(),
+ %% sth(),
+ stop(Pid).
+%%% Setup.
start() ->
- io:format("Starting.~n"),
- plop:start_link("test/rsakey.pem", "sikrit").
+ {ok, Pid} = plop:start_link("test/rsakey.pem", "sikrit"),
+ Pid.
+
+stop(_) ->
+ plop:stop().
-stop(_Pid) ->
- [?_assertEqual({qok, plop}, plop:stop())].
+%%% Tests.
+is_registered(Pid) ->
+ [?_assert(erlang:is_process_alive(Pid)),
+ ?_assertEqual(Pid, whereis(plop))].
-test_add(_Pid) ->
+%%% Helpers.
+add() ->
TestVector =
<<1,247,141,118,3,148,171,128,29,143,106,97,200,179,204,166,242,98,70,185,231,
78,193,39,12,245,82,254,230,136,69,69,0,0,0,0,0,0,0,18,103,69,73,8,105,107,
@@ -38,25 +48,25 @@ test_add(_Pid) ->
203,214,189,144,145,21,247,165,125,192,43,94,247,209,81,50,100>>,
Entry = #plop_entry{type = test, data = <<"some data">>},
SPT = #spt{signature_type = test, timestamp = 4711, entry = Entry},
- [?_assertEqual(TestVector, plop:add(SPT))].
+ ?assertEqual(TestVector, plop:add(SPT)).
-test_sth(_Pid) ->
+sth() ->
TestVector =
- <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,103,93,90,159,157,211,129,96,54,161,145,226,
+ <<0,0,0,0,0,0,0,1,0,0,0,0,0,0,18,103,93,90,159,157,211,129,96,54,161,145,226,
218,28,127,43,87,221,243,153,101,255,249,156,114,234,50,84,163,183,64,215,
- 227,112,208,11,52,174,79,151,153,101,56,175,228,12,222,146,138,32,222,199,
- 187,222,38,67,121,85,204,137,41,61,226,88,128,19,77,73,1,208,145,83,142,28,
- 130,99,147,213,29,103,113,232,20,209,250,76,198,16,4,249,65,26,232,149,1,21,
- 42,95,229,251,167,126,220,212,74,195,215,225,22,145,98,51,11,28,83,30,213,15,
- 42,162,135,251,71,195,145,165,194,247,181,213,47,126,95,232,111,231,49,46,
- 150,177,118,142,28,230,228,167,54,209,42,177,108,62,39,236,85,153,176,117,
- 111,61,220,120,49,159,89,185,220,212,53,71,69,144,188,200,16,29,234,255,242,
- 126,223,87,146,219,248,164,180,20,229,161,227,24,32,209,180,122,61,195,149,
- 49,3,195,162,218,56,86,185,200,17,188,82,23,64,67,187,160,167,13,175,233,211,
- 226,72,198,182,6,6,65,123,76,10,81,66,55,159,120,162,56,102,233,35,102,153,
- 214,238,116,108,181,106,159,157,241,101,120,35,107,152,36,193,241,211,210,72,
- 184,166,220,155,198,238,246,47,181,89,80,29,52,222,181,25,81,76,123,249,225,
- 5,192,233,133,131>>,
+ 227,16,126,61,255,54,243,5,185,250,149,18,30,228,16,48,168,252,213,27,205,
+ 254,157,72,230,112,65,150,187,18,215,17,249,72,18,38,159,217,49,159,177,153,
+ 175,86,139,158,29,24,202,126,203,88,216,19,205,237,172,48,9,113,228,231,170,
+ 131,38,155,185,188,232,215,15,54,93,254,173,100,13,115,172,161,7,106,226,180,
+ 168,81,245,47,10,59,14,25,26,23,80,11,227,147,115,216,173,93,63,232,50,213,
+ 43,148,71,149,104,32,10,217,108,182,194,88,12,153,187,42,190,154,203,114,200,
+ 24,137,106,65,51,25,162,178,24,199,155,215,208,115,5,239,64,189,69,0,196,55,
+ 211,91,12,83,132,131,84,92,146,124,125,117,74,62,7,162,230,37,13,45,122,183,
+ 112,207,227,240,152,190,181,168,96,210,252,59,144,12,141,46,18,18,51,226,14,
+ 218,17,255,212,136,198,154,69,64,232,234,249,2,232,45,165,206,157,195,77,254,
+ 126,173,10,12,184,21,55,111,183,15,2,251,177,220,139,35,20,148,219,137,78,
+ 187,221,242,23,254,196,182,98,110,150,95,126,53,42,243,123,198,30,247,79,17,
+ 172,129>>,
STH = plop:sth(#sth{timestamp = 4711}),
%%io:format(element(2, file:open("foo", write)), "~p", [STH]),
- [?_assertEqual(TestVector, STH)].
+ ?assertEqual(TestVector, STH).