main_test.go 964 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. type mockLogger struct{}
  15. func (self *mockLogger) Error(_ string, _ ...interface{}) {}
  16. func TestPlacebo(_ *testing.T) {}
  17. func TestMain(_ *testing.T) {
  18. os.Args = []string{}
  19. main()
  20. }
  21. func TestConfigure(t *testing.T) {
  22. // set a value on all parameters
  23. os.Args = []string{"-t", "afile", "-i", "/in/", "-o", "/out/", "-b", "-r"}
  24. // run configure & check results
  25. s, l := configure()
  26. if s == nil || l == nil {
  27. t.FailNow()
  28. }
  29. // cast and check values on s
  30. g, e := s.(*staticmd.Generator)
  31. if !e {
  32. t.FailNow()
  33. }
  34. // check values on generator match cli parameters
  35. if g.Input != "/in/" || g.Output != "/out/" || !g.Book || g.TemplateFile != "afile" {
  36. t.FailNow()
  37. }
  38. }