MuranoCLI 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +27 -0
  6. data/LICENSE.txt +19 -0
  7. data/MuranoCLI.gemspec +50 -0
  8. data/MuranoCLI.iss +50 -0
  9. data/README.markdown +208 -0
  10. data/Rakefile +188 -0
  11. data/TODO.taskpaper +122 -0
  12. data/bin/mr +8 -0
  13. data/bin/murano +84 -0
  14. data/docs/demo.md +109 -0
  15. data/lib/MrMurano/Account.rb +211 -0
  16. data/lib/MrMurano/Config-Migrate.rb +47 -0
  17. data/lib/MrMurano/Config.rb +286 -0
  18. data/lib/MrMurano/Mock.rb +63 -0
  19. data/lib/MrMurano/Product-1P-Device.rb +145 -0
  20. data/lib/MrMurano/Product-Resources.rb +195 -0
  21. data/lib/MrMurano/Product.rb +358 -0
  22. data/lib/MrMurano/ProjectFile.rb +349 -0
  23. data/lib/MrMurano/Solution-Cors.rb +46 -0
  24. data/lib/MrMurano/Solution-Endpoint.rb +177 -0
  25. data/lib/MrMurano/Solution-File.rb +150 -0
  26. data/lib/MrMurano/Solution-ServiceConfig.rb +140 -0
  27. data/lib/MrMurano/Solution-Services.rb +326 -0
  28. data/lib/MrMurano/Solution-Users.rb +129 -0
  29. data/lib/MrMurano/Solution.rb +59 -0
  30. data/lib/MrMurano/SubCmdGroupContext.rb +49 -0
  31. data/lib/MrMurano/SyncUpDown.rb +565 -0
  32. data/lib/MrMurano/commands/assign.rb +57 -0
  33. data/lib/MrMurano/commands/businessList.rb +45 -0
  34. data/lib/MrMurano/commands/completion.rb +152 -0
  35. data/lib/MrMurano/commands/config.rb +67 -0
  36. data/lib/MrMurano/commands/content.rb +130 -0
  37. data/lib/MrMurano/commands/cors.rb +30 -0
  38. data/lib/MrMurano/commands/domain.rb +17 -0
  39. data/lib/MrMurano/commands/gb.rb +33 -0
  40. data/lib/MrMurano/commands/init.rb +138 -0
  41. data/lib/MrMurano/commands/keystore.rb +157 -0
  42. data/lib/MrMurano/commands/logs.rb +78 -0
  43. data/lib/MrMurano/commands/mock.rb +63 -0
  44. data/lib/MrMurano/commands/password.rb +88 -0
  45. data/lib/MrMurano/commands/postgresql.rb +41 -0
  46. data/lib/MrMurano/commands/product.rb +14 -0
  47. data/lib/MrMurano/commands/productCreate.rb +39 -0
  48. data/lib/MrMurano/commands/productDelete.rb +33 -0
  49. data/lib/MrMurano/commands/productDevice.rb +84 -0
  50. data/lib/MrMurano/commands/productDeviceIdCmds.rb +86 -0
  51. data/lib/MrMurano/commands/productList.rb +45 -0
  52. data/lib/MrMurano/commands/productWrite.rb +27 -0
  53. data/lib/MrMurano/commands/show.rb +80 -0
  54. data/lib/MrMurano/commands/solution.rb +14 -0
  55. data/lib/MrMurano/commands/solutionCreate.rb +39 -0
  56. data/lib/MrMurano/commands/solutionDelete.rb +34 -0
  57. data/lib/MrMurano/commands/solutionList.rb +45 -0
  58. data/lib/MrMurano/commands/status.rb +92 -0
  59. data/lib/MrMurano/commands/sync.rb +60 -0
  60. data/lib/MrMurano/commands/timeseries.rb +115 -0
  61. data/lib/MrMurano/commands/tsdb.rb +271 -0
  62. data/lib/MrMurano/commands/usage.rb +23 -0
  63. data/lib/MrMurano/commands/zshcomplete.erb +112 -0
  64. data/lib/MrMurano/commands.rb +32 -0
  65. data/lib/MrMurano/hash.rb +20 -0
  66. data/lib/MrMurano/http.rb +153 -0
  67. data/lib/MrMurano/makePretty.rb +75 -0
  68. data/lib/MrMurano/schema/pf-v1.0.0.yaml +114 -0
  69. data/lib/MrMurano/schema/sf-v0.2.0.yaml +77 -0
  70. data/lib/MrMurano/schema/sf-v0.3.0.yaml +78 -0
  71. data/lib/MrMurano/template/mock.erb +9 -0
  72. data/lib/MrMurano/template/projectFile.murano.erb +81 -0
  73. data/lib/MrMurano/verbosing.rb +99 -0
  74. data/lib/MrMurano/version.rb +4 -0
  75. data/lib/MrMurano.rb +20 -0
  76. data/spec/Account-Passwords_spec.rb +242 -0
  77. data/spec/Account_spec.rb +272 -0
  78. data/spec/ConfigFile_spec.rb +50 -0
  79. data/spec/ConfigMigrate_spec.rb +89 -0
  80. data/spec/Config_spec.rb +409 -0
  81. data/spec/Http_spec.rb +204 -0
  82. data/spec/MakePretties_spec.rb +118 -0
  83. data/spec/Mock_spec.rb +53 -0
  84. data/spec/ProductBase_spec.rb +113 -0
  85. data/spec/ProductContent_spec.rb +162 -0
  86. data/spec/ProductResources_spec.rb +329 -0
  87. data/spec/Product_1P_Device_spec.rb +202 -0
  88. data/spec/Product_1P_RPC_spec.rb +175 -0
  89. data/spec/Product_spec.rb +153 -0
  90. data/spec/ProjectFile_spec.rb +324 -0
  91. data/spec/Solution-Cors_spec.rb +164 -0
  92. data/spec/Solution-Endpoint_spec.rb +581 -0
  93. data/spec/Solution-File_spec.rb +212 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +202 -0
  95. data/spec/Solution-ServiceDevice_spec.rb +176 -0
  96. data/spec/Solution-ServiceEventHandler_spec.rb +385 -0
  97. data/spec/Solution-ServiceModules_spec.rb +465 -0
  98. data/spec/Solution-UsersRoles_spec.rb +207 -0
  99. data/spec/Solution_spec.rb +92 -0
  100. data/spec/SyncRoot_spec.rb +83 -0
  101. data/spec/SyncUpDown_spec.rb +495 -0
  102. data/spec/Verbosing_spec.rb +279 -0
  103. data/spec/_workspace.rb +27 -0
  104. data/spec/cmd_assign_spec.rb +51 -0
  105. data/spec/cmd_business_spec.rb +59 -0
  106. data/spec/cmd_common.rb +72 -0
  107. data/spec/cmd_config_spec.rb +68 -0
  108. data/spec/cmd_content_spec.rb +71 -0
  109. data/spec/cmd_cors_spec.rb +50 -0
  110. data/spec/cmd_device_spec.rb +96 -0
  111. data/spec/cmd_domain_spec.rb +32 -0
  112. data/spec/cmd_init_spec.rb +30 -0
  113. data/spec/cmd_keystore_spec.rb +97 -0
  114. data/spec/cmd_password_spec.rb +62 -0
  115. data/spec/cmd_status_spec.rb +239 -0
  116. data/spec/cmd_syncdown_spec.rb +86 -0
  117. data/spec/cmd_syncup_spec.rb +62 -0
  118. data/spec/cmd_usage_spec.rb +36 -0
  119. data/spec/fixtures/.mrmuranorc +9 -0
  120. data/spec/fixtures/ProjectFiles/invalid.yaml +9 -0
  121. data/spec/fixtures/ProjectFiles/only_meta.yaml +24 -0
  122. data/spec/fixtures/ProjectFiles/with_routes.yaml +27 -0
  123. data/spec/fixtures/SolutionFiles/0.2.0.json +20 -0
  124. data/spec/fixtures/SolutionFiles/0.2.0_invalid.json +18 -0
  125. data/spec/fixtures/SolutionFiles/0.2.json +21 -0
  126. data/spec/fixtures/SolutionFiles/0.3.0.json +20 -0
  127. data/spec/fixtures/SolutionFiles/0.3.0_invalid.json +19 -0
  128. data/spec/fixtures/SolutionFiles/0.3.json +20 -0
  129. data/spec/fixtures/SolutionFiles/basic.json +20 -0
  130. data/spec/fixtures/SolutionFiles/secret.json +6 -0
  131. data/spec/fixtures/configfile +9 -0
  132. data/spec/fixtures/dumped_config +42 -0
  133. data/spec/fixtures/mrmuranorc_deleted_bob +8 -0
  134. data/spec/fixtures/mrmuranorc_tool_bob +3 -0
  135. data/spec/fixtures/product_spec_files/example.exoline.spec.yaml +116 -0
  136. data/spec/fixtures/product_spec_files/example.murano.spec.yaml +14 -0
  137. data/spec/fixtures/product_spec_files/gwe.exoline.spec.yaml +21 -0
  138. data/spec/fixtures/product_spec_files/gwe.murano.spec.yaml +16 -0
  139. data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
  140. data/spec/fixtures/product_spec_files/lightbulb.yaml +14 -0
  141. data/spec/fixtures/roles-three.yaml +11 -0
  142. data/spec/fixtures/syncable_content/assets/icon.png +0 -0
  143. data/spec/fixtures/syncable_content/assets/index.html +0 -0
  144. data/spec/fixtures/syncable_content/assets/js/script.js +0 -0
  145. data/spec/fixtures/syncable_content/modules/table_util.lua +58 -0
  146. data/spec/fixtures/syncable_content/routes/manyRoutes.lua +11 -0
  147. data/spec/fixtures/syncable_content/routes/singleRoute.lua +5 -0
  148. data/spec/fixtures/syncable_content/services/devdata.lua +18 -0
  149. data/spec/fixtures/syncable_content/services/timers.lua +4 -0
  150. data/spec/spec_helper.rb +119 -0
  151. metadata +498 -0
data/spec/Http_spec.rb ADDED
@@ -0,0 +1,204 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/http'
3
+ require 'MrMurano/verbosing'
4
+ require 'MrMurano/Account'
5
+ require '_workspace'
6
+
7
+ class Tst
8
+ include MrMurano::Verbose
9
+ include MrMurano::Http
10
+ def initialize
11
+ @token = nil
12
+ end
13
+ end
14
+ RSpec.describe MrMurano::Http do
15
+ include_context "WORKSPACE"
16
+
17
+ before(:example) do
18
+ $cfg = MrMurano::Config.new
19
+ $cfg.load
20
+ @tst = Tst.new
21
+ end
22
+
23
+ context "gets a token" do
24
+ before(:example) do
25
+ @acc = instance_double("MrMurano::Account")
26
+ allow(MrMurano::Account).to receive(:new).and_return(@acc)
27
+ end
28
+
29
+ it "already has one" do
30
+ @tst.instance_variable_set(:@token, "ABCDEFG")
31
+ ret = @tst.token
32
+ expect(ret).to eq("ABCDEFG")
33
+ end
34
+
35
+ it "gets one" do
36
+ expect(@acc).to receive(:token).and_return("ABCDEFG")
37
+ ret = @tst.token
38
+ expect(ret).to eq("ABCDEFG")
39
+ end
40
+
41
+ it "raises when no logged in" do
42
+ expect(@acc).to receive(:token).and_return(nil)
43
+ expect {
44
+ @tst.token
45
+ }.to raise_error "Not logged in!"
46
+
47
+ end
48
+ end
49
+
50
+ context "puts curl request" do
51
+ before(:example) do
52
+ @req = Net::HTTP::Get.new URI("https://test.host/this/is/a/test")
53
+ @req.content_type = 'application/json'
54
+ @req['User-Agent'] = 'test'
55
+ end
56
+ it "puts nothing" do
57
+ $cfg['tool.curldebug'] = false
58
+ $stdout = StringIO.new
59
+ @tst.curldebug(@req)
60
+ expect($stdout.string).to eq("")
61
+ end
62
+
63
+ it "puts something" do
64
+ $cfg['tool.curldebug'] = true
65
+ $stdout = StringIO.new
66
+ @tst.curldebug(@req)
67
+ expect($stdout.string).to eq(%{curl -s -H 'User-Agent: test' -H 'Content-Type: application/json' -X GET 'https://test.host/this/is/a/test'\n})
68
+ end
69
+
70
+ it "puts something with Auth" do
71
+ $cfg['tool.curldebug'] = true
72
+ $stdout = StringIO.new
73
+ @req['Authorization'] = 'LetMeIn'
74
+ @tst.curldebug(@req)
75
+ expect($stdout.string).to eq(%{curl -s -H 'Authorization: LetMeIn' -H 'User-Agent: test' -H 'Content-Type: application/json' -X GET 'https://test.host/this/is/a/test'\n})
76
+ end
77
+
78
+ it "puts something with Body" do
79
+ $cfg['tool.curldebug'] = true
80
+ $stdout = StringIO.new
81
+ @req.body = "builder"
82
+ @tst.curldebug(@req)
83
+ expect($stdout.string).to eq(%{curl -s -H 'User-Agent: test' -H 'Content-Type: application/json' -X GET 'https://test.host/this/is/a/test' -d 'builder'\n})
84
+ end
85
+ end
86
+
87
+ context "checks if JSON" do
88
+ it "is JSON" do
89
+ ok, data = @tst.isJSON(%{{"one": "two", "three":[1,2,3,4,5,6]}})
90
+ expect(ok).to be true
91
+ expect(data).to eq({
92
+ :one=>'two',
93
+ :three=>[1,2,3,4,5,6]
94
+ })
95
+ end
96
+ it "is not JSON" do
97
+ ok, data = @tst.isJSON(%{woeiutepoxam})
98
+ expect(ok).to be false
99
+ expect(data).to eq('woeiutepoxam')
100
+ end
101
+ end
102
+
103
+ context "shows HTTP errors" do
104
+ before(:example) do
105
+ @req = Net::HTTP::Get.new URI("https://test.host/this/is/a/test")
106
+ @req.content_type = 'application/json'
107
+ @req['User-Agent'] = 'test'
108
+ @rsp = Net::HTTPGone.new('1.1', 410, 'ok')
109
+ end
110
+
111
+ it "shows debug details" do
112
+ $cfg['tool.debug'] = true
113
+ $stdout = StringIO.new
114
+ $stderr = StringIO.new
115
+
116
+ allow(@rsp).to receive(:body).and_return("ok")
117
+ expect(@tst).to receive(:error).once.with('Request Failed: 410: ok')
118
+
119
+ @tst.showHttpError(@req, @rsp)
120
+ expect($stdout.string).to eq(%{Sent GET https://test.host/this/is/a/test
121
+ > Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
122
+ > Accept: */*
123
+ > User-Agent: test
124
+ > Host: test.host
125
+ > Content-Type: application/json
126
+ Got 410 ok
127
+ }.gsub(/^\s+/,''))
128
+ expect($stderr.string).to eq('')
129
+ end
130
+
131
+ it "shows debug details; has req body" do
132
+ $cfg['tool.debug'] = true
133
+ $stdout = StringIO.new
134
+ $stderr = StringIO.new
135
+
136
+ allow(@req).to receive(:body).and_return("this is my body")
137
+ allow(@rsp).to receive(:body).and_return("ok")
138
+ expect(@tst).to receive(:error).once.with('Request Failed: 410: ok')
139
+
140
+ @tst.showHttpError(@req, @rsp)
141
+ expect($stdout.string).to eq(%{Sent GET https://test.host/this/is/a/test
142
+ > Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
143
+ > Accept: */*
144
+ > User-Agent: test
145
+ > Host: test.host
146
+ > Content-Type: application/json
147
+ >> this is my body
148
+ Got 410 ok
149
+ }.gsub(/^\s+/,''))
150
+ expect($stderr.string).to eq('')
151
+ end
152
+
153
+ it "shows debug details; json body" do
154
+ $cfg['tool.debug'] = true
155
+ $stdout = StringIO.new
156
+ $stderr = StringIO.new
157
+
158
+ allow(@rsp).to receive(:body).and_return(%{{"statusCode": 123, "message": "ok"}})
159
+ expect(@tst).to receive(:error).once.with('Request Failed: 410: [123] ok')
160
+
161
+ @tst.showHttpError(@req, @rsp)
162
+ expect($stdout.string).to eq(%{Sent GET https://test.host/this/is/a/test
163
+ > Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
164
+ > Accept: */*
165
+ > User-Agent: test
166
+ > Host: test.host
167
+ > Content-Type: application/json
168
+ Got 410 ok
169
+ }.gsub(/^\s+/,''))
170
+ expect($stderr.string).to eq('')
171
+ end
172
+
173
+ it "shows full error responses" do
174
+ $cfg['tool.fullerror'] = true
175
+ $stdout = StringIO.new
176
+ $stderr = StringIO.new
177
+
178
+ allow(@rsp).to receive(:body).and_return(%{{"statusCode": 123, "message": "ok"}})
179
+ expect(@tst).to receive(:error).once.with("Request Failed: 410: {\n \"statusCode\": 123,\n \"message\": \"ok\"\n}")
180
+
181
+ @tst.showHttpError(@req, @rsp)
182
+ expect($stdout.string).to eq('')
183
+ expect($stderr.string).to eq('')
184
+ end
185
+
186
+
187
+ it "calls showHttpError" do
188
+ $stdout = StringIO.new
189
+ $stderr = StringIO.new
190
+
191
+ idhttp = instance_double('Net::HTTP')
192
+ expect(idhttp).to receive(:request).once.and_return(@rsp)
193
+ expect(@tst).to receive(:http).once.and_return(idhttp)
194
+ expect(@rsp).to receive(:body).and_return(%{{"statusCode": 123, "message": "gone"}})
195
+
196
+ @tst.workit(@req)
197
+ expect($stdout.string).to eq('')
198
+ expect($stderr.string).to eq("\e[31mRequest Failed: 410: [123] gone\e[0m\n")
199
+
200
+ end
201
+ end
202
+
203
+ end
204
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,118 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/makePretty'
3
+
4
+ RSpec.describe MrMurano::Pretties do
5
+ before(:example) do
6
+ @options = {:pretty=>true, :localtime=>false}
7
+ def @options.method_missing(mid)
8
+ self[mid]
9
+ end
10
+ end
11
+
12
+ it "makes json pretty with color" do
13
+ data ={:type=>"debug", :timestamp=>1476386031,
14
+ :subject=>"websocket_websocket_info",
15
+ :data=>"Script Error: "}
16
+ str ="\e[35m{\e[0m\n \"type\": \"debug\",\n \"timestamp\": 1476386031,\n \"subject\": \"websocket_websocket_info\",\n \"data\": \"Script Error: \"\n\e[35m}\e[0m"
17
+ ret = MrMurano::Pretties::makeJsonPretty(data, @options)
18
+ expect(ret).to eq(str)
19
+ end
20
+ it "makes json pretty without color" do
21
+ data ={:type=>"debug", :timestamp=>1476386031,
22
+ :subject=>"websocket_websocket_info",
23
+ :data=>"Script Error: "}
24
+ str ="{\"type\":\"debug\",\"timestamp\":1476386031,\"subject\":\"websocket_websocket_info\",\"data\":\"Script Error: \"}"
25
+ @options[:pretty] = false
26
+ ret = MrMurano::Pretties::makeJsonPretty(data, @options)
27
+ expect(ret).to eq(str)
28
+ end
29
+
30
+ it "makes it pretty." do
31
+ data ={:type=>"debug", :timestamp=>1476386031,
32
+ :subject=>"websocket_websocket_info",
33
+ :data=>"Script Error: "}
34
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\nScript Error: "
35
+ ret = MrMurano::Pretties::makePretty(data, @options)
36
+ expect(ret).to eq(str)
37
+ end
38
+
39
+ it "makes it pretty; missing type" do
40
+ data ={:timestamp=>1476386031,
41
+ :subject=>"websocket_websocket_info",
42
+ :data=>"Script Error: "}
43
+ str ="\e[31m\e[48;5;231m-- \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\nScript Error: "
44
+ ret = MrMurano::Pretties::makePretty(data, @options)
45
+ expect(ret).to eq(str)
46
+ end
47
+
48
+ it "makes it pretty; localtime" do
49
+ data ={:type=>"debug", :timestamp=>1476386031,
50
+ :subject=>"websocket_websocket_info",
51
+ :data=>"Script Error: "}
52
+ ldt = Time.at(1476386031).localtime.to_datetime.iso8601(3)
53
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m#{ldt}\e[0m:\nScript Error: "
54
+ @options[:localtime] = true
55
+ ret = MrMurano::Pretties::makePretty(data, @options)
56
+ @options[:localtime] = false
57
+ expect(ret).to eq(str)
58
+ end
59
+
60
+ it "makes it pretty; missing timestamp" do
61
+ data ={:type=>"debug",
62
+ :subject=>"websocket_websocket_info",
63
+ :data=>"Script Error: "}
64
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m<no timestamp>\e[0m:\nScript Error: "
65
+ ret = MrMurano::Pretties::makePretty(data, @options)
66
+ expect(ret).to eq(str)
67
+ end
68
+
69
+ it "makes it pretty; missing subject" do
70
+ data ={:type=>"debug", :timestamp=>1476386031,
71
+ :data=>"Script Error: "}
72
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\nScript Error: "
73
+ ret = MrMurano::Pretties::makePretty(data, @options)
74
+ expect(ret).to eq(str)
75
+ end
76
+
77
+
78
+ it "makes it pretty; missing data" do
79
+ data ={:type=>"debug", :timestamp=>1476386031,
80
+ :subject=>"websocket_websocket_info"}
81
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\n\e[35m{\e[0m\n\e[35m}\e[0m"
82
+ ret = MrMurano::Pretties::makePretty(data, @options)
83
+ expect(ret).to eq(str)
84
+ end
85
+
86
+ it "makes it pretty; NAN timestamp" do
87
+ data ={:type=>"debug", :timestamp => "bob",
88
+ :subject=>"websocket_websocket_info",
89
+ :data=>"Script Error: "}
90
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34mbob\e[0m:\nScript Error: "
91
+ ret = MrMurano::Pretties::makePretty(data, @options)
92
+ expect(ret).to eq(str)
93
+ end
94
+
95
+ it "makes it pretty; hash data" do
96
+ data ={:type=>"debug", :timestamp=>1476386031,
97
+ :subject=>"websocket_websocket_info",
98
+ :data=>{
99
+ :random=>'junk'
100
+ }}
101
+ str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\n\e[35m{\e[0m\n \"random\": \"junk\"\n\e[35m}\e[0m"
102
+ ret = MrMurano::Pretties::makePretty(data, @options)
103
+ expect(ret).to eq(str)
104
+ end
105
+
106
+ it "makes it pretty; http hash data" do
107
+ data ={:type=>"debug", :timestamp=>1476386031,
108
+ :subject=>"websocket_websocket_info",
109
+ :data=>{
110
+ :request=>{:method=>'get'},
111
+ :response=>{:status=>200},
112
+ }}
113
+ str =%|\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\n---------\nrequest:\e[35m{\e[0m\n "method\": \"get\"\n\e[35m}\e[0m\n---------\nresponse:\e[35m{\e[0m\n \"status\": 200\n\e[35m}\e[0m|
114
+ ret = MrMurano::Pretties::makePretty(data, @options)
115
+ expect(ret).to eq(str)
116
+ end
117
+ end
118
+ # vim: set ai et sw=2 ts=2 :
data/spec/Mock_spec.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'MrMurano/Config'
2
+ require 'MrMurano/Mock'
3
+ require 'tempfile'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::Mock, "#mock" do
7
+ include_context "WORKSPACE"
8
+ before(:example) do
9
+ FileUtils.mkpath(@projectDir + '/routes')
10
+ $cfg = MrMurano::Config.new
11
+ $cfg.load
12
+
13
+ @mock = MrMurano::Mock.new
14
+ end
15
+
16
+ it "can create the testpoint file" do
17
+ uuid = @mock.create_testpoint()
18
+ expect(uuid.length).to be("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX".length)
19
+ path = @mock.get_testpoint_path()
20
+ testpoint = File.read(path)
21
+ expect(testpoint.include? uuid).to be(true)
22
+ end
23
+
24
+ it "can show the UUID from the testpoint file" do
25
+ uuid = @mock.create_testpoint()
26
+ retrieved_uuid = @mock.show()
27
+ expect(uuid).to eq(retrieved_uuid)
28
+ end
29
+
30
+ it "can remove the testpoint file" do
31
+ @mock.create_testpoint()
32
+ path = @mock.get_testpoint_path()
33
+ removed = @mock.remove_testpoint()
34
+ expect(removed).to be(true)
35
+ expect(File.exist?(path)).to be(false)
36
+ end
37
+
38
+ it "can remove the missing testpoint file" do
39
+ path = @mock.get_testpoint_path()
40
+ removed = @mock.remove_testpoint()
41
+ expect(removed).to be(false)
42
+ expect(File.exist?(path)).to be(false)
43
+ end
44
+
45
+ it "cannot show the UUID if there's no testpoint file" do
46
+ @mock.create_testpoint()
47
+ @mock.show()
48
+ @mock.remove_testpoint()
49
+ retrieved_uuid = @mock.show()
50
+ expect(retrieved_uuid).to be(false)
51
+ end
52
+ end
53
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,113 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Product'
3
+ require '_workspace'
4
+
5
+ RSpec.describe MrMurano::ProductBase, "#product_base" do
6
+ include_context "WORKSPACE"
7
+ before(:example) do
8
+ $cfg = MrMurano::Config.new
9
+ $cfg.load
10
+ $project = MrMurano::ProjectFile.new
11
+ $project.load
12
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
13
+ $cfg['product.id'] = 'XYZ'
14
+
15
+ @prd = MrMurano::ProductBase.new
16
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
17
+ end
18
+
19
+ it "initializes" do
20
+ uri = @prd.endPoint('/')
21
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/product/XYZ/")
22
+ end
23
+
24
+ it "can get" do
25
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
26
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
27
+ 'Content-Type'=>'application/json'}).
28
+ to_return(body: "Fooo")
29
+
30
+ ret = @prd.get('/')
31
+ expect(ret).to eq("Fooo")
32
+ end
33
+
34
+ it "returns hash when getting empty body" do
35
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
36
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
37
+ 'Content-Type'=>'application/json'}).
38
+ to_return(body: "")
39
+
40
+ ret = @prd.get('/')
41
+ expect(ret).to eq({})
42
+ end
43
+
44
+ it "auto parses JSON responses" do
45
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
46
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
47
+ 'Content-Type'=>'application/json'}).
48
+ to_return(body: %{{"first": "str", "sec":[1,2,3], "third":{"a":"b"}}})
49
+
50
+ ret = @prd.get('/')
51
+ expect(ret).to eq({:sec=>[1,2,3],:third=>{:a=>'b'},:first=>'str'})
52
+ end
53
+
54
+ it "can post nothing" do
55
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
56
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
57
+ 'Content-Type'=>'application/json'}).
58
+ to_return(body: "")
59
+ ret = @prd.post('/')
60
+ expect(ret).to eq({})
61
+ end
62
+
63
+ it "can post json" do
64
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
65
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
66
+ 'Content-Type'=>'application/json'},
67
+ body: {:this=>"is", :a=>'test'}).
68
+ to_return(body: "")
69
+ ret = @prd.post('/', {:this=>"is", :a=>'test'})
70
+ expect(ret).to eq({})
71
+ end
72
+
73
+ it "can post form data" do
74
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
75
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
76
+ 'Content-Type'=>'application/x-www-form-urlencoded'},
77
+ body: "this=is&a=test").
78
+ to_return(body: "")
79
+ ret = @prd.postf('/', {:this=>"is", :a=>'test'})
80
+ expect(ret).to eq({})
81
+ end
82
+
83
+ it "can put nothing" do
84
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
85
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
86
+ 'Content-Type'=>'application/json'}).
87
+ to_return(body: "")
88
+ ret = @prd.put('/')
89
+ expect(ret).to eq({})
90
+ end
91
+
92
+ it "can put json" do
93
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
94
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
95
+ 'Content-Type'=>'application/json'},
96
+ body: {:this=>"is", :a=>'test'}).
97
+ to_return(body: "")
98
+ ret = @prd.put('/', {:this=>"is", :a=>'test'})
99
+ expect(ret).to eq({})
100
+ end
101
+
102
+ it "can delete" do
103
+ stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/").
104
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
105
+ 'Content-Type'=>'application/json'}).
106
+ to_return(body: "")
107
+ ret = @prd.delete('/')
108
+ expect(ret).to eq({})
109
+ end
110
+
111
+ end
112
+
113
+ # vim: set ai et sw=2 ts=2 :