Update blorg test - make it actually fail when public changes

This commit is contained in:
Niklas Fasching 2020-06-26 22:19:02 +02:00
parent d7ef673644
commit c536adf6e9
3 changed files with 26 additions and 1 deletions

View file

@ -1,6 +1,12 @@
package blorg package blorg
import "testing" import (
"fmt"
"io/ioutil"
"os/exec"
"strings"
"testing"
)
func TestBlorg(t *testing.T) { func TestBlorg(t *testing.T) {
config, err := ReadConfig("testdata/blorg.org") config, err := ReadConfig("testdata/blorg.org")
@ -8,7 +14,23 @@ func TestBlorg(t *testing.T) {
t.Errorf("Could not read config: %s", err) t.Errorf("Could not read config: %s", err)
return return
} }
commitedHashBs, err := ioutil.ReadFile("testdata/public.md5")
if err != nil {
t.Errorf("Could not read hash bytes: %s", err)
return
}
if err := config.Render(); err != nil { if err := config.Render(); err != nil {
t.Errorf("Could not render: %s", err) t.Errorf("Could not render: %s", err)
return
}
renderedHashBs, err := exec.Command("bash", "-c", fmt.Sprintf("find %s -type f | sort -u | xargs cat | md5sum", config.PublicDir)).Output()
if err != nil {
t.Errorf("Could not hash PublicDir: %s", err)
return
}
rendered, committed := strings.TrimSpace(string(renderedHashBs)), strings.TrimSpace(string(commitedHashBs))
if rendered != committed {
t.Errorf("PublicDir hashes do not match: '%s' -> '%s'", committed, rendered)
return
} }
} }

1
blorg/testdata/public.md5 vendored Normal file
View file

@ -0,0 +1 @@
89cf2d231acc494dde0a4f565e668242 -

View file

@ -5,3 +5,5 @@ for org_file in org/testdata/*.org; do
./go-org render $org_file html > org/testdata/$(basename $org_file .org).html ./go-org render $org_file html > org/testdata/$(basename $org_file .org).html
./go-org render $org_file org > org/testdata/$(basename $org_file .org).pretty_org ./go-org render $org_file org > org/testdata/$(basename $org_file .org).pretty_org
done done
find blorg/testdata/public -type f | sort -u | xargs cat | md5sum > blorg/testdata/public.md5