notes-server/notes/file_test.go

50 lines
735 B
Go
Executable File

package notes
import (
"fmt"
"io/ioutil"
"gitea.inhome.blapointe.com/local/notes-server/config"
"os"
"path"
"strings"
"testing"
)
func TestFile(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "until*")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
fmt.Fprintln(f, `
# Hello
## World
* This
* is
* bullets
| My | table | goes |
|----|-------|------|
| h | e | n |
`)
f.Close()
n := &Notes{}
config.Root = "/"
s, err := n.File(path.Join("notes", f.Name()))
if err != nil {
t.Fatal(err)
}
shouldContain := []string{
"tbody",
"h1",
"h2",
}
for _, should := range shouldContain {
if !strings.Contains(s, should) {
t.Fatalf("%s: %s", should, s)
}
}
t.Logf("%s", s)
}