kubo/assets/assets_test.go
Steven Allen 3883dfe450 assets: move away from gx
1. Use a submodule for dir-index-html. This isn't a go dependency and treating
   it like one is more trouble than it's worth. We don't actually need to
   checkout the submodule unless we need to regenerate the assets.
2. Avoid a runtime dependency on dir-index-html (may shave a few bytes off the
   final binary?).
3. Remove unused code.
4. Avoid bundling unused files.
5. Switch to a maintained version of go-bindata.
6. Use go mod to manage go-bindata.
2019-06-11 15:36:47 -07:00

54 lines
1.0 KiB
Go

package assets
import (
"bytes"
"io/ioutil"
"sync"
"testing"
)
// TestEmbeddedDocs makes sure we don't forget to regenerate after documentation change
func TestEmbeddedDocs(t *testing.T) {
testNFiles(initDocPaths, 5, t, "documents")
}
func testNFiles(fs []string, wantCnt int, t *testing.T, ftype string) {
if len(fs) < wantCnt {
t.Fatalf("expected %d %s. got %d", wantCnt, ftype, len(fs))
}
var wg sync.WaitGroup
for _, f := range fs {
wg.Add(1)
// compare asset
go func(f string) {
defer wg.Done()
testOneFile(f, t)
}(f)
}
wg.Wait()
}
func testOneFile(f string, t *testing.T) {
// load data from filesystem (git)
vcsData, err := ioutil.ReadFile(f)
if err != nil {
t.Errorf("asset %s: could not read vcs file: %s", f, err)
return
}
// load data from emdedded source
embdData, err := Asset(f)
if err != nil {
t.Errorf("asset %s: could not read vcs file: %s", f, err)
return
}
if !bytes.Equal(vcsData, embdData) {
t.Errorf("asset %s: vcs and embedded data isnt equal", f)
return
}
t.Logf("checked %s", f)
}