markdown_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package static
  2. import (
  3. "io"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. )
  8. type mockLogger struct{}
  9. func (l *mockLogger) Debug(string, ...interface{}) {}
  10. func (l *mockLogger) Info(string, ...interface{}) {}
  11. func (l *mockLogger) Error(string, ...interface{}) {}
  12. func TestMarkdown(t *testing.T) {
  13. var files []*os.File
  14. // abstract behaviors
  15. o := func(b []byte) []byte { return b }
  16. readall = func(f io.Reader) ([]byte, error) { return []byte{}, nil }
  17. mkdirall = func(d string, f os.FileMode) error { return nil }
  18. create = func(n string) (*os.File, error) {
  19. tfo, e := ioutil.TempFile(os.TempDir(), "static-out")
  20. files = append(files, tfo)
  21. return tfo, e
  22. }
  23. open = func(n string) (*os.File, error) {
  24. tfi, e := ioutil.TempFile(os.TempDir(), "static-in")
  25. files = append(files, tfi)
  26. return tfi, e
  27. }
  28. // execute operation book mode
  29. m := &Markdown{L: &mockLogger{}}
  30. if e := m.Run(o); e != nil {
  31. t.Error(e)
  32. }
  33. // execute operation web mode
  34. m.Web = true
  35. if e := m.Run(o); e != nil {
  36. t.Error(e)
  37. }
  38. // remove all temporary files
  39. for i := range files {
  40. os.Remove(files[i].Name())
  41. }
  42. }