MuranoCLI 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,162 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Config'
3
+ require 'MrMurano/Product'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::ProductContent, "#product_content" do
7
+ include_context "WORKSPACE"
8
+ before(:example) do
9
+ $cfg = MrMurano::Config.new
10
+ $cfg.load
11
+ $project = MrMurano::ProjectFile.new
12
+ $project.load
13
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
+ $cfg['product.id'] = 'XYZ'
15
+
16
+ @prd = MrMurano::ProductContent.new
17
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
18
+
19
+ @urlroot = "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/provision/manage/content/XYZ"
20
+ end
21
+
22
+ it "lists nothing" do
23
+ stub_request(:get, @urlroot + "/").
24
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
25
+ 'Content-Type'=>'application/json'}).
26
+ to_return(body: "")
27
+
28
+ ret = @prd.list
29
+ expect(ret).to eq([])
30
+ end
31
+
32
+ it "lists something" do
33
+ stub_request(:get, @urlroot + "/").
34
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
35
+ 'Content-Type'=>'application/json'}).
36
+ to_return(body: "one\ntwo\nthree\n")
37
+
38
+ ret = @prd.list
39
+ expect(ret).to eq(['one','two','three'])
40
+ end
41
+
42
+ it "lists something for identifier" do
43
+ stub_request(:get, @urlroot + "/?sn=12").
44
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
45
+ 'Content-Type'=>'application/json'}).
46
+ to_return(body: "one\ntwo\nthree\n")
47
+
48
+ ret = @prd.list_for('12')
49
+ expect(ret).to eq(['one','two','three'])
50
+ end
51
+
52
+ it "creates an item" do
53
+ stub_request(:post, @urlroot + "/").
54
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
55
+ 'Content-Type'=>'application/x-www-form-urlencoded'}).
56
+ with(body: {'id'=>'testFor', 'meta'=> 'some meta'}).
57
+ to_return(status: 205)
58
+
59
+ ret = @prd.create("testFor", "some meta")
60
+ expect(ret).to eq({})
61
+ end
62
+
63
+ it "removes an item" do
64
+ stub_request(:post, @urlroot + "/").
65
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
66
+ 'Content-Type'=>'application/x-www-form-urlencoded'}).
67
+ with(body: {'id'=>'testFor', 'delete'=>'true'}).
68
+ to_return(status: 205)
69
+
70
+ ret = @prd.remove("testFor")
71
+ expect(ret).to eq({})
72
+ end
73
+
74
+ it "gets info for content" do
75
+ stub_request(:get, @urlroot + "/testFor").
76
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
77
+ 'Content-Type'=>'application/json'}).
78
+ to_return(body: "text/plain,42,123456789,test meta,false")
79
+
80
+ ret = @prd.info("testFor")
81
+ expect(ret).to eq([['text/plain','42','123456789','test meta','false']])
82
+ end
83
+
84
+ it "gets info for missing content" do
85
+ stub_request(:get, @urlroot + "/testFor").
86
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
87
+ 'Content-Type'=>'application/json'}).
88
+ to_return(status: 404, body: "")
89
+
90
+ ret = @prd.info("testFor")
91
+ expect(ret).to be_nil
92
+ end
93
+
94
+ it "removes content" do
95
+ stub_request(:delete, @urlroot + "/testFor").
96
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
97
+ 'Content-Type'=>'application/json'}).
98
+ to_return(status: 205)
99
+
100
+ ret = @prd.remove_content("testFor")
101
+ expect(ret).to eq({})
102
+ end
103
+
104
+ it "uploads content data" do
105
+ pth = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
106
+ size = FileTest.size(pth.to_path)
107
+ stub_request(:post, @urlroot + "/testFor").
108
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
109
+ 'Content-Type'=>/text\/(x-)?yaml/,
110
+ 'Content-Length' => size
111
+ }).
112
+ to_return(status: 205)
113
+
114
+ ret = @prd.upload('testFor', pth.to_path)
115
+ expect(ret).to eq({})
116
+ end
117
+
118
+ context "downloads content" do
119
+ it "to block" do
120
+ stub_request(:get, @urlroot + "/testFor?download=true").
121
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
122
+ 'Content-Type'=>'application/json'}).
123
+ to_return(body: "short and sweet")
124
+
125
+ data = ""
126
+ @prd.download('testFor') {|chunk| data << chunk}
127
+ expect(data).to eq("short and sweet")
128
+ end
129
+
130
+ it "to stdout" do
131
+ stub_request(:get, @urlroot + "/testFor?download=true").
132
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
133
+ 'Content-Type'=>'application/json'}).
134
+ to_return(body: "short and sweet")
135
+
136
+ begin
137
+ old_stdout = $stdout
138
+ $stdout = StringIO.new('','w')
139
+ @prd.download('testFor')
140
+ expect($stdout.string).to eq("short and sweet")
141
+ ensure
142
+ $stdout = old_stdout
143
+ end
144
+ end
145
+
146
+ it "but error" do
147
+ stub_request(:get, @urlroot + "/testFor?download=true").
148
+ with(headers: {'Authorization'=>'token TTTTTTTTTT',
149
+ 'Content-Type'=>'application/json'}).
150
+ to_return(status:404, body: "{}")
151
+
152
+ data = ""
153
+ expect(@prd).to receive(:error).once
154
+ @prd.download('testFor') {|chunk| data << chunk}
155
+ expect(data).to eq("")
156
+
157
+ end
158
+ end
159
+
160
+ end
161
+
162
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,329 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Config'
3
+ require 'MrMurano/Product-Resources'
4
+ require '_workspace'
5
+
6
+ RSpec.describe MrMurano::ProductResources do
7
+ include_context "WORKSPACE"
8
+ before(:example) do
9
+ $cfg = MrMurano::Config.new
10
+ $cfg.load
11
+ $project = MrMurano::ProjectFile.new
12
+ $project.load
13
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
+ $cfg['product.id'] = 'XYZ'
15
+ $cfg['product.spec'] = 'XYZ.yaml'
16
+
17
+ @prd = MrMurano::ProductResources.new
18
+ allow(@prd).to receive(:token).and_return("TTTTTTTTTT")
19
+ allow(@prd).to receive(:model_rid).and_return("LLLLLLLLLL")
20
+ end
21
+
22
+ it "initializes" do
23
+ uri = @prd.endPoint('')
24
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process")
25
+ end
26
+
27
+ context "queries" do
28
+ it "gets info" do
29
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
30
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
31
+ :calls=>[{:id=>1,
32
+ :procedure=>"info",
33
+ :arguments=>["LLLLLLLLLL", {}]} ]}).
34
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:comments=>[]}}])
35
+
36
+ ret = @prd.info
37
+ expect(ret).to eq({:comments=>[]})
38
+ end
39
+
40
+ it "gets listing" do
41
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
42
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
43
+ :calls=>[{:id=>1,
44
+ :procedure=>"info",
45
+ :arguments=>["LLLLLLLLLL", {}]} ]}).
46
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:aliases=>{:abcdefg=>["bob"]}}}])
47
+
48
+ ret = @prd.list
49
+ expect(ret).to eq([{:alias=>"bob", :rid=>:abcdefg}])
50
+ end
51
+
52
+ it "gets item" do
53
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
54
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
55
+ :calls=>[{:id=>1,
56
+ :procedure=>"info",
57
+ :arguments=>["FFFFFFFFFF", {}]} ]}).
58
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:comments=>[]}}])
59
+
60
+ ret = @prd.fetch("FFFFFFFFFF")
61
+ expect(ret).to eq({:comments=>[]})
62
+ end
63
+ end
64
+
65
+ context "Modifying" do
66
+ it "Drops RID" do
67
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
68
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
69
+ :calls=>[{:id=>1,
70
+ :procedure=>"drop",
71
+ :arguments=>["abcdefg"]} ]}).
72
+ to_return(body: [{:id=>1, :status=>"ok"}])
73
+
74
+ ret = @prd.remove("abcdefg")
75
+ expect(ret).to be_nil
76
+ end
77
+
78
+ it "Creates" do
79
+ frid = "ffffffffffffffffffffffffffffffffffffffff"
80
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
81
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
82
+ :calls=>[{:id=>1,
83
+ :procedure=>"create",
84
+ :arguments=>["dataport",{
85
+ :format=>"string",
86
+ :name=>"bob",
87
+ :retention=>{
88
+ :count=>1,
89
+ :duration=>"infinity"
90
+ }
91
+ }]} ]}).
92
+ to_return(body: [{:id=>1, :status=>"ok", :result=>frid}])
93
+
94
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
95
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
96
+ :calls=>[{:id=>1,
97
+ :procedure=>"map",
98
+ :arguments=>["alias", frid, "bob"]} ]}).
99
+ to_return(body: [{:id=>1, :status=>"ok"}])
100
+
101
+ ret = @prd.create("bob")
102
+ expect(ret).to be_nil
103
+ end
104
+ end
105
+
106
+ context "uploads" do
107
+ it "replacing" do
108
+ frid = "ffffffffffffffffffffffffffffffffffffffff"
109
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
110
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
111
+ :calls=>[{:id=>1,
112
+ :procedure=>"drop",
113
+ :arguments=>[frid]} ]}).
114
+ to_return(body: [{:id=>1, :status=>"ok"}])
115
+
116
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
117
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
118
+ :calls=>[{:id=>1,
119
+ :procedure=>"create",
120
+ :arguments=>["dataport",{
121
+ :format=>"string",
122
+ :name=>"bob",
123
+ :retention=>{
124
+ :count=>1,
125
+ :duration=>"infinity"
126
+ }
127
+ }]} ]}).
128
+ to_return(body: [{:id=>1, :status=>"ok", :result=>frid}])
129
+
130
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
131
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
132
+ :calls=>[{:id=>1,
133
+ :procedure=>"map",
134
+ :arguments=>["alias", frid, "bob"]} ]}).
135
+ to_return(body: [{:id=>1, :status=>"ok"}])
136
+
137
+ @prd.upload(nil, {:alias=>"bob", :format=>"string", :rid=>frid}, true)
138
+ end
139
+
140
+ it "creating" do
141
+ frid = "ffffffffffffffffffffffffffffffffffffffff"
142
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
143
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
144
+ :calls=>[{:id=>1,
145
+ :procedure=>"create",
146
+ :arguments=>["dataport",{
147
+ :format=>"string",
148
+ :name=>"bob",
149
+ :retention=>{
150
+ :count=>1,
151
+ :duration=>"infinity"
152
+ }
153
+ }]} ]}).
154
+ to_return(body: [{:id=>1, :status=>"ok", :result=>frid}])
155
+
156
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
157
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
158
+ :calls=>[{:id=>1,
159
+ :procedure=>"map",
160
+ :arguments=>["alias", frid, "bob"]} ]}).
161
+ to_return(body: [{:id=>1, :status=>"ok"}])
162
+
163
+ @prd.upload(nil, {:alias=>"bob", :format=>"string"}, false)
164
+ end
165
+ end
166
+
167
+ context "compares" do
168
+ before(:example) do
169
+ @iA = {:alias=>"data",
170
+ :format=>"string",
171
+ }
172
+ @iB = {:alias=>"data",
173
+ :format=>"string",
174
+ }
175
+ end
176
+ it "same" do
177
+ ret = @prd.docmp(@iA, @iB)
178
+ expect(ret).to eq(false)
179
+ end
180
+
181
+ it "different alias" do
182
+ iA = @iA.merge({:alias=>"bob"})
183
+ ret = @prd.docmp(iA, @iB)
184
+ expect(ret).to eq(true)
185
+ end
186
+
187
+ it "different format" do
188
+ iA = @iA.merge({:format=>"integer"})
189
+ ret = @prd.docmp(iA, @iB)
190
+ expect(ret).to eq(true)
191
+ end
192
+ end
193
+
194
+
195
+ context "Lookup functions" do
196
+ it "gets local name" do
197
+ ret = @prd.tolocalname({ :method=>'get', :path=>'one/two/three' }, nil)
198
+ expect(ret).to eq('')
199
+ end
200
+
201
+ it "gets synckey" do
202
+ ret = @prd.synckey({ :alias=>'get' })
203
+ expect(ret).to eq("get")
204
+ end
205
+
206
+ it "tolocalpath is into" do
207
+ ret = @prd.tolocalpath('a/path/', {:id=>'cors'})
208
+ expect(ret).to eq('a/path/')
209
+ end
210
+ end
211
+
212
+ context "local resoruces" do
213
+ before(:example) do
214
+ # pull over test file.
215
+ FileUtils.mkpath(File.dirname($cfg['location.specs']))
216
+ lb = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
217
+ @spec_path = $cfg['location.specs']
218
+ FileUtils.copy(lb.to_path, @spec_path)
219
+ end
220
+
221
+ context "gets local items" do
222
+ it "is there" do
223
+ ret = @prd.localitems(@spec_path)
224
+ expect(ret).to eq([
225
+ {:alias=>"state", :format=>"integer", :initial=>0},
226
+ {:alias=>"temperature", :format=>"float", :initial=>0},
227
+ {:alias=>"uptime", :format=>"integer", :initial=>0},
228
+ {:alias=>"humidity", :format=>"float", :initial=>0}
229
+ ])
230
+ end
231
+
232
+ it "is missing" do
233
+ expect(@prd).to receive(:warning).once.with("Skipping missing specs/resources.yaml-h")
234
+ ret = @prd.localitems(@spec_path + '-h')
235
+ expect(ret).to eq([])
236
+ end
237
+
238
+ it "isn't a file" do
239
+ expect(@prd).to receive(:warning).once.with("Cannot read from specs/resources.yaml-h")
240
+ FileUtils.mkpath(@spec_path + '-h')
241
+ ret = @prd.localitems(@spec_path + '-h')
242
+ expect(ret).to eq([])
243
+ end
244
+
245
+ it "has wrong format" do
246
+ File.open(@spec_path + '-h', 'w') do |io|
247
+ io << ['a','b','c'].to_yaml
248
+ end
249
+ expect(@prd).to receive(:warning).once.with("Unexpected data in specs/resources.yaml-h")
250
+ ret = @prd.localitems(@spec_path + '-h')
251
+ expect(ret).to eq([])
252
+ end
253
+ end
254
+ end
255
+
256
+ context "downloads" do
257
+ before(:example) do
258
+ FileUtils.mkpath($cfg['location.specs'])
259
+ @lb = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
260
+ @spec_path = Pathname.new(File.join($cfg['location.specs'], $cfg['product.spec']))
261
+ end
262
+
263
+ it "when nothing is there" do
264
+ frid = "FFFFFFFFFF"
265
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
266
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
267
+ :calls=>[{:id=>1,
268
+ :procedure=>"info",
269
+ :arguments=>[frid, {}]} ]}).
270
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:description=>{:format=>'integer'}}}])
271
+
272
+ @prd.download(@spec_path, {:rid=>frid, :alias=>'state'})
273
+
274
+ data = nil
275
+ @spec_path.open{|io| data = YAML.load(io)}
276
+ expect(data).to eq({"resources"=>[{"alias"=>"state", "format"=>"integer"}]})
277
+ end
278
+
279
+ it "merging into existing file" do
280
+ FileUtils.copy(@lb.to_path, @spec_path)
281
+ frid = "FFFFFFFFFF"
282
+ stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/onep:v1/rpc/process").
283
+ with(body: {:auth=>{:client_id=>"LLLLLLLLLL"},
284
+ :calls=>[{:id=>1,
285
+ :procedure=>"info",
286
+ :arguments=>[frid, {}]} ]}).
287
+ to_return(body: [{:id=>1, :status=>"ok", :result=>{:description=>{:format=>'integer'}}}])
288
+
289
+ @prd.download(@spec_path, {:rid=>frid, :alias=>'state'})
290
+ #FileUtils.copy_stream(@spec_path, $stdout)
291
+ #expect(FileUtils.cmp(@spec_path.to_path, @lb.to_path)).to be true
292
+
293
+ data = nil
294
+ @spec_path.open{|io| data = YAML.load(io)}
295
+ expect(data).to eq({"resources"=>[
296
+ {"alias"=>"temperature", "format"=>"float", "initial"=>0},
297
+ {"alias"=>"uptime", "format"=>"integer", "initial"=>0},
298
+ {"alias"=>"humidity", "format"=>"float", "initial"=>0},
299
+ {"alias"=>"state", "format"=>"integer"}
300
+ ]})
301
+ end
302
+
303
+ end
304
+
305
+ context "removes local items" do
306
+ before(:example) do
307
+ # pull over test file.
308
+ FileUtils.mkpath($cfg['location.specs'])
309
+ @lb = (@testdir + 'spec/fixtures/product_spec_files/lightbulb.yaml').realpath
310
+ @spec_path = File.join($cfg['location.specs'], $cfg['product.spec'])
311
+ FileUtils.copy(@lb.to_path, @spec_path)
312
+ @spec_path = Pathname.new(@spec_path)
313
+ end
314
+
315
+ it "it exists and has item" do
316
+ @prd.removelocal(@spec_path, {:alias=>"state"})
317
+ lbns = (@testdir + 'spec/fixtures/product_spec_files/lightbulb-no-state.yaml').realpath
318
+ expect(lbns.read).to eq(@spec_path.read)
319
+ end
320
+
321
+ it "it exists and does not have item" do
322
+ @prd.removelocal(@spec_path, {:alias=>"ThisAliasDoesNotExistInHere"})
323
+ # nothing changed
324
+ expect(@lb.read).to eq(@spec_path.read)
325
+ end
326
+ end
327
+ end
328
+
329
+ # vim: set ai et sw=2 ts=2 :