yui_rest_client 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca27d870afe905331021d8f5e4f5404fddbde8cbd6f1c30f99014a9e67c65e26
4
- data.tar.gz: 4b80b15184d9ab7073a23bdf126366790571aa976892c79183b559b053b2fe1a
3
+ metadata.gz: 054eac696bc03538afc5b08fa12c156e6706d478080139f2aae45a84b08848c8
4
+ data.tar.gz: e5ff3ffce8cd7f73f755e64da9805195d162870d73beb83bbacba3a019beb62d
5
5
  SHA512:
6
- metadata.gz: f49a5754c51af9e4e97013872ed4b0b9db9b3b88cc436e54150e0247ef628dad4f22f5f2cde32a463d3e11427e11ba0ba209248b1e0adeefb516fde4d50d2a3e
7
- data.tar.gz: 7f1aadb357cbce7897199832153388b5e421abf4ee651032ad75b18d21fc4042d2ed9eb960b6668b2a4a47e0cb7071f398c9b8be4b08a282043cb6bf9aaa37f4
6
+ metadata.gz: a850ce076c6250c3d68713bf9e9a629834598cc8ff7b9b1cb74949d9201ef6f75809f16cccd34232c7bfb3d5b7f3fee91e8dd91986d76edd0738a5feae7ca92b
7
+ data.tar.gz: 42cfa2bb2347ac72c952a6718de07f87b0e3f00481169aead945b464454a1eede7002eb1ee2806f9ba63650529b0ef1ec2c176d1e8878a4577ae7ae6a7edc78e
@@ -8,7 +8,6 @@ require 'timeout'
8
8
  require 'time'
9
9
 
10
10
  require 'yui_rest_client/version'
11
- require 'yui_rest_client/local_process'
12
11
  require 'yui_rest_client/widgets'
13
12
  require 'yui_rest_client/logger'
14
13
  require 'yui_rest_client/timer'
@@ -2,6 +2,8 @@
2
2
 
3
3
  module YuiRestClient
4
4
  class App
5
+ attr_reader :host, :port
6
+
5
7
  # Used to initialize main entry point of YuiRestClient and set host and port
6
8
  # for the application under control.
7
9
  # @param host [String] host address (e.g. 'localhost', '192.168.0.1')
@@ -13,6 +15,16 @@ module YuiRestClient
13
15
  @version_controller = Http::VersionController.new(host: host, port: port)
14
16
  end
15
17
 
18
+ # wait until the specified port is open or until the timeout is reached
19
+ # @raise YuiRestClient::Error::TimeoutError if the port is not opened in time
20
+ def connect
21
+ Wait.until(timeout: YuiRestClient.timeout, interval: YuiRestClient.interval) do
22
+ YuiRestClient.logger.debug("Waiting for #{@host}:#{@port}...")
23
+ port_open?
24
+ end
25
+ self
26
+ end
27
+
16
28
  # Initializes new instance of Bargraph with the filter provided.
17
29
  # Does not make request to libyui-rest-api.
18
30
  # @param filter [Hash] filter to find a widget
@@ -226,5 +238,20 @@ module YuiRestClient
226
238
  YuiRestClient.logger.info("Server API version: #{server_api_v}")
227
239
  server_api_v <= client_api_version
228
240
  end
241
+
242
+ private
243
+
244
+ # is the target port open?
245
+ # @return [Boolean] true if the port is open, false otherwise
246
+ def port_open?(seconds = 1)
247
+ Timeout.timeout(seconds) do
248
+ TCPSocket.new(@host, @port).close
249
+ true
250
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
251
+ false
252
+ end
253
+ rescue Timeout::Error
254
+ false
255
+ end
229
256
  end
230
257
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YuiRestClient
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.2'
5
5
  API_VERSION = 'v1'
6
6
  end
@@ -20,7 +20,6 @@ module YuiRestClient
20
20
  require 'yui_rest_client/widgets/table'
21
21
  require 'yui_rest_client/widgets/textbox'
22
22
  require 'yui_rest_client/widgets/timefield'
23
- require 'yui_rest_client/widgets/label'
24
23
  require 'yui_rest_client/widgets/richtext'
25
24
  require 'yui_rest_client/widgets/tree'
26
25
  # Class representing a Wizard UI. It can be YWizard
@@ -128,7 +128,7 @@ module YuiRestClient
128
128
 
129
129
  def get_nodes(items, root = '')
130
130
  items.map do |x|
131
- current = root.empty? ? x[:label] : root + '|' + x[:label]
131
+ current = root.empty? ? x[:label] : "#{root}|#{x[:label]}"
132
132
  x.key?(:children) ? [current, get_nodes(x[:children], current)] : current
133
133
  end.flatten
134
134
  end
@@ -136,7 +136,7 @@ module YuiRestClient
136
136
  def get_selected_node(items, root = '')
137
137
  selected = ''
138
138
  items.each do |x|
139
- current = root.empty? ? x[:label] : root + '|' + x[:label]
139
+ current = root.empty? ? x[:label] : "#{root}|#{x[:label]}"
140
140
  return current if x[:selected]
141
141
 
142
142
  selected = get_selected_node(x[:children], current) if x.key?(:children)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yui_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquin Rivera
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2020-10-20 00:00:00.000000000 Z
15
+ date: 2020-11-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -167,7 +167,6 @@ files:
167
167
  - lib/yui_rest_client/http/response.rb
168
168
  - lib/yui_rest_client/http/version_controller.rb
169
169
  - lib/yui_rest_client/http/widget_controller.rb
170
- - lib/yui_rest_client/local_process.rb
171
170
  - lib/yui_rest_client/logger.rb
172
171
  - lib/yui_rest_client/timer.rb
173
172
  - lib/yui_rest_client/version.rb
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Client to interact with YAST UI rest api framework for integration testing
4
- module YuiRestClient
5
- class LocalProcess
6
- # default timeout for process
7
- DEFAULT_TIMEOUT_PROCESS = 2
8
-
9
- # start the application in background
10
- # @param application [String] the command to start
11
- def start_app(application)
12
- @app_host = 'localhost'
13
- @app_port = port
14
-
15
- # another app already running?
16
- raise "The port #{@app_host}:#{@app_port} is already open!" if port_open?(@app_host, @app_port)
17
-
18
- YuiRestClient.logger.debug("Starting #{application}...")
19
- # create a new process group so easily we will be able
20
- # to kill all its sub-processes
21
- @app_pid = spawn(application, pgroup: true)
22
- wait_for_port(@app_host, @app_port)
23
- YuiRestClient.logger.debug("App started: '#{application}'")
24
- end
25
-
26
- # kill the process if it is still running after finishing a scenario
27
- def kill_app
28
- return unless @app_pid
29
-
30
- Process.waitpid(@app_pid, Process::WNOHANG)
31
- YuiRestClient.logger.debug("Sending KILL signal for PID #{@app_pid}")
32
- Process.kill('-KILL', @app_pid)
33
- rescue Errno::ECHILD, Errno::ESRCH
34
- # the process has already exited
35
- @app_pid = nil
36
- end
37
-
38
- private
39
-
40
- # set the application introspection port for communication
41
- def port
42
- ENV['YUI_HTTP_PORT'] ||= '9999'
43
- end
44
-
45
- # is the target port open?
46
- # @param host [String] the host to connect to
47
- # @param port [Integer] the port number
48
- # @return [Boolean] true if the port is open, false otherwise
49
- def port_open?(host, port)
50
- TCPSocket.new(host, port).close
51
- true
52
- rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
53
- false
54
- end
55
-
56
- # wait until the specified port is open or until the timeout is reached
57
- # @param host [String] the host to connect to
58
- # @param port [Integer] the port number
59
- # @raise YuiRestClient::Error::TimeoutError if the port is not opened in time
60
- def wait_for_port(host, port)
61
- Wait.until(timeout: YuiRestClient.timeout, interval: YuiRestClient.interval) do
62
- YuiRestClient.logger.debug("Waiting for #{host}:#{port}...")
63
- port_open?(host, port)
64
- end
65
- end
66
-
67
- # optionally allow a short delay between the steps to watch the UI changes
68
- def add_step_delay
69
- delay = ENV['STEP_DELAY'].to_f
70
- sleep(delay) if delay.positive?
71
- end
72
- end
73
- end