Skip to content

Commit ab52a91

Browse files
committed
Make mudbrick_test less brittle
Make IDs predictable across versions
1 parent b1ed383 commit ab52a91

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

test/mudbrick_test.exs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ defmodule MudbrickTest do
7878
a new line!\
7979
""")
8080
|> page(size: Page.size(:a4))
81-
|> render()
82-
|> to_string() ==
81+
|> comparable() ==
8382
"""
8483
%PDF-2.0
8584
%����
@@ -121,8 +120,8 @@ defmodule MudbrickTest do
121120
</dc:title>
122121
</rdf:Description>
123122
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
124-
<xmpMM:DocumentID>OZwlvvscl2EvtNnawU3bf4LcjVKMXc7miQZtxrzmFCk</xmpMM:DocumentID>
125-
<xmpMM:InstanceID>z1MfnkCKfrWi4OT2JJpEYwwMAc28M/7FlCLRHXNRAss</xmpMM:InstanceID>
123+
<xmpMM:DocumentID>0000000000000000000000000000000000000000000</xmpMM:DocumentID>
124+
<xmpMM:InstanceID>0000000000000000000000000000000000000000000</xmpMM:InstanceID>
126125
</rdf:Description>
127126
</rdf:RDF>
128127
</x:xmpmeta>
@@ -210,8 +209,7 @@ defmodule MudbrickTest do
210209
test "can serialise with one empty page" do
211210
assert new()
212211
|> page()
213-
|> render()
214-
|> to_string() ==
212+
|> comparable() ==
215213
"""
216214
%PDF-2.0
217215
%����
@@ -239,8 +237,8 @@ defmodule MudbrickTest do
239237
</dc:title>
240238
</rdf:Description>
241239
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
242-
<xmpMM:DocumentID>tmkxRntcYJxXApecOCsIkUzOKj982KUmBE28bsh/Btw</xmpMM:DocumentID>
243-
<xmpMM:InstanceID>hfuu1Fk+glpWfauCVDrYAyuxMOSG+1ZzxKrGCxzE+XY</xmpMM:InstanceID>
240+
<xmpMM:DocumentID>0000000000000000000000000000000000000000000</xmpMM:DocumentID>
241+
<xmpMM:InstanceID>0000000000000000000000000000000000000000000</xmpMM:InstanceID>
244242
</rdf:Description>
245243
</rdf:RDF>
246244
</x:xmpmeta>
@@ -300,8 +298,7 @@ defmodule MudbrickTest do
300298

301299
test "can serialise with no pages" do
302300
assert new()
303-
|> render()
304-
|> to_string() ==
301+
|> comparable() ==
305302
"""
306303
%PDF-2.0
307304
%����
@@ -329,8 +326,8 @@ defmodule MudbrickTest do
329326
</dc:title>
330327
</rdf:Description>
331328
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
332-
<xmpMM:DocumentID>tmkxRntcYJxXApecOCsIkUzOKj982KUmBE28bsh/Btw</xmpMM:DocumentID>
333-
<xmpMM:InstanceID>hfuu1Fk+glpWfauCVDrYAyuxMOSG+1ZzxKrGCxzE+XY</xmpMM:InstanceID>
329+
<xmpMM:DocumentID>0000000000000000000000000000000000000000000</xmpMM:DocumentID>
330+
<xmpMM:InstanceID>0000000000000000000000000000000000000000000</xmpMM:InstanceID>
334331
</rdf:Description>
335332
</rdf:RDF>
336333
</x:xmpmeta>
@@ -371,6 +368,16 @@ defmodule MudbrickTest do
371368
"""
372369
end
373370

371+
def comparable(doc) do
372+
doc
373+
|> render()
374+
|> to_string()
375+
|> String.replace(
376+
~r{<xmpMM:(Document|Instance)ID>.*</xmpMM:(Document|Instance)ID>},
377+
"<xmpMM:\\1ID>0000000000000000000000000000000000000000000</xmpMM:\\2ID>"
378+
)
379+
end
380+
374381
def output(chain) do
375382
tap(chain, fn rendered ->
376383
File.write("test.pdf", rendered)

0 commit comments

Comments
 (0)