roku_builder 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +101 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +282 -0
- data/bin/roku +152 -0
- data/config.json.example +28 -0
- data/lib/roku_builder.rb +32 -0
- data/lib/roku_builder/config_manager.rb +157 -0
- data/lib/roku_builder/controller.rb +582 -0
- data/lib/roku_builder/inspector.rb +90 -0
- data/lib/roku_builder/keyer.rb +52 -0
- data/lib/roku_builder/linker.rb +46 -0
- data/lib/roku_builder/loader.rb +197 -0
- data/lib/roku_builder/manifest_manager.rb +63 -0
- data/lib/roku_builder/monitor.rb +62 -0
- data/lib/roku_builder/navigator.rb +107 -0
- data/lib/roku_builder/packager.rb +47 -0
- data/lib/roku_builder/tester.rb +32 -0
- data/lib/roku_builder/util.rb +31 -0
- data/lib/roku_builder/version.rb +4 -0
- data/rakefile +8 -0
- data/roku_builder.gemspec +36 -0
- data/tests/roku_builder/config_manager_test.rb +400 -0
- data/tests/roku_builder/controller_test.rb +250 -0
- data/tests/roku_builder/inspector_test.rb +153 -0
- data/tests/roku_builder/keyer_test.rb +88 -0
- data/tests/roku_builder/linker_test.rb +37 -0
- data/tests/roku_builder/loader_test.rb +153 -0
- data/tests/roku_builder/manifest_manager_test.rb +25 -0
- data/tests/roku_builder/monitor_test.rb +34 -0
- data/tests/roku_builder/navigator_test.rb +72 -0
- data/tests/roku_builder/packager_test.rb +125 -0
- data/tests/roku_builder/test_files/controller_test/load_config_test.json +28 -0
- data/tests/roku_builder/test_files/controller_test/valid_config.json +28 -0
- data/tests/roku_builder/test_files/loader_test/c +0 -0
- data/tests/roku_builder/test_files/loader_test/manifest +0 -0
- data/tests/roku_builder/test_files/loader_test/source/a +0 -0
- data/tests/roku_builder/test_files/loader_test/source/b +0 -0
- data/tests/roku_builder/test_files/manifest_manager_test/manifest_template +2 -0
- data/tests/roku_builder/test_helper.rb +6 -0
- data/tests/roku_builder/tester_test.rb +33 -0
- data/tests/roku_builder/util_test.rb +23 -0
- metadata +286 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
|
3
|
+
class LinkerTest < Minitest::Test
|
4
|
+
def test_linker_link
|
5
|
+
connection = Minitest::Mock.new
|
6
|
+
faraday = Minitest::Mock.new
|
7
|
+
response = Minitest::Mock.new
|
8
|
+
|
9
|
+
device_config = {
|
10
|
+
ip: "111.222.333",
|
11
|
+
user: "user",
|
12
|
+
password: "password",
|
13
|
+
logger: Logger.new("/dev/null")
|
14
|
+
}
|
15
|
+
path = "/launch/dev?a=A&b=B:C&d=a%5Cb"
|
16
|
+
options = 'a:A, b:B:C, d:a\b'
|
17
|
+
|
18
|
+
connection.expect(:post, response, [path])
|
19
|
+
faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
|
20
|
+
faraday.expect(:request, nil, [:multipart])
|
21
|
+
faraday.expect(:request, nil, [:url_encoded])
|
22
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
23
|
+
response.expect(:success?, true)
|
24
|
+
|
25
|
+
linker = RokuBuilder::Linker.new(**device_config)
|
26
|
+
success = nil
|
27
|
+
Faraday.stub(:new, connection, faraday) do
|
28
|
+
success = linker.link(options: options)
|
29
|
+
end
|
30
|
+
|
31
|
+
assert success
|
32
|
+
|
33
|
+
connection.verify
|
34
|
+
faraday.verify
|
35
|
+
response.verify
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
|
3
|
+
class LoaderTest < Minitest::Test
|
4
|
+
def test_loader_sideload
|
5
|
+
connection = Minitest::Mock.new
|
6
|
+
faraday = Minitest::Mock.new
|
7
|
+
io = Minitest::Mock.new
|
8
|
+
response = Minitest::Mock.new
|
9
|
+
|
10
|
+
root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
|
11
|
+
device_config = {
|
12
|
+
ip: "111.222.333",
|
13
|
+
user: "user",
|
14
|
+
password: "password",
|
15
|
+
logger: Logger.new("/dev/null")
|
16
|
+
}
|
17
|
+
loader_config = {
|
18
|
+
root_dir: root_dir,
|
19
|
+
folders: ["source"],
|
20
|
+
files: ["manifest"]
|
21
|
+
}
|
22
|
+
payload = {
|
23
|
+
mysubmit: "Replace",
|
24
|
+
archive: io,
|
25
|
+
}
|
26
|
+
path = "/plugin_install"
|
27
|
+
|
28
|
+
faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
|
29
|
+
faraday.expect(:request, nil, [:multipart])
|
30
|
+
faraday.expect(:request, nil, [:url_encoded])
|
31
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
32
|
+
connection.expect(:post, response) do |arg1, arg2|
|
33
|
+
assert_equal path, arg1
|
34
|
+
assert_equal payload[:mysubmit], arg2[:mysubmit]
|
35
|
+
assert payload[:archive] === arg2[:archive]
|
36
|
+
end
|
37
|
+
response.expect(:status, 200)
|
38
|
+
response.expect(:body, "Install Success")
|
39
|
+
|
40
|
+
loader = RokuBuilder::Loader.new(**device_config)
|
41
|
+
result = nil
|
42
|
+
RokuBuilder::ManifestManager.stub(:build_version, "build_version") do
|
43
|
+
loader.stub(:build, "zip_file") do
|
44
|
+
Faraday.stub(:new, connection, faraday) do
|
45
|
+
Faraday::UploadIO.stub(:new, io) do
|
46
|
+
File.stub(:delete, nil) do
|
47
|
+
result = loader.sideload(**loader_config)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_equal "build_version", result
|
55
|
+
|
56
|
+
connection.verify
|
57
|
+
faraday.verify
|
58
|
+
io.verify
|
59
|
+
response.verify
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_loader_build_defining_folder_and_files
|
63
|
+
root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
|
64
|
+
device_config = {
|
65
|
+
ip: "111.222.333",
|
66
|
+
user: "user",
|
67
|
+
password: "password",
|
68
|
+
logger: Logger.new("/dev/null")
|
69
|
+
}
|
70
|
+
build_config = {
|
71
|
+
root_dir: root_dir,
|
72
|
+
folders: ["source"],
|
73
|
+
files: ["manifest"]
|
74
|
+
}
|
75
|
+
loader = RokuBuilder::Loader.new(**device_config)
|
76
|
+
outfile = nil
|
77
|
+
RokuBuilder::ManifestManager.stub(:build_version, "build_version") do
|
78
|
+
outfile = loader.build(**build_config)
|
79
|
+
end
|
80
|
+
Zip::File.open(outfile) do |file|
|
81
|
+
assert file.find_entry("manifest") != nil
|
82
|
+
assert file.find_entry("source/a") != nil
|
83
|
+
assert file.find_entry("source/b") != nil
|
84
|
+
assert_nil file.find_entry("c")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
def test_loader_build_all_contents
|
88
|
+
root_dir = File.join(File.dirname(__FILE__), "test_files", "loader_test")
|
89
|
+
device_config = {
|
90
|
+
ip: "111.222.333",
|
91
|
+
user: "user",
|
92
|
+
password: "password",
|
93
|
+
logger: Logger.new("/dev/null")
|
94
|
+
}
|
95
|
+
build_config = {
|
96
|
+
root_dir: root_dir,
|
97
|
+
}
|
98
|
+
loader = RokuBuilder::Loader.new(**device_config)
|
99
|
+
outfile = nil
|
100
|
+
RokuBuilder::ManifestManager.stub(:build_version, "build_version") do
|
101
|
+
outfile = loader.build(**build_config)
|
102
|
+
end
|
103
|
+
Zip::File.open(outfile) do |file|
|
104
|
+
assert file.find_entry("manifest") != nil
|
105
|
+
assert file.find_entry("source/a") != nil
|
106
|
+
assert file.find_entry("source/b") != nil
|
107
|
+
assert file.find_entry("c") != nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_loader_unload
|
112
|
+
connection = Minitest::Mock.new
|
113
|
+
faraday = Minitest::Mock.new
|
114
|
+
response = Minitest::Mock.new
|
115
|
+
|
116
|
+
device_config = {
|
117
|
+
ip: "111.222.333",
|
118
|
+
user: "user",
|
119
|
+
password: "password",
|
120
|
+
logger: Logger.new("/dev/null")
|
121
|
+
}
|
122
|
+
payload = {
|
123
|
+
mysubmit: "Delete",
|
124
|
+
archive: "",
|
125
|
+
}
|
126
|
+
path = "/plugin_install"
|
127
|
+
|
128
|
+
faraday.expect(:headers, {})
|
129
|
+
faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
|
130
|
+
faraday.expect(:request, nil, [:multipart])
|
131
|
+
faraday.expect(:request, nil, [:url_encoded])
|
132
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
133
|
+
connection.expect(:post, response) do |arg1, arg2|
|
134
|
+
assert_equal path, arg1
|
135
|
+
assert_equal payload[:mysubmit], arg2[:mysubmit]
|
136
|
+
assert payload[:archive] === arg2[:archive]
|
137
|
+
end
|
138
|
+
response.expect(:status, 200)
|
139
|
+
response.expect(:body, "Install Success")
|
140
|
+
|
141
|
+
loader = RokuBuilder::Loader.new(**device_config)
|
142
|
+
result = nil
|
143
|
+
Faraday.stub(:new, connection, faraday) do
|
144
|
+
result = loader.unload
|
145
|
+
end
|
146
|
+
|
147
|
+
assert_equal true, result
|
148
|
+
|
149
|
+
connection.verify
|
150
|
+
faraday.verify
|
151
|
+
response.verify
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
|
3
|
+
class ManifestManagerTest < Minitest::Test
|
4
|
+
def test_manifest_manager_update
|
5
|
+
logger = Logger.new('/dev/null')
|
6
|
+
root_dir = File.join(File.dirname(__FILE__), "test_files", "manifest_manager_test")
|
7
|
+
FileUtils.cp(File.join(root_dir, "manifest_template"), File.join(root_dir, "manifest"))
|
8
|
+
build_version = nil
|
9
|
+
Time.stub(:now, Time.new(2001, 02, 01)) do
|
10
|
+
build_version = RokuBuilder::ManifestManager.update_build(root_dir: root_dir, logger: logger)
|
11
|
+
end
|
12
|
+
assert_equal "020101.2", build_version
|
13
|
+
FileUtils.rm(File.join(root_dir, "manifest"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_manifest_manager_build_version
|
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"), File.join(root_dir, "manifest"))
|
20
|
+
build_version = nil
|
21
|
+
build_version = RokuBuilder::ManifestManager.build_version(root_dir: root_dir, logger: logger)
|
22
|
+
assert_equal "010101.1", build_version
|
23
|
+
FileUtils.rm(File.join(root_dir, "manifest"))
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
|
3
|
+
class MonitorTest < Minitest::Test
|
4
|
+
def test_monitor_monit
|
5
|
+
connection = Minitest::Mock.new
|
6
|
+
device_config = {
|
7
|
+
ip: "111.222.333",
|
8
|
+
user: "user",
|
9
|
+
password: "password",
|
10
|
+
logger: Logger.new("/dev/null")
|
11
|
+
}
|
12
|
+
monitor_config = {
|
13
|
+
'Host' => device_config[:ip],
|
14
|
+
'Post' => 8085
|
15
|
+
}
|
16
|
+
monitor = RokuBuilder::Monitor.new(**device_config)
|
17
|
+
|
18
|
+
connection.expect(:waitfor, nil) do |config|
|
19
|
+
assert_equal /./, config['Match']
|
20
|
+
assert_equal false, config['Timeout']
|
21
|
+
end
|
22
|
+
|
23
|
+
def monitor.gets
|
24
|
+
sleep(0.1)
|
25
|
+
"q"
|
26
|
+
end
|
27
|
+
|
28
|
+
Net::Telnet.stub(:new, connection) do
|
29
|
+
monitor.monitor(type: :main)
|
30
|
+
end
|
31
|
+
|
32
|
+
connection.verify
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
|
3
|
+
class NavigatorTest < Minitest::Test
|
4
|
+
def test_navigator_nav
|
5
|
+
commands = {
|
6
|
+
up: "Up",
|
7
|
+
down: "Down",
|
8
|
+
right: "Right",
|
9
|
+
left: "Left",
|
10
|
+
select: "Select",
|
11
|
+
back: "Back",
|
12
|
+
home: "Home",
|
13
|
+
rew: "Rev",
|
14
|
+
ff: "Fwd",
|
15
|
+
play: "Play",
|
16
|
+
replay: "InstantReplay"
|
17
|
+
}
|
18
|
+
commands.each {|k,v|
|
19
|
+
path = "/keypress/#{v}"
|
20
|
+
navigator_test(path: path, input: k, type: :nav)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_navigator_type
|
25
|
+
path = "keypress/LIT_"
|
26
|
+
navigator_test(path: path, input: "Type", type: :text)
|
27
|
+
end
|
28
|
+
|
29
|
+
def navigator_test(path:, input:, type:)
|
30
|
+
connection = Minitest::Mock.new
|
31
|
+
faraday = Minitest::Mock.new
|
32
|
+
io = Minitest::Mock.new
|
33
|
+
response = Minitest::Mock.new
|
34
|
+
|
35
|
+
device_config = {
|
36
|
+
ip: "111.222.333",
|
37
|
+
user: "user",
|
38
|
+
password: "password",
|
39
|
+
logger: Logger.new("/dev/null")
|
40
|
+
}
|
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)}"
|
47
|
+
connection.expect(:post, response, [path])
|
48
|
+
response.expect(:success?, true)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
faraday.expect(:request, nil, [:multipart])
|
52
|
+
faraday.expect(:request, nil, [:url_encoded])
|
53
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
54
|
+
|
55
|
+
navigator = RokuBuilder::Navigator.new(**device_config)
|
56
|
+
success = nil
|
57
|
+
Faraday.stub(:new, connection, faraday) do
|
58
|
+
if type == :nav
|
59
|
+
success = navigator.nav(command: input)
|
60
|
+
elsif type == :text
|
61
|
+
success = navigator.type(text: input)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
assert success
|
66
|
+
|
67
|
+
connection.verify
|
68
|
+
faraday.verify
|
69
|
+
io.verify
|
70
|
+
response.verify
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require_relative "test_helper.rb"
|
2
|
+
|
3
|
+
class PackagerTest < Minitest::Test
|
4
|
+
def test_packager_package_failed
|
5
|
+
connection = Minitest::Mock.new
|
6
|
+
faraday = Minitest::Mock.new
|
7
|
+
response = Minitest::Mock.new
|
8
|
+
|
9
|
+
device_config = {
|
10
|
+
ip: "111.222.333",
|
11
|
+
user: "user",
|
12
|
+
password: "password",
|
13
|
+
logger: Logger.new("/dev/null")
|
14
|
+
}
|
15
|
+
payload = {
|
16
|
+
mysubmit: "Package",
|
17
|
+
app_name: "app_name",
|
18
|
+
passwd: "password",
|
19
|
+
pkg_time: 0
|
20
|
+
}
|
21
|
+
package_config ={
|
22
|
+
app_name_version: "app_name",
|
23
|
+
out_file: "out_file",
|
24
|
+
password: "password"
|
25
|
+
}
|
26
|
+
path = "/plugin_package"
|
27
|
+
|
28
|
+
faraday.expect(:headers, {})
|
29
|
+
faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
|
30
|
+
faraday.expect(:request, nil, [:multipart])
|
31
|
+
faraday.expect(:request, nil, [:url_encoded])
|
32
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
33
|
+
connection.expect(:post, response) do |arg1, arg2|
|
34
|
+
assert_equal path, arg1
|
35
|
+
assert_equal payload[:mysubmit], arg2[:mysubmit]
|
36
|
+
assert_equal payload[:app_name], arg2[:app_name]
|
37
|
+
assert_equal payload[:passwd], arg2[:passwd]
|
38
|
+
assert_equal payload[:pkg_time], arg2[:pkg_time]
|
39
|
+
end
|
40
|
+
response.expect(:body, "Failed: Error.")
|
41
|
+
|
42
|
+
packager = RokuBuilder::Packager.new(**device_config)
|
43
|
+
result = nil
|
44
|
+
Faraday.stub(:new, connection, faraday) do
|
45
|
+
Time.stub(:now, Time.at(0)) do
|
46
|
+
result = packager.package(**package_config)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal "Failed: Error.", result
|
51
|
+
|
52
|
+
connection.verify
|
53
|
+
faraday.verify
|
54
|
+
response.verify
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_packager_package
|
58
|
+
connection = Minitest::Mock.new
|
59
|
+
faraday = Minitest::Mock.new
|
60
|
+
response = Minitest::Mock.new
|
61
|
+
io = Minitest::Mock.new
|
62
|
+
|
63
|
+
device_config = {
|
64
|
+
ip: "111.222.333",
|
65
|
+
user: "user",
|
66
|
+
password: "password",
|
67
|
+
logger: Logger.new("/dev/null")
|
68
|
+
}
|
69
|
+
payload = {
|
70
|
+
mysubmit: "Package",
|
71
|
+
app_name: "app_name",
|
72
|
+
passwd: "password",
|
73
|
+
pkg_time: 0
|
74
|
+
}
|
75
|
+
package_config ={
|
76
|
+
app_name_version: "app_name",
|
77
|
+
out_file: "out_file",
|
78
|
+
password: "password"
|
79
|
+
}
|
80
|
+
path = "/plugin_package"
|
81
|
+
|
82
|
+
faraday.expect(:headers, {})
|
83
|
+
faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
|
84
|
+
faraday.expect(:request, nil, [:multipart])
|
85
|
+
faraday.expect(:request, nil, [:url_encoded])
|
86
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
87
|
+
|
88
|
+
faraday.expect(:request, nil, [:digest, device_config[:user], device_config[:password]])
|
89
|
+
faraday.expect(:adapter, nil, [Faraday.default_adapter])
|
90
|
+
|
91
|
+
connection.expect(:post, response) do |arg1, arg2|
|
92
|
+
assert_equal path, arg1
|
93
|
+
assert_equal payload[:mysubmit], arg2[:mysubmit]
|
94
|
+
assert_equal payload[:app_name], arg2[:app_name]
|
95
|
+
assert_equal payload[:passwd], arg2[:passwd]
|
96
|
+
assert_equal payload[:pkg_time], arg2[:pkg_time]
|
97
|
+
end
|
98
|
+
connection.expect(:get, response, ["/pkgs/pkg_url"])
|
99
|
+
|
100
|
+
response.expect(:body, "<a href=\"pkgs\">pkg_url</a>")
|
101
|
+
response.expect(:body, "<a href=\"pkgs\">pkg_url</a>")
|
102
|
+
|
103
|
+
response.expect(:status, 200)
|
104
|
+
response.expect(:body, "package_body")
|
105
|
+
|
106
|
+
io.expect(:write, nil, ["package_body"])
|
107
|
+
|
108
|
+
packager = RokuBuilder::Packager.new(**device_config)
|
109
|
+
result = nil
|
110
|
+
Faraday.stub(:new, connection, faraday) do
|
111
|
+
Time.stub(:now, Time.at(0)) do
|
112
|
+
File.stub(:open, nil, io) do
|
113
|
+
result = packager.package(**package_config)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_equal true, result
|
119
|
+
|
120
|
+
connection.verify
|
121
|
+
faraday.verify
|
122
|
+
response.verify
|
123
|
+
io.verify
|
124
|
+
end
|
125
|
+
end
|