scansion: Use captures or wildcards instead of mocking time
authorKim Alvefur <zash@zash.se>
Sun, 17 Dec 2023 16:29:03 +0100
changeset 13409 c8f3cfe59e90
parent 13408 034c7af177f0
child 13410 3adc67301722
scansion: Use captures or wildcards instead of mocking time > Mockery is one of the things I hold dear! And he's making a mockery of it!! -- Belkar Bitterleaf
spec/scansion/extdisco.scs
spec/scansion/lastactivity.scs
spec/scansion/mam_extended.scs
spec/scansion/prosody.cfg.lua
spec/scansion/uptime.scs
--- a/spec/scansion/extdisco.scs	Sat Dec 16 13:47:55 2023 +0100
+++ b/spec/scansion/extdisco.scs	Sun Dec 17 16:29:03 2023 +0100
@@ -17,8 +17,8 @@
 	<iq type='result' id='lx2' from='localhost'>
 		<services xmlns='urn:xmpp:extdisco:2'>
 			<service host='default.example' transport='udp' port='9876' type='stun'/>
-			<service port='9876' type='turn' restricted='1' password='yHYYBDN7M3mdlug0LTdJbW0GvvQ=' transport='udp' host='default.example' username='1219525744'/>
-			<service port='9876' type='turn' restricted='1' password='1Uc6QfrDhIlbK97rGCUQ/cUICxs=' transport='udp' host='default.example' username='1219525744'/>
+			<service port='9876' type='turn' restricted='1' password='{scansion:any}' transport='udp' host='default.example' username='{scansion:any}'/>
+			<service port='9876' type='turn' restricted='1' password='{scansion:any}' transport='udp' host='default.example' username='{scansion:any}'/>
 			<service port='2121' type='ftp' restricted='1' password='password' transport='tcp' host='default.example' username='john'/>
 			<service port='21' type='ftp' restricted='1' password='password' transport='tcp' host='ftp.example.com' username='john'/>
 		</services>
@@ -47,8 +47,8 @@
 Romeo receives:
 	<iq type='result' id='lx4' from='localhost'>
 		<credentials xmlns='urn:xmpp:extdisco:2'>
-			<service port='9876' type='turn' restricted='1' password='yHYYBDN7M3mdlug0LTdJbW0GvvQ=' transport='udp' host='default.example' username='1219525744'/>
-			<service port='9876' type='turn' restricted='1' password='1Uc6QfrDhIlbK97rGCUQ/cUICxs=' transport='udp' host='default.example' username='1219525744'/>
+			<service port='9876' type='turn' restricted='1' password='{scansion:any}' transport='udp' host='default.example' username='{scansion:any}'/>
+			<service port='9876' type='turn' restricted='1' password='{scansion:any}' transport='udp' host='default.example' username='{scansion:any}'/>
 		</credentials>
 	</iq>
 
--- a/spec/scansion/lastactivity.scs	Sat Dec 16 13:47:55 2023 +0100
+++ b/spec/scansion/lastactivity.scs	Sun Dec 17 16:29:03 2023 +0100
@@ -37,7 +37,7 @@
 
 Romeo receives:
 	<iq type='result' id='a'>
-		<query xmlns='jabber:iq:last' seconds='0'>Goodbye</query>
+		<query xmlns='jabber:iq:last' seconds='{scansion:any}'>Goodbye</query>
 	</iq>
 
 Romeo disconnects
--- a/spec/scansion/mam_extended.scs	Sat Dec 16 13:47:55 2023 +0100
+++ b/spec/scansion/mam_extended.scs	Sun Dec 17 16:29:03 2023 +0100
@@ -45,8 +45,8 @@
 Romeo receives:
 	<iq type="result" id="mamextmeta">
 		<metadata xmlns="urn:xmpp:mam:2">
-			<start timestamp="2008-08-22T21:09:04.500000Z" xmlns="urn:xmpp:mam:2" id="{scansion:any}"/>
-			<end timestamp="2008-08-22T21:09:04.500000Z" xmlns="urn:xmpp:mam:2" id="{scansion:any}"/>
+			<start timestamp="{scansion:capture:start}" xmlns="urn:xmpp:mam:2" id="{scansion:capture:first}"/>
+			<end timestamp="{scansion:capture:end}" xmlns="urn:xmpp:mam:2" id="{scansion:capture:last}"/>
 		</metadata>
 	</iq>
 
@@ -57,9 +57,9 @@
 
 Romeo receives:
 	<message to="${Romeo's full JID}">
-		<result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:any}">
+		<result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:capture:first}">
 			<forwarded xmlns="urn:xmpp:forward:0">
-				<delay stamp="2008-08-22T21:09:04.500000Z" xmlns="urn:xmpp:delay"/>
+				<delay stamp="{scansion:capture:start}" xmlns="urn:xmpp:delay"/>
 				<message to="someone@localhost" xmlns="jabber:client" type="chat" xml:lang="en" id="chat01" from="${Romeo's full JID}">
 					<body>Hello</body>
 				</message>
@@ -69,9 +69,9 @@
 
 Romeo receives:
 	<message to="${Romeo's full JID}">
-		<result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:any}">
+		<result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:capture:last}">
 			<forwarded xmlns="urn:xmpp:forward:0">
-				<delay stamp="2008-08-22T21:09:04.500000Z" xmlns="urn:xmpp:delay"/>
+				<delay stamp="{scansion:capture:end}" xmlns="urn:xmpp:delay"/>
 				<message to="someone@localhost" xmlns="jabber:client" type="chat" xml:lang="en" id="chat02" from="${Romeo's full JID}">
 					<body>U there?</body>
 				</message>
@@ -98,7 +98,7 @@
 	<message to="${Romeo's full JID}">
 		<result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:any}">
 			<forwarded xmlns="urn:xmpp:forward:0">
-				<delay stamp="2008-08-22T21:09:04.500000Z" xmlns="urn:xmpp:delay"/>
+				<delay stamp="{scansion:capture:start}" xmlns="urn:xmpp:delay"/>
 				<message to="someone@localhost" xmlns="jabber:client" type="chat" xml:lang="en" id="chat02" from="${Romeo's full JID}">
 					<body>U there?</body>
 				</message>
@@ -110,7 +110,7 @@
 	<message to="${Romeo's full JID}">
 		<result xmlns="urn:xmpp:mam:2" queryid="q1" id="{scansion:any}">
 			<forwarded xmlns="urn:xmpp:forward:0">
-				<delay stamp="2008-08-22T21:09:04.500000Z" xmlns="urn:xmpp:delay"/>
+				<delay stamp="{scansion:capture:end}" xmlns="urn:xmpp:delay"/>
 				<message to="someone@localhost" xmlns="jabber:client" type="chat" xml:lang="en" id="chat01" from="${Romeo's full JID}">
 					<body>Hello</body>
 				</message>
--- a/spec/scansion/prosody.cfg.lua	Sat Dec 16 13:47:55 2023 +0100
+++ b/spec/scansion/prosody.cfg.lua	Sun Dec 17 16:29:03 2023 +0100
@@ -1,15 +1,5 @@
 --luacheck: ignore
 
--- Mock time functions to simplify tests --
-local time = require "util.time";
-function _G.os.time()
-	return 1219439344;
-end
-function time.now()
-	return 1219439344.5;
-end
--------------------------------------------
-
 admins = { "admin@localhost" }
 
 network_backend = ENV_PROSODY_NETWORK_BACKEND or "epoll"
--- a/spec/scansion/uptime.scs	Sat Dec 16 13:47:55 2023 +0100
+++ b/spec/scansion/uptime.scs	Sun Dec 17 16:29:03 2023 +0100
@@ -15,7 +15,7 @@
 
 Romeo receives:
 	<iq type='result' id='a' from='localhost'>
-		<query xmlns='jabber:iq:last' seconds='0'/>
+		<query xmlns='jabber:iq:last' seconds='{scansion:any}'/>
 	</iq>
 
 Romeo disconnects