From 8daebbd6b41177ee1e0de79257f162aa4b486766 Mon Sep 17 00:00:00 2001
From: Shulhan
Date: Thu, 13 Feb 2025 19:58:04 +0700
Subject: 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.
---
Makefile | 1 +
document_test.go | 18 ++++++++++++------
testdata/test.exp.html | 2 +-
testdata/test.got.html | 2 +-
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.