Skip to content
This repository
tree: 85b3ba4c90
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 79 lines (66 sloc) 3.145 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
(load "test_helper")

(describe "CLI" `(
  (before (do ()
    (set @cli ((CLI alloc) init))
  ))
  
  (it "is not authorized by default" (do ()
    (~ (@cli isAuthorized) should be:false)
  ))
))

(describe "CLI, when unauthorized" `(do
  (before (do ()
    (set @cli ((CLI alloc) init))
    (@cli setPathToCLI:pathToCLI)
  ))
  
  (it "lists currently configured applications" (do ()
    (set applications (@cli listApplications))
    (~ (applications count) should be:3)
    (set hostnames `())
    (for ((set index 0) (< index (applications count)) (set index (+ index 1)))
      (set application (applications objectAtIndex:index) description)
      (set hostnames (append hostnames (list (application host))))
    )
    (~ hostnames should equal:`("manager.boom.local" "scoring.boom.local" "diagnose.local"))
  ))
  
  (it "restarts an application" (do ()
    (set applications (@cli listApplications))
    (@cli restart:(applications objectAtIndex:0))
    
    (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
    (~ arguments should equal:"[\"restart\", \"manager.boom.local\"]")
  ))
))

(describe "CLI, when authorized" `(do
  (before (do ()
    (set @cli ((CLI alloc) init))
    (@cli setPathToCLI:pathToCLI)
    (@cli fakeAuthorize)
    
    (set attributes (NSMutableDictionary dictionary))
    (attributes setValue:"test.local" forKey:"host")
    (attributes setValue:"assets.test.local" forKey:"aliases")
    (attributes setValue:"/path/to/test" forKey:"path")
    (attributes setValue:"production" forKey:"environment")
    (attributes setValue:"/path/to/test.conf" forKey:"config_filename")
    (set @application ((Application alloc) initWithAttributes:attributes))
  ))
  
  (it "adds a new application" (do ()
    (@cli add:@application)
    (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
    (~ 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\"]")
  ))
  
  (it "updates an application" (do ()
    (@cli update:@application)
    (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
    (~ 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\"]")
  ))
  
  (it "deletes an application" (do ()
    (@cli delete:@application)
    (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
    (~ arguments should equal:"[\"delete\", \"test.local\"]")
  ))
  
  (it "restarts an application" (do ()
    (@cli restart:@application)
    (set arguments (NSString stringWithContentsOfFile:pathToCLIArguments encoding:NSUTF8StringEncoding error:nil))
    (~ arguments should equal:"[\"restart\", \"test.local\"]")
  ))
))

((Bacon sharedInstance) run)
Something went wrong with that request. Please try again.