PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/test/passenger_pane/cli_test.nu

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