z_test.go 672 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package mjs
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "os"
  7. "testing"
  8. )
  9. var contentPath = "content"
  10. func filePath(name string) string {
  11. return fmt.Sprintf("%v/%v", contentPath, name)
  12. }
  13. func modified(name string) (res int64) {
  14. if info, err := os.Stat(filePath(name)); err == nil {
  15. res = info.ModTime().Unix()
  16. }
  17. return
  18. }
  19. func content(name string) ([]byte, error) {
  20. return ioutil.ReadFile(filePath(name))
  21. }
  22. func TestMJS(t *testing.T) {
  23. mjs := New(modified, content)
  24. for i := 0; i < 20; i++ {
  25. modified, err := mjs.Exec("main", map[string]interface{}{
  26. "flush": func(args ...interface{}) {
  27. log.Println(args)
  28. },
  29. })
  30. t.Log(err, err == nil, modified)
  31. }
  32. }