Skip to content

Commit

Permalink
Make mudbrick_test less brittle
Browse files Browse the repository at this point in the history
Make IDs predictable across versions
  • Loading branch information
camelpunch committed Oct 22, 2024
1 parent b1ed383 commit ab52a91
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions test/mudbrick_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ defmodule MudbrickTest do
a new line!\
""")
|> page(size: Page.size(:a4))
|> render()
|> to_string() ==
|> comparable() ==
"""
%PDF-2.0
%����
Expand Down Expand Up @@ -121,8 +120,8 @@ defmodule MudbrickTest do
</dc:title>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
<xmpMM:DocumentID>OZwlvvscl2EvtNnawU3bf4LcjVKMXc7miQZtxrzmFCk</xmpMM:DocumentID>
<xmpMM:InstanceID>z1MfnkCKfrWi4OT2JJpEYwwMAc28M/7FlCLRHXNRAss</xmpMM:InstanceID>
<xmpMM:DocumentID>0000000000000000000000000000000000000000000</xmpMM:DocumentID>
<xmpMM:InstanceID>0000000000000000000000000000000000000000000</xmpMM:InstanceID>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Expand Down Expand Up @@ -210,8 +209,7 @@ defmodule MudbrickTest do
test "can serialise with one empty page" do
assert new()
|> page()
|> render()
|> to_string() ==
|> comparable() ==
"""
%PDF-2.0
%����
Expand Down Expand Up @@ -239,8 +237,8 @@ defmodule MudbrickTest do
</dc:title>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
<xmpMM:DocumentID>tmkxRntcYJxXApecOCsIkUzOKj982KUmBE28bsh/Btw</xmpMM:DocumentID>
<xmpMM:InstanceID>hfuu1Fk+glpWfauCVDrYAyuxMOSG+1ZzxKrGCxzE+XY</xmpMM:InstanceID>
<xmpMM:DocumentID>0000000000000000000000000000000000000000000</xmpMM:DocumentID>
<xmpMM:InstanceID>0000000000000000000000000000000000000000000</xmpMM:InstanceID>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Expand Down Expand Up @@ -300,8 +298,7 @@ defmodule MudbrickTest do

test "can serialise with no pages" do
assert new()
|> render()
|> to_string() ==
|> comparable() ==
"""
%PDF-2.0
%����
Expand Down Expand Up @@ -329,8 +326,8 @@ defmodule MudbrickTest do
</dc:title>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
<xmpMM:DocumentID>tmkxRntcYJxXApecOCsIkUzOKj982KUmBE28bsh/Btw</xmpMM:DocumentID>
<xmpMM:InstanceID>hfuu1Fk+glpWfauCVDrYAyuxMOSG+1ZzxKrGCxzE+XY</xmpMM:InstanceID>
<xmpMM:DocumentID>0000000000000000000000000000000000000000000</xmpMM:DocumentID>
<xmpMM:InstanceID>0000000000000000000000000000000000000000000</xmpMM:InstanceID>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Expand Down Expand Up @@ -371,6 +368,16 @@ defmodule MudbrickTest do
"""
end

def comparable(doc) do
doc
|> render()
|> to_string()
|> String.replace(
~r{<xmpMM:(Document|Instance)ID>.*</xmpMM:(Document|Instance)ID>},
"<xmpMM:\\1ID>0000000000000000000000000000000000000000000</xmpMM:\\2ID>"
)
end

def output(chain) do
tap(chain, fn rendered ->
File.write("test.pdf", rendered)
Expand Down

0 comments on commit ab52a91

Please sign in to comment.