main_test.go 876 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/cdelorme/staticmd"
  6. )
  7. func init() {
  8. exit = func(_ int) {}
  9. getwd = func() (string, error) { return "", nil }
  10. }
  11. var mockError error
  12. type mockGenerator struct{}
  13. func (self *mockGenerator) Generate() error { return mockError }
  14. func TestPlacebo(_ *testing.T) {}
  15. func TestMain(_ *testing.T) {
  16. os.Args = []string{}
  17. main()
  18. }
  19. func TestConfigure(t *testing.T) {
  20. // set a value on all parameters
  21. os.Args = []string{"-t", "afile", "-i", "/in/", "-o", "/out/", "-b", "-r"}
  22. // run configure & check results
  23. s := configure()
  24. if s == nil {
  25. t.FailNow()
  26. }
  27. // cast and check values on s
  28. g, e := s.(*staticmd.Generator)
  29. if !e {
  30. t.FailNow()
  31. }
  32. // check values on generator match cli parameters
  33. if g.Input != "/in/" || g.Output != "/out/" || !g.Relative || !g.Book || g.TemplateFile != "afile" {
  34. t.FailNow()
  35. }
  36. }