roku_builder 3.3.2 → 3.3.3

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.
@@ -66,6 +66,81 @@ class InspectorTest < Minitest::Test
66
66
  response.expect(:body, body)
67
67
 
68
68
 
69
+ package_info = {}
70
+ inspector = RokuBuilder::Inspector.new(**device_config)
71
+ Faraday.stub(:new, connection, faraday) do
72
+ Faraday::UploadIO.stub(:new, io) do
73
+ package_info = inspector.inspect(pkg: "pkg/path", password: password)
74
+ end
75
+ end
76
+
77
+ assert_equal "app_name", package_info[:app_name]
78
+ assert_equal "dev_id", package_info[:dev_id]
79
+ assert_equal Time.at(628232400).to_s, package_info[:creation_date]
80
+ assert_equal "dev_zip", package_info[:dev_zip]
81
+
82
+ connection.verify
83
+ faraday.verify
84
+ io.verify
85
+ response.verify
86
+ end
87
+ def test_inspector_inspect_old_interface
88
+ connection = Minitest::Mock.new
89
+ faraday = Minitest::Mock.new
90
+ io = Minitest::Mock.new
91
+ response = Minitest::Mock.new
92
+
93
+ device_config = {
94
+ ip: "111.222.333",
95
+ user: "user",
96
+ password: "password",
97
+ logger: Logger.new("/dev/null")
98
+ }
99
+ path = "/plugin_inspect"
100
+ password = "password"
101
+ payload ={
102
+ mysubmit: "Inspect",
103
+ password: password,
104
+ archive: io
105
+ }
106
+ body = " <table cellpadding=\"2\">"+
107
+ " <tbody><tr><td> App Name: </td><td> <font color=\"blue\">app_name</font> </td></tr>"+
108
+ " <tr><td> Dev ID: </td><td> <font face=\"Courier\" color=\"blue\">dev_id</font> </td></tr>"+
109
+ " <tr><td> Creation Date: </td><td> <font color=\"blue\">"+
110
+ " <script type=\"text/javascript\">"+
111
+ " var d = new Date(628232400)"+
112
+ " document.write(d.getMonth()+1)"+
113
+ " document.write(\"/\")"+
114
+ " document.write(d.getDate())"+
115
+ " document.write(\"/\");"+
116
+ " document.write(d.getFullYear())"+
117
+ " document.write(\" \")"+
118
+ " document.write(d.getHours())"+
119
+ " document.write(\":\")"+
120
+ " document.write(d.getMinutes())"+
121
+ " document.write(\":\")"+
122
+ " document.write(d.getSeconds())"+
123
+ " </script>1/17/1970 16:42:28"+
124
+ " </font> </td></tr>"+
125
+ " <tr><td> dev.zip: </td><td> <font face=\"Courier\" color=\"blue\">dev_zip</font> </td></tr>"+
126
+ " </tbody></table>"
127
+
128
+ connection.expect(:post, response) do |arg1, arg2|
129
+ assert_equal path, arg1
130
+ assert_equal payload[:mysubmit], arg2[:mysubmit]
131
+ assert_equal payload[:password], arg2[:passwd]
132
+ assert payload[:archive] === arg2[:archive]
133
+ end
134
+ faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
135
+ faraday.expect(:request, nil, [:multipart])
136
+ faraday.expect(:request, nil, [:url_encoded])
137
+ faraday.expect(:adapter, nil, [Faraday.default_adapter])
138
+ response.expect(:body, body)
139
+ response.expect(:body, body)
140
+ response.expect(:body, body)
141
+ response.expect(:body, body)
142
+
143
+
69
144
  package_info = {}
70
145
  inspector = RokuBuilder::Inspector.new(**device_config)
71
146
  Faraday.stub(:new, connection, faraday) do
@@ -22,6 +22,39 @@ class KeyerTest < Minitest::Test
22
22
  response.expect(:body, body)
23
23
 
24
24
 
25
+ package_info = {}
26
+ dev_id = nil
27
+ keyer = RokuBuilder::Keyer.new(**device_config)
28
+ Faraday.stub(:new, connection, faraday) do
29
+ dev_id = keyer.dev_id
30
+ end
31
+
32
+ assert_equal "dev_id", dev_id
33
+
34
+ connection.verify
35
+ faraday.verify
36
+ response.verify
37
+ end
38
+ def test_keyer_dev_id_old_interface
39
+ connection = Minitest::Mock.new
40
+ faraday = Minitest::Mock.new
41
+ response = Minitest::Mock.new
42
+
43
+ device_config = {
44
+ ip: "111.222.333",
45
+ user: "user",
46
+ password: "password",
47
+ logger: Logger.new("/dev/null")
48
+ }
49
+ path = "/plugin_package"
50
+ body = "<p> Your Dev ID: <font face=\"Courier\">dev_id</font> </p>"
51
+
52
+ connection.expect(:get, response, [path])
53
+ faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
54
+ faraday.expect(:adapter, nil, [Faraday.default_adapter])
55
+ response.expect(:body, body)
56
+
57
+
25
58
  package_info = {}
26
59
  dev_id = nil
27
60
  keyer = RokuBuilder::Keyer.new(**device_config)
@@ -34,4 +34,19 @@ class LinkerTest < Minitest::Test
34
34
  faraday.verify
35
35
  response.verify
36
36
  end
37
+ def test_linker_link_nothing
38
+ device_config = {
39
+ ip: "111.222.333",
40
+ user: "user",
41
+ password: "password",
42
+ logger: Logger.new("/dev/null")
43
+ }
44
+ options = ''
45
+ linker = RokuBuilder::Linker.new(**device_config)
46
+ success = nil
47
+ success = linker.link(options: options)
48
+
49
+ assert !success
50
+
51
+ end
37
52
  end
@@ -58,6 +58,64 @@ class LoaderTest < Minitest::Test
58
58
  io.verify
59
59
  response.verify
60
60
  end
61
+ def test_loader_sideload_update
62
+ connection = Minitest::Mock.new
63
+ faraday = Minitest::Mock.new
64
+ io = Minitest::Mock.new
65
+ response = Minitest::Mock.new
66
+
67
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
68
+ device_config = {
69
+ ip: "111.222.333",
70
+ user: "user",
71
+ password: "password",
72
+ logger: Logger.new("/dev/null")
73
+ }
74
+ loader_config = {
75
+ root_dir: root_dir,
76
+ update_manifest: true,
77
+ folders: ["source"],
78
+ files: ["manifest"]
79
+ }
80
+ payload = {
81
+ mysubmit: "Replace",
82
+ archive: io,
83
+ }
84
+ path = "/plugin_install"
85
+
86
+ faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
87
+ faraday.expect(:request, nil, [:multipart])
88
+ faraday.expect(:request, nil, [:url_encoded])
89
+ faraday.expect(:adapter, nil, [Faraday.default_adapter])
90
+ connection.expect(:post, response) do |arg1, arg2|
91
+ assert_equal path, arg1
92
+ assert_equal payload[:mysubmit], arg2[:mysubmit]
93
+ assert payload[:archive] === arg2[:archive]
94
+ end
95
+ response.expect(:status, 200)
96
+ response.expect(:body, "Install Success")
97
+
98
+ loader = RokuBuilder::Loader.new(**device_config)
99
+ result = nil
100
+ RokuBuilder::ManifestManager.stub(:update_build, "build_version") do
101
+ loader.stub(:build, "zip_file") do
102
+ Faraday.stub(:new, connection, faraday) do
103
+ Faraday::UploadIO.stub(:new, io) do
104
+ File.stub(:delete, nil) do
105
+ result = loader.sideload(**loader_config)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ assert_equal "build_version", result
113
+
114
+ connection.verify
115
+ faraday.verify
116
+ io.verify
117
+ response.verify
118
+ end
61
119
 
62
120
  def test_loader_build_defining_folder_and_files
63
121
  root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
@@ -79,9 +137,9 @@ class LoaderTest < Minitest::Test
79
137
  end
80
138
  Zip::File.open(outfile) do |file|
81
139
  assert file.find_entry("manifest") != nil
82
- assert file.find_entry("source/a") != nil
140
+ assert_nil file.find_entry("a")
83
141
  assert file.find_entry("source/b") != nil
84
- assert_nil file.find_entry("c")
142
+ assert file.find_entry("source/c/d") != nil
85
143
  end
86
144
  end
87
145
  def test_loader_build_all_contents
@@ -102,9 +160,9 @@ class LoaderTest < Minitest::Test
102
160
  end
103
161
  Zip::File.open(outfile) do |file|
104
162
  assert file.find_entry("manifest") != nil
105
- assert file.find_entry("source/a") != nil
163
+ assert file.find_entry("a") != nil
106
164
  assert file.find_entry("source/b") != nil
107
- assert file.find_entry("c") != nil
165
+ assert file.find_entry("source/c/d") != nil
108
166
  end
109
167
  end
110
168
 
@@ -144,7 +202,49 @@ class LoaderTest < Minitest::Test
144
202
  result = loader.unload
145
203
  end
146
204
 
147
- assert_equal true, result
205
+ assert result
206
+
207
+ connection.verify
208
+ faraday.verify
209
+ response.verify
210
+ end
211
+ def test_loader_unload_fail
212
+ connection = Minitest::Mock.new
213
+ faraday = Minitest::Mock.new
214
+ response = Minitest::Mock.new
215
+
216
+ device_config = {
217
+ ip: "111.222.333",
218
+ user: "user",
219
+ password: "password",
220
+ logger: Logger.new("/dev/null")
221
+ }
222
+ payload = {
223
+ mysubmit: "Delete",
224
+ archive: "",
225
+ }
226
+ path = "/plugin_install"
227
+
228
+ faraday.expect(:headers, {})
229
+ faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
230
+ faraday.expect(:request, nil, [:multipart])
231
+ faraday.expect(:request, nil, [:url_encoded])
232
+ faraday.expect(:adapter, nil, [Faraday.default_adapter])
233
+ connection.expect(:post, response) do |arg1, arg2|
234
+ assert_equal path, arg1
235
+ assert_equal payload[:mysubmit], arg2[:mysubmit]
236
+ assert payload[:archive] === arg2[:archive]
237
+ end
238
+ response.expect(:status, 200)
239
+ response.expect(:body, "Install Filed")
240
+
241
+ loader = RokuBuilder::Loader.new(**device_config)
242
+ result = nil
243
+ Faraday.stub(:new, connection, faraday) do
244
+ result = loader.unload
245
+ end
246
+
247
+ assert !result
148
248
 
149
249
  connection.verify
150
250
  faraday.verify
@@ -13,6 +13,18 @@ class ManifestManagerTest < Minitest::Test
13
13
  FileUtils.rm(File.join(root_dir, "manifest"))
14
14
  end
15
15
 
16
+ def test_manifest_manager_update_missing_build_number
17
+ logger = Logger.new('/dev/null')
18
+ root_dir = File.join(File.dirname(__FILE__), "test_files", "manifest_manager_test")
19
+ FileUtils.cp(File.join(root_dir, "manifest_template_2"), File.join(root_dir, "manifest"))
20
+ build_version = nil
21
+ Time.stub(:now, Time.new(2001, 02, 01)) do
22
+ build_version = RokuBuilder::ManifestManager.update_build(root_dir: root_dir, logger: logger)
23
+ end
24
+ assert_equal "020101.1", build_version
25
+ FileUtils.rm(File.join(root_dir, "manifest"))
26
+ end
27
+
16
28
  def test_manifest_manager_build_version
17
29
  logger = Logger.new('/dev/null')
18
30
  root_dir = File.join(File.dirname(__FILE__), "test_files", "manifest_manager_test")
@@ -31,4 +31,73 @@ class MonitorTest < Minitest::Test
31
31
 
32
32
  connection.verify
33
33
  end
34
+
35
+ def test_monitor_monit_input
36
+ connection = Minitest::Mock.new
37
+ device_config = {
38
+ ip: "111.222.333",
39
+ user: "user",
40
+ password: "password",
41
+ logger: Logger.new("/dev/null")
42
+ }
43
+ monitor_config = {
44
+ 'Host' => device_config[:ip],
45
+ 'Post' => 8085
46
+ }
47
+ monitor = RokuBuilder::Monitor.new(**device_config)
48
+
49
+ connection.expect(:waitfor, nil) do |config|
50
+ assert_equal /./, config['Match']
51
+ assert_equal false, config['Timeout']
52
+ end
53
+ connection.expect(:puts, nil, ["text"])
54
+
55
+ def monitor.gets
56
+ @count = 0 unless @count
57
+ sleep(0.1)
58
+ case @count
59
+ when 0
60
+ @count += 1
61
+ "text"
62
+ else
63
+ "q"
64
+ end
65
+ end
66
+
67
+ Net::Telnet.stub(:new, connection) do
68
+ monitor.monitor(type: :main)
69
+ end
70
+
71
+ connection.verify
72
+ end
73
+
74
+ def test_monitor_manage_text
75
+ mock = Minitest::Mock.new
76
+ device_config = {
77
+ ip: "111.222.333",
78
+ user: "user",
79
+ password: "password",
80
+ logger: Logger.new("/dev/null")
81
+ }
82
+ monitor = RokuBuilder::Monitor.new(**device_config)
83
+ monitor.instance_variable_set(:@mock, mock)
84
+
85
+ def monitor.puts(input)
86
+ @mock.puts(input)
87
+ end
88
+ def monitor.print(input)
89
+ @mock.print(input)
90
+ end
91
+
92
+ mock.expect(:puts, nil, ["midline split\n"])
93
+ mock.expect(:print, nil, ["BrightScript Debugger> "])
94
+
95
+ all_text = "midline "
96
+ txt = "split\nBrightScript Debugger> "
97
+
98
+ result = monitor.send(:manage_text, {all_text: all_text, txt: txt})
99
+
100
+ assert_equal "", result
101
+
102
+ end
34
103
  end
@@ -21,12 +21,17 @@ class NavigatorTest < Minitest::Test
21
21
  }
22
22
  end
23
23
 
24
+ def test_navigator_nav_fail
25
+ path = ""
26
+ navigator_test(path: path, input: :bad, type: :nav, success: false)
27
+ end
28
+
24
29
  def test_navigator_type
25
30
  path = "keypress/LIT_"
26
31
  navigator_test(path: path, input: "Type", type: :text)
27
32
  end
28
33
 
29
- def navigator_test(path:, input:, type:)
34
+ def navigator_test(path:, input:, type:, success: true)
30
35
  connection = Minitest::Mock.new
31
36
  faraday = Minitest::Mock.new
32
37
  io = Minitest::Mock.new
@@ -38,35 +43,90 @@ class NavigatorTest < Minitest::Test
38
43
  password: "password",
39
44
  logger: Logger.new("/dev/null")
40
45
  }
41
- if type == :nav
42
- connection.expect(:post, response, [path])
43
- response.expect(:success?, true)
44
- elsif type == :text
45
- input.split(//).each do |c|
46
- path = "/keypress/LIT_#{CGI::escape(c)}"
46
+ if success
47
+ if type == :nav
47
48
  connection.expect(:post, response, [path])
48
49
  response.expect(:success?, true)
50
+ elsif type == :text
51
+ input.split(//).each do |c|
52
+ path = "/keypress/LIT_#{CGI::escape(c)}"
53
+ connection.expect(:post, response, [path])
54
+ response.expect(:success?, true)
55
+ end
49
56
  end
50
- end
51
- faraday.expect(:request, nil, [:multipart])
52
- faraday.expect(:request, nil, [:url_encoded])
53
- faraday.expect(:adapter, nil, [Faraday.default_adapter])
57
+ faraday.expect(:request, nil, [:multipart])
58
+ faraday.expect(:request, nil, [:url_encoded])
59
+ faraday.expect(:adapter, nil, [Faraday.default_adapter])
60
+ end if
54
61
 
55
62
  navigator = RokuBuilder::Navigator.new(**device_config)
56
- success = nil
63
+ result = nil
57
64
  Faraday.stub(:new, connection, faraday) do
58
65
  if type == :nav
59
- success = navigator.nav(command: input)
66
+ result = navigator.nav(command: input)
60
67
  elsif type == :text
61
- success = navigator.type(text: input)
68
+ result = navigator.type(text: input)
62
69
  end
63
70
  end
64
71
 
65
- assert success
72
+ assert_equal success, result
66
73
 
67
74
  connection.verify
68
75
  faraday.verify
69
76
  io.verify
70
77
  response.verify
71
78
  end
79
+
80
+ def test_navigator_screen
81
+ logger = Minitest::Mock.new
82
+ device_config = {
83
+ ip: "111.222.333",
84
+ user: "user",
85
+ password: "password",
86
+ logger: logger
87
+ }
88
+ navigator = RokuBuilder::Navigator.new(**device_config)
89
+
90
+ logger.expect(:unknown, nil, ["Home x 5, Fwd x 3, Rev x 2,"])
91
+ logger.expect(:unknown, nil, ["Home x 5, Up, Rev x 2, Fwd x 2,"])
92
+
93
+ navigator.screen(type: :secret)
94
+ navigator.screen(type: :reboot)
95
+
96
+ logger.verify
97
+ end
98
+
99
+ def test_navigator_screen_fail
100
+ logger = Minitest::Mock.new
101
+ device_config = {
102
+ ip: "111.222.333",
103
+ user: "user",
104
+ password: "password",
105
+ logger: logger
106
+ }
107
+ navigator = RokuBuilder::Navigator.new(**device_config)
108
+
109
+ assert !navigator.screen(type: :bad)
110
+
111
+ logger.verify
112
+ end
113
+
114
+ def test_navigator_screens
115
+ logger = Minitest::Mock.new
116
+ device_config = {
117
+ ip: "111.222.333",
118
+ user: "user",
119
+ password: "password",
120
+ logger: logger
121
+ }
122
+ navigator = RokuBuilder::Navigator.new(**device_config)
123
+
124
+ navigator.instance_variable_get("@screens").each_key do |key|
125
+ logger.expect(:unknown, nil, [key])
126
+ end
127
+
128
+ navigator.screens
129
+
130
+ logger.verify
131
+ end
72
132
  end