/test/passenger_pane/cli_test.nu

http://github.com/tgunr/passengerpane · Nushell · 84 lines · 70 code · 14 blank · 0 comment · 0 complexity · 1b022ea86e7ab7d7e12a01e3e5695171 MD5 · raw file

  1. (load "test_helper")
  2. (describe "CLI" `(
  3. (before (do ()
  4. (set @cli ((CLI alloc) init))
  5. ))
  6. (it "is not authorized by default" (do ()
  7. (~ (@cli isAuthorized) should be:false)
  8. ))
  9. ))
  10. (describe "CLI, when unauthorized" `(do
  11. (before (do ()
  12. (set @cli ((CLI alloc) init))
  13. (@cli setPathToCLI:pathToCLI)
  14. ))
  15. (it "lists currently configured applications" (do ()
  16. (set applications (@cli listApplications))
  17. (~ (applications count) should be:3)
  18. (set hostnames `())
  19. (for ((set index 0) (< index (applications count)) (set index (+ index 1)))
  20. (set application (applications objectAtIndex:index) description)
  21. (set hostnames (append hostnames (list (application host))))
  22. )
  23. (~ hostnames should equal:`("manager.boom.local" "scoring.boom.local" "diagnose.local"))
  24. ))
  25. (it "restarts an application" (do ()
  26. (set applications (@cli listApplications))
  27. (@cli restart:(applications objectAtIndex:0))
  28. (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
  29. (~ arguments should equal:"[\"restart\", \"manager.boom.local\"]")
  30. ))
  31. (it "knows whether the Passenger module is installed" (do ()
  32. (set installed (@cli isPassengerModuleInstalled))
  33. (~ installed should equal:false)
  34. ))
  35. ))
  36. (describe "CLI, when authorized" `(do
  37. (before (do ()
  38. (set @cli ((CLI alloc) init))
  39. (@cli setPathToCLI:pathToCLI)
  40. (@cli fakeAuthorize)
  41. (set attributes (NSMutableDictionary dictionary))
  42. (attributes setValue:"test.local" forKey:"host")
  43. (attributes setValue:"assets.test.local" forKey:"aliases")
  44. (attributes setValue:"/path/to/test" forKey:"path")
  45. (attributes setValue:"production" forKey:"environment")
  46. (attributes setValue:"/path/to/test.conf" forKey:"config_filename")
  47. (set @application ((Application alloc) initWithAttributes:attributes))
  48. ))
  49. (it "adds a new application" (do ()
  50. (@cli add:@application)
  51. (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
  52. (~ arguments should equal:"[\"add\", \"/path/to/test\", \"-path\", \"/path/to/test\", \"-environment\", \"production\", \"-host\", \"test.local\", \"-config_filename\", \"/path/to/test.conf\", \"-aliases\", \"assets.test.local\"]")
  53. ))
  54. (it "updates an application" (do ()
  55. (@cli update:@application)
  56. (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
  57. (~ arguments should equal:"[\"update\", \"test.local\", \"-path\", \"/path/to/test\", \"-environment\", \"production\", \"-host\", \"test.local\", \"-config_filename\", \"/path/to/test.conf\", \"-aliases\", \"assets.test.local\"]")
  58. ))
  59. (it "deletes an application" (do ()
  60. (@cli delete:@application)
  61. (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
  62. (~ arguments should equal:"[\"delete\", \"test.local\"]")
  63. ))
  64. (it "restarts an application" (do ()
  65. (@cli restart:@application)
  66. (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
  67. (~ arguments should equal:"[\"restart\", \"test.local\"]")
  68. ))
  69. ))
  70. ((Bacon sharedInstance) run)