aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-02-13 19:58:04 +0700
committerShulhan <ms@kilabit.info>2025-02-13 20:32:18 +0700
commit8daebbd6b41177ee1e0de79257f162aa4b486766 (patch)
tree6a47669f97ba5c70706cf0a9a3e14877f7b72c94
parent48843938adc4f6c687b61808ba8122b94299c642 (diff)
downloadasciidoctor-go-8daebbd6b41177ee1e0de79257f162aa4b486766.tar.xz
testdata: redact the "Last updated" time in test-parser HTML files
Every time we execute "make test-parser", the generated HTML files will changes the "Last updated xxx" (where xxx is the time its executed). This changes prevent this unnecessary diff in the future.
-rw-r--r--Makefile1
-rw-r--r--document_test.go18
-rw-r--r--testdata/test.exp.html2
-rw-r--r--testdata/test.got.html2
4 files changed, 15 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 8ef844a..51bf801 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@ test-parser:
asciidoctor \
--out-file=testdata/test.exp.html \
testdata/test.adoc
+ sed -i 's/Last updated \(.*\)/Last updated [REDACTED]/' testdata/test.exp.html
go test -v -run=Open .
.PHONY: serve-doc
diff --git a/document_test.go b/document_test.go
index f22313d..0c160c5 100644
--- a/document_test.go
+++ b/document_test.go
@@ -4,7 +4,9 @@
package asciidoctor
import (
+ "bytes"
"os"
+ "regexp"
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
@@ -12,11 +14,9 @@ import (
func TestOpen(t *testing.T) {
var (
- doc *Document
- fout *os.File
- err error
+ doc *Document
+ err error
)
-
doc, err = Open(`testdata/test.adoc`)
if err != nil {
t.Fatal(err)
@@ -26,12 +26,18 @@ func TestOpen(t *testing.T) {
// generator, we override ourself.
doc.Attributes.Entry[DocAttrGenerator] = `Asciidoctor 2.0.18`
- fout, err = os.OpenFile(`testdata/test.got.html`, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
+ var buf bytes.Buffer
+
+ err = doc.ToHTML(&buf)
if err != nil {
t.Fatal(err)
}
- err = doc.ToHTML(fout)
+ var redactLastUpdated = regexp.MustCompile(`Last updated (.*)`)
+ var got = redactLastUpdated.ReplaceAll(buf.Bytes(),
+ []byte(`Last updated [REDACTED]`))
+
+ err = os.WriteFile(`testdata/test.got.html`, got, 0600)
if err != nil {
t.Fatal(err)
}
diff --git a/testdata/test.exp.html b/testdata/test.exp.html
index 309d46f..f18a625 100644
--- a/testdata/test.exp.html
+++ b/testdata/test.exp.html
@@ -3498,7 +3498,7 @@ this sidebar.</p>
<div id="footer">
<div id="footer-text">
1.1.1<br>
-Last updated 2025-01-02 20:10:48 +0700
+Last updated [REDACTED]
</div>
</div>
</body>
diff --git a/testdata/test.got.html b/testdata/test.got.html
index 07a1028..240a961 100644
--- a/testdata/test.got.html
+++ b/testdata/test.got.html
@@ -3501,7 +3501,7 @@ this sidebar.</p>
<div id="footer">
<div id="footer-text">
1.1.1<br>
-Last updated 2025-01-02 20:10:48 +0700
+Last updated [REDACTED]
</div>
</div>
</body>