From 2cce0ae0c11fb2f3b3bfad14f20784c2a50997cc Mon Sep 17 00:00:00 2001 From: StefanStrobel <> Date: Sat, 29 Aug 2020 16:18:31 +0000 Subject: [PATCH] 98_HTTPMOD: updated tests git-svn-id: https://svn.fhem.de/fhem/trunk@22692 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg | 1 + fhem/t/FHEM/98_HTTPMOD/10_Redirects.t | 11 ++++++++ fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.t | 8 ++++++ fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg | 10 ++++--- fhem/t/FHEM/98_HTTPMOD/30_requestExpr.t | 33 ++++------------------ fhem/t/FHEM/98_HTTPMOD/31_Regexes.t | 12 ++++++++ fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg | 5 ++-- fhem/t/FHEM/98_HTTPMOD/40_maxAge.t | 4 +-- fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t | 17 ++++++++++- 9 files changed, 64 insertions(+), 37 deletions(-) diff --git a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg index 623208d78..9f4e64b0c 100644 --- a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.cfg @@ -3,3 +3,4 @@ attr H2 verbose 5 attr H2 fileHeaderSplit --end-of-http-header-- attr H2 queueDelay 2 attr H2 minSendDelay 2 + diff --git a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.t b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.t index ebde8b0c2..a4ed34bef 100644 --- a/fhem/t/FHEM/98_HTTPMOD/10_Redirects.t +++ b/fhem/t/FHEM/98_HTTPMOD/10_Redirects.t @@ -5,6 +5,17 @@ use strict; use warnings; use Test::More; +my $hash = $defs{'H2'}; +my $modVersion = $hash->{ModuleVersion}; +$modVersion =~ /^([0-9]+)\./; +my $major = $1; + +if ($major && $major >= 4) { + plan tests => 1; +} else { + plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; +} + fhem('set H2 reread'); is(FhemTestUtils_gotLog("AddToQueue prepends type update to URL http://test.url/"), 1, "Match redirected url"); diff --git a/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.t b/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.t index 2d6987931..9b057993f 100644 --- a/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.t +++ b/fhem/t/FHEM/98_HTTPMOD/20_extractAllJSON.t @@ -5,6 +5,14 @@ use strict; use warnings; use Test::More; +eval "use JSON"; +if ($@) { + plan skip_all => "This test checks an optional JSON-Feature of HTTPMOD and can only be run with the JSON library installed. Please install JSON Library (apt-get install libjson-perl)"; +} else { + plan tests => 3; +} + + fhem('set H1 reread'); InternalTimer(time()+1, sub() { diff --git a/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg b/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg index 3a03a1658..768f07c78 100644 --- a/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.cfg @@ -1,8 +1,8 @@ define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON 0 attr H1 verbose 3 attr H1 get01Name TestGet -attr H1 get01Data Post Data for Test attr H1 get01Header1 Content-Type: application/json +attr H1 get01Data Post Data for Test attr H1 get01URLExpr $old . '.testdata' attr H1 get01HdrExpr $old . '345' attr H1 get01DatExpr $old . '567' @@ -13,14 +13,16 @@ attr H2 requestHeader2 TestHeader: T1E2S3T attr H2 verbose 5 attr H2 minSendDelay 0 attr H2 reading01Name TestReading -attr H2 reading01JSON MQTT_ip_1 +attr H2 reading01Regex "ip":\[192,(\d+),1,24\] attr H2 reading01OExpr $val * 2 attr H2 reading02Name TestReading2 -attr H2 reading02JSON modes +attr H2 reading02Regex \"([^\"\]\[]+)\"\, +attr H2 reading02RegOpt g attr H2 reading03Name CombReading -attr H2 reading03JSON modes +attr H2 reading03Regex \"([^\"\]\[]+)\"\, +attr H2 reading03RegOpt g attr H2 reading03RecombineExpr join ' ', @matchlist attr H2 set01Name TestSet1 diff --git a/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.t b/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.t index 46da3e7cb..d56355d72 100644 --- a/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.t +++ b/fhem/t/FHEM/98_HTTPMOD/30_requestExpr.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use FHEM::HTTPMOD::Utils qw(:all); + fhem('attr H1 verbose 5'); fhem('attr H1 get02IExpr $vale'); @@ -17,38 +17,15 @@ is(FhemTestUtils_gotLog("header Content-Type: application/json345"), 1, "Header is(FhemTestUtils_gotLog(", data Post Data for Test567"), 1, "Post Data expression in log"); fhem('set H2 reread'); -is(FhemTestUtils_gotEvent(qr/H2:TestReading:\s336/xms), 1, "JSON Reading creation with OExpr Expression"); -is(FhemTestUtils_gotEvent("H2:TestReading2-8: UDP"), 1, "JSON multiple Reading creation"); -is(FhemTestUtils_gotEvent("H2:CombReading: Off SimpleColor RainbowChase"), 1, "Reading recombine expresion"); +is(FhemTestUtils_gotEvent(qr/H2:TestReading:\s336/xms), 1, "Regex Reading creation with OExpr Expression"); +is(FhemTestUtils_gotEvent("H2:TestReading2-10: UDP"), 1, "Regex multiple Reading creation"); + +is(FhemTestUtils_gotEvent("H2:CombReading: tvlights 0 Off SimpleColor"), 1, "Reading recombine expresion"); is(FhemTestUtils_gotLog(qr/HandleSendQueue\ssends\supdate.*header:\sContent-Type:\sTest-Content.*TestHeader:\sT1E2S3T/xms), 1, "requestHeader"); fhem('set H2 TestSet1 4'); is(FhemTestUtils_gotLog("TestSet1 PostData 8"), 1, "set IExpr1 to Post Data in log"); -my $hash = $defs{'H2'}; -my $name = 'H2'; -my $val = 5; -my @array = (1,2,3); -my %tHash = (a => 10, b => 20); -my $exp = '$val * 2'; - -my $result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array}); -#Log3 $name, 3, "$name: result of EvalExpr test 1 = $result"; -is $result, 10, "simple expression with one scalar in list"; - -$exp = '$array[1] * 2'; -$result = EvalExpr($hash, $exp, {'$val' => $val, '@array' => \@array}); -is $result, 4, "simple expression with array ref in hash"; - -$exp = '$hash{a} * 2'; -$result = EvalExpr($hash, $exp, {'$val' => $val, '%hash' => \%tHash}); -is $result, 20, "simple expression with hash ref in hash"; - -$exp = '$hash->{a} * 2'; -$result = EvalExpr($hash, $exp, {'$val' => $val, '$hash' => \%tHash}); -is $result, 20, "simple expression with hash ref as ref in hash"; - - done_testing; exit(0); diff --git a/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t b/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t index e4a738265..c4fc2b53a 100644 --- a/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t +++ b/fhem/t/FHEM/98_HTTPMOD/31_Regexes.t @@ -15,6 +15,18 @@ use strict; use warnings; use Test::More; +my $hash = $defs{'H2'}; +my $modVersion = $hash->{ModuleVersion}; +$modVersion =~ /^([0-9]+)\./; +my $major = $1; + +if ($major && $major >= 4) { + plan tests => 13; +} else { + plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; +} + + fhem('set H1 reread'); is(FhemTestUtils_gotEvent(qr/H1:TestReading1:\sRainbowChase/xms), 1, "match simple case with regex compilation"); is(FhemTestUtils_gotEvent(qr/H1:TestReading2:\sRainbowChase/xms), 1, "match with options xms with regex compilation"); diff --git a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg index 60f306037..5d80666d8 100644 --- a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg +++ b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.cfg @@ -3,10 +3,11 @@ attr H1 verbose 5 attr H1 minSendDelay 0 attr H1 reading01Name TestReading1 -attr H1 reading01JSON MQTT_ip_1 +attr H1 reading01Regex "ip":\[192,(\d+),1,24\] attr H1 reading02Name TestReading2 -attr H1 reading02JSON modes +attr H1 reading02Regex \"([^\"\]\[]+)\"\, +attr H1 reading02RegOpt g attr H1 readingMaxAge 0.1 attr H1 readingMaxAgeReplacement outdated diff --git a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t index 1377c646c..e9e9a4e3f 100644 --- a/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t +++ b/fhem/t/FHEM/98_HTTPMOD/40_maxAge.t @@ -7,7 +7,7 @@ use Test::More; fhem('get H1 G1'); is(FhemTestUtils_gotEvent("H1:TestReading1: 168"), 1, "Normal Reading 1"); -is(FhemTestUtils_gotEvent("H1:TestReading2-1: Off"), 1, "Normal Reading 2"); +is(FhemTestUtils_gotEvent("H1:TestReading2-1: tvlights"), 1, "Normal Reading 2"); sleep 0.15; @@ -15,7 +15,7 @@ fhem('setreading H1 tr 789'); fhem('get H1 G2'); is(FhemTestUtils_gotEvent("H1:TestReading1: outdated"), 1, "Outdated Reading 1 with mode text"); -is(FhemTestUtils_gotEvent("H1:TestReading2-1: old - was Off"), 1, "Outdated Reading 2 with mode expression"); +is(FhemTestUtils_gotEvent("H1:TestReading2-1: old - was tvlights"), 1, "Outdated Reading 2 with mode expression"); is(FhemTestUtils_gotEvent("H1:TestReading2-2: 789"), 1, "Outdated Reading 3 with mode reading"); is(FhemTestUtils_gotEvent("H1:TestReading2-3: H1"), 1, "Outdated Reading 4 with mode internal"); is(FhemTestUtils_gotEvent("H1:TestReading2-4:"), 1, "Outdated Reading 5 with mode delete"); diff --git a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t index 64c101425..9938a2d5a 100644 --- a/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t +++ b/fhem/t/FHEM/98_HTTPMOD/90_SmallFeatures.t @@ -5,10 +5,25 @@ use strict; use warnings; use Test::More; +my $hash = $defs{'H2'}; +my $modVersion = $hash->{ModuleVersion}; +$modVersion =~ /^([0-9]+)\./; +my $major = $1; + +if ($major && $major >= 4) { + plan tests => 3; +} else { + plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion"; +} + fhem('attr H2 bodyDecode none'); fhem('set H2 reread'); -is(FhemTestUtils_gotEvent("H2:Fhem_Mem"), 1, "memReading"); +SKIP: { + skip "this test can only run on Linux", 1 if (!-e "/proc/$$/status"); + is(FhemTestUtils_gotEvent("H2:Fhem_Mem"), 1, "memReading"); +} + is(FhemTestUtils_gotEvent("H2:TestReading1: \x8e\x6e"), 1, "TestReading without bodyDecode"); fhem('attr H2 bodyDecode auto');