nonnative 1.41.0 → 1.46.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50953dcfe695bf9196b5d3968a88f15fa6db81c630c0537e8c796ad63486d15f
4
- data.tar.gz: f910aec0fdb41fd9cea678657be191be85756d2c99ae45d64750a6f31c2534f7
3
+ metadata.gz: 5ab3f3907cd50fe1984cc57c28da9a17612beba23d73e8e82111ab133569a082
4
+ data.tar.gz: 71601b678ec6a2dbf53a1a2347955c691619dcf7310224d974d0b84bdc4de922
5
5
  SHA512:
6
- metadata.gz: 621d4af2d17163e749f0a706b991a52583f32603f64ba3a0fd978c31961c1de11c4b713a0023e0baf7309a9abf072f8642a4551d5a87d1c33bb4caa8844116b6
7
- data.tar.gz: 7f1516ab344e4ce99388046490809cb6a63e4de40909aab41c018b73d18e70d3d3b6c76069b9a747a15eed801d9bc94d83e097012bd82cdbcc49ff7a140443eb
6
+ metadata.gz: 0bcee6e1dfcba57e0a6be43cff1be649f9fcff7c1ec94a26cca48e47b1ae0d734a279ff61464acdca5e531ba4abfb79479a9f473bd893f63d97efa575b7387e4
7
+ data.tar.gz: 91d0a695d1d2efc013af95e4a10db2637c8d47dfa21ab49a0765098f7f69c34520e514598aadca2652d69610b7baeea76822388c6030f33b3f0c78c33ec039ea
data/CHANGELOG.md CHANGED
@@ -2,6 +2,52 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.46.0](https://github.com/alexfalkowski/nonnative/compare/v1.45.0...v1.46.0) (2021-05-10)
6
+
7
+
8
+ ### Features
9
+
10
+ * add loading config through configure ([#87](https://github.com/alexfalkowski/nonnative/issues/87)) ([a95e8b6](https://github.com/alexfalkowski/nonnative/commit/a95e8b6817380afd732d0aefb170726f905548cb))
11
+
12
+ ## [1.45.0](https://github.com/alexfalkowski/nonnative/compare/v1.44.1...v1.45.0) (2021-05-10)
13
+
14
+
15
+ ### Features
16
+
17
+ * add loading go command through config ([#86](https://github.com/alexfalkowski/nonnative/issues/86)) ([2f500d3](https://github.com/alexfalkowski/nonnative/commit/2f500d34ef6eb536b223651f84213f4f3d10c496))
18
+
19
+ ### [1.44.1](https://github.com/alexfalkowski/nonnative/compare/v1.44.0...v1.44.1) (2021-05-06)
20
+
21
+ ## [1.44.0](https://github.com/alexfalkowski/nonnative/compare/v1.43.0...v1.44.0) (2021-05-01)
22
+
23
+
24
+ ### Features
25
+
26
+ * move to reusable steps ([#84](https://github.com/alexfalkowski/nonnative/issues/84)) ([37b6175](https://github.com/alexfalkowski/nonnative/commit/37b6175e920dfb70f3d6f13226240dd045c2db3d))
27
+
28
+ ## [1.43.0](https://github.com/alexfalkowski/nonnative/compare/v1.42.2...v1.43.0) (2021-04-30)
29
+
30
+
31
+ ### Features
32
+
33
+ * release version 1.43.0 ([#83](https://github.com/alexfalkowski/nonnative/issues/83)) ([b51526d](https://github.com/alexfalkowski/nonnative/commit/b51526d99d24522a26f534d28769cc8cdee4af04))
34
+
35
+ ### [1.42.2](https://github.com/alexfalkowski/nonnative/compare/v1.42.1...v1.42.2) (2021-04-30)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * make sure we parse services config ([#82](https://github.com/alexfalkowski/nonnative/issues/82)) ([2a52af7](https://github.com/alexfalkowski/nonnative/commit/2a52af74b75443674a2235c424d69f15516ab60f))
41
+
42
+ ### [1.42.1](https://github.com/alexfalkowski/nonnative/compare/v1.42.0...v1.42.1) (2021-04-30)
43
+
44
+ ## [1.42.0](https://github.com/alexfalkowski/nonnative/compare/v1.41.0...v1.42.0) (2021-04-30)
45
+
46
+
47
+ ### Features
48
+
49
+ * add services ([#80](https://github.com/alexfalkowski/nonnative/issues/80)) ([454980e](https://github.com/alexfalkowski/nonnative/commit/454980e1eb141995c96203fcf9254bfe2cb0133e))
50
+
5
51
  ## [1.41.0](https://github.com/alexfalkowski/nonnative/compare/v1.40.2...v1.41.0) (2021-04-30)
6
52
 
7
53
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.41.0)
4
+ nonnative (1.46.0)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.5)
6
6
  cucumber (>= 6, < 7)
7
7
  grpc (>= 1, < 2)
@@ -15,7 +15,7 @@ PATH
15
15
  GEM
16
16
  remote: https://rubygems.org/
17
17
  specs:
18
- activesupport (6.1.3.1)
18
+ activesupport (6.1.3.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 1.6, < 2)
21
21
  minitest (>= 5.1)
@@ -73,7 +73,7 @@ GEM
73
73
  unf (>= 0.0.5, < 1.0.0)
74
74
  e2mmap (0.1.0)
75
75
  ffi (1.15.0)
76
- google-protobuf (3.15.8)
76
+ google-protobuf (3.16.0)
77
77
  googleapis-common-protos-types (1.0.6)
78
78
  google-protobuf (~> 3.14)
79
79
  grpc (1.37.1)
@@ -106,14 +106,14 @@ GEM
106
106
  mini_portile2 (~> 2.5.0)
107
107
  racc (~> 1.4)
108
108
  parallel (1.20.1)
109
- parser (3.0.1.0)
109
+ parser (3.0.1.1)
110
110
  ast (~> 2.4.1)
111
111
  protobuf-cucumber (3.10.8)
112
112
  activesupport (>= 3.2)
113
113
  middleware
114
114
  thor
115
115
  thread_safe
116
- puma (5.2.2)
116
+ puma (5.3.0)
117
117
  nio4r (~> 2.0)
118
118
  racc (1.5.2)
119
119
  rack (2.2.3)
@@ -147,17 +147,17 @@ GEM
147
147
  diff-lcs (>= 1.2.0, < 2.0)
148
148
  rspec-support (~> 3.10.0)
149
149
  rspec-support (3.10.2)
150
- rubocop (1.13.0)
150
+ rubocop (1.14.0)
151
151
  parallel (~> 1.10)
152
152
  parser (>= 3.0.0.0)
153
153
  rainbow (>= 2.2.2, < 4.0)
154
154
  regexp_parser (>= 1.8, < 3.0)
155
155
  rexml
156
- rubocop-ast (>= 1.2.0, < 2.0)
156
+ rubocop-ast (>= 1.5.0, < 2.0)
157
157
  ruby-progressbar (~> 1.7)
158
158
  unicode-display_width (>= 1.4.0, < 3.0)
159
- rubocop-ast (1.4.1)
160
- parser (>= 2.7.1.5)
159
+ rubocop-ast (1.5.0)
160
+ parser (>= 3.0.1.1)
161
161
  ruby-progressbar (1.11.0)
162
162
  ruby2_keywords (0.0.4)
163
163
  simplecov (0.16.1)
@@ -210,7 +210,7 @@ DEPENDENCIES
210
210
  bundler (~> 2.1, >= 2.1.4)
211
211
  coveralls (~> 0.8.23)
212
212
  nonnative!
213
- rubocop (~> 1.12)
213
+ rubocop (~> 1.14)
214
214
  solargraph (~> 0.40.4)
215
215
 
216
216
  BUNDLED WITH
data/README.md CHANGED
@@ -33,12 +33,12 @@ Or install it yourself as:
33
33
 
34
34
  Configure nonnative with the following:
35
35
 
36
- - Process/Server that you want to start.
36
+ - Process, Server or Service that you want to start.
37
37
  - A timeout value.
38
38
  - Port to verify.
39
39
  - The class for servers.
40
40
  - The log for servers/processes
41
- - The strategy for processes/servers.
41
+ - The strategy for processes, servers and services.
42
42
 
43
43
  ### Strategy
44
44
 
@@ -53,6 +53,8 @@ This can be overridden by the following environment variables:
53
53
 
54
54
  ### Processes
55
55
 
56
+ A process is some sort of command that you would run locally.
57
+
56
58
  Setup it up programmatically:
57
59
 
58
60
  ```ruby
@@ -84,7 +86,7 @@ Setup it up through configuration:
84
86
 
85
87
  ```yaml
86
88
  version: 1.0
87
- strategy: manual
89
+ strategy: startup
88
90
  processes:
89
91
  -
90
92
  name: start_1
@@ -106,11 +108,15 @@ Then load the file with
106
108
  ```ruby
107
109
  require 'nonnative'
108
110
 
109
- Nonnative.load_configuration('configuration.yml')
111
+ Nonnative.configure do |config|
112
+ config.load_file('configuration.yml')
113
+ end
110
114
  ```
111
115
 
112
116
  ### Servers
113
117
 
118
+ A server is a dependency to some external API.
119
+
114
120
  Define your server:
115
121
 
116
122
  ```ruby
@@ -140,7 +146,7 @@ Setup it up programmatically:
140
146
  require 'nonnative'
141
147
 
142
148
  Nonnative.configure do |config|
143
- config.strategy = :manual
149
+ config.strategy = :startup
144
150
 
145
151
  config.server do |s|
146
152
  s.name = 'server_1'
@@ -164,17 +170,17 @@ Setup it up through configuration:
164
170
 
165
171
  ```yaml
166
172
  version: 1.0
167
- strategy: manual
173
+ strategy: startup
168
174
  servers:
169
175
  -
170
176
  name: server_1
171
- klass: Nonnative::EchoServer
177
+ class: Nonnative::EchoServer
172
178
  timeout: 1
173
179
  port: 12323
174
180
  log: features/logs/server_1.log
175
181
  -
176
182
  name: server_2
177
- klass: Nonnative::EchoServer
183
+ class: Nonnative::EchoServer
178
184
  timeout: 1
179
185
  port: 12324
180
186
  log: features/logs/server_2.log
@@ -185,7 +191,9 @@ Then load the file with:
185
191
  ```ruby
186
192
  require 'nonnative'
187
193
 
188
- Nonnative.load_configuration('configuration.yml')
194
+ Nonnative.configure do |config|
195
+ config.load_file('configuration.yml')
196
+ end
189
197
  ```
190
198
 
191
199
  #### HTTP
@@ -220,7 +228,7 @@ Setup it up programmatically:
220
228
  require 'nonnative'
221
229
 
222
230
  Nonnative.configure do |config|
223
- config.strategy = :manual
231
+ config.strategy = :startup
224
232
 
225
233
  config.server do |s|
226
234
  s.name = 'http_server_1'
@@ -236,11 +244,11 @@ Setup it up through configuration:
236
244
 
237
245
  ```yaml
238
246
  version: 1.0
239
- strategy: manual
247
+ strategy: startup
240
248
  servers:
241
249
  -
242
250
  name: http_server_1
243
- klass: Nonnative::Features::HTTPServer
251
+ class: Nonnative::Features::HTTPServer
244
252
  timeout: 1
245
253
  port: 4567
246
254
  log: features/logs/http_server_1.log
@@ -251,7 +259,9 @@ Then load the file with:
251
259
  ```ruby
252
260
  require 'nonnative'
253
261
 
254
- Nonnative.load_configuration('configuration.yml')
262
+ Nonnative.configure do |config|
263
+ config.load_file('configuration.yml')
264
+ end
255
265
  ```
256
266
 
257
267
  #### gRPC
@@ -282,7 +292,7 @@ Setup it up programmatically:
282
292
  require 'nonnative'
283
293
 
284
294
  Nonnative.configure do |config|
285
- config.strategy = :manual
295
+ config.strategy = :startup
286
296
 
287
297
  config.server do |s|
288
298
  s.name = 'grpc_server_1'
@@ -298,11 +308,11 @@ Setup it up through configuration:
298
308
 
299
309
  ```yaml
300
310
  version: 1.0
301
- strategy: manual
311
+ strategy: startup
302
312
  servers:
303
313
  -
304
314
  name: grpc_server_1
305
- klass: Nonnative::Features::GRPCServer
315
+ class: Nonnative::Features::GRPCServer
306
316
  timeout: 1
307
317
  port: 9002
308
318
  log: features/logs/grpc_server_1.log
@@ -313,8 +323,59 @@ Then load the file with:
313
323
  ```ruby
314
324
  require 'nonnative'
315
325
 
316
- Nonnative.load_configuration('configuration.yml')
326
+ Nonnative.configure do |config|
327
+ config.load_file('configuration.yml')
328
+ end
329
+ ```
330
+
331
+ ### Services
332
+
333
+ A service is an external dependency to your system. This is usually an expensive process to start like a DB and you would prefer to be managed externally. Services are not really exciting by themselves, it's when we add proxies that they allow us to do some extra work.
334
+
335
+ Setup it up programmatically:
336
+
337
+ ```ruby
338
+ require 'nonnative'
339
+
340
+ Nonnative.configure do |config|
341
+ config.strategy = :startup
342
+
343
+ config.service do |s|
344
+ s.name = 'postgres'
345
+ p.port = 5432
346
+ end
347
+
348
+ config.service do |s|
349
+ s.name = 'redis'
350
+ s.port = 6379
351
+ end
352
+ end
353
+ ```
354
+
355
+ Setup it up through configuration:
356
+
357
+ ```yaml
358
+ version: 1.0
359
+ strategy: startup
360
+ processes:
361
+ -
362
+ name: postgres
363
+ port: 5432
364
+ -
365
+ name: redis
366
+ port: 6379
367
+ ```
368
+
369
+ Then load the file with
370
+
371
+ ```ruby
372
+ require 'nonnative'
373
+
374
+ Nonnative.configure do |config|
375
+ config.load_file('configuration.yml')
376
+ end
317
377
  ```
378
+
318
379
  #### Proxies
319
380
 
320
381
  We allow different proxies to be configured. These proxies can be used to simulate all kind of situations. The proxies that can be configured are:
@@ -329,7 +390,7 @@ Setup it up programmatically:
329
390
  require 'nonnative'
330
391
 
331
392
  Nonnative.configure do |config|
332
- config.strategy = :manual
393
+ config.strategy = :startup
333
394
 
334
395
  config.process do |p|
335
396
  p.proxy = {
@@ -348,7 +409,7 @@ Setup it up through configuration:
348
409
 
349
410
  ```yaml
350
411
  version: 1.0
351
- strategy: manual
412
+ strategy: startup
352
413
  processes:
353
414
  -
354
415
  proxy:
@@ -367,7 +428,7 @@ Setup it up programmatically:
367
428
  require 'nonnative'
368
429
 
369
430
  Nonnative.configure do |config|
370
- config.strategy = :manual
431
+ config.strategy = :startup
371
432
 
372
433
  config.server do |s|
373
434
  s.proxy = {
@@ -386,7 +447,7 @@ Setup it up through configuration:
386
447
 
387
448
  ```yaml
388
449
  version: 1.0
389
- strategy: manual
450
+ strategy: startup
390
451
  servers:
391
452
  -
392
453
  proxy:
@@ -397,6 +458,44 @@ servers:
397
458
  delay: 5
398
459
  ```
399
460
 
461
+ ##### Services
462
+
463
+ Setup it up programmatically:
464
+
465
+ ```ruby
466
+ require 'nonnative'
467
+
468
+ Nonnative.configure do |config|
469
+ config.strategy = :startup
470
+
471
+ config.service do |s|
472
+ s.proxy = {
473
+ type: 'fault_injection',
474
+ port: 20_000,
475
+ log: 'features/logs/proxy_server.log',
476
+ options: {
477
+ delay: 5
478
+ }
479
+ }
480
+ end
481
+ end
482
+ ```
483
+
484
+ Setup it up through configuration:
485
+
486
+ ```yaml
487
+ version: 1.0
488
+ strategy: startup
489
+ services:
490
+ -
491
+ proxy:
492
+ type: fault_injection
493
+ port: 20000
494
+ log: features/logs/proxy_server.log
495
+ options:
496
+ delay: 5
497
+ ```
498
+
400
499
  ##### Fault Injection
401
500
 
402
501
  The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
@@ -416,6 +515,13 @@ server.proxy.close_all # To use close_all.
416
515
  server.proxy.reset # To reset it back to a good state.
417
516
  ```
418
517
 
518
+ With cucumber:
519
+
520
+ ```cucumber
521
+ Given I set the proxy for process 'process_1' to 'close_all'
522
+ Then And I should reset the proxy for process 'process_1'
523
+ ```
524
+
419
525
  ###### Servers
420
526
 
421
527
  Setup it up programmatically:
@@ -428,6 +534,32 @@ server.proxy.close_all # To use close_all.
428
534
  server.proxy.reset # To reset it back to a good state.
429
535
  ```
430
536
 
537
+ With cucumber:
538
+
539
+ ```cucumber
540
+ Given I set the proxy for server 'server_1' to 'close_all'
541
+ Then And I should reset the proxy for server 'server_1'
542
+ ```
543
+
544
+ ###### Services
545
+
546
+ Setup it up programmatically:
547
+
548
+ ```ruby
549
+ name = 'name of service in configuration'
550
+ service = Nonnative.pool.service_by_name(name)
551
+
552
+ service.proxy.close_all # To use close_all.
553
+ service.proxy.reset # To reset it back to a good state.
554
+ ```
555
+
556
+ With cucumber:
557
+
558
+ ```cucumber
559
+ Given I set the proxy for service 'service_1' to 'close_all'
560
+ Then And I should reset the proxy for service 'service_1'
561
+ ```
562
+
431
563
  ### Go
432
564
 
433
565
  As we love using go as a language for services we have added support to start binaries with defined parameters. This expects that you build your services in the format of `command sub_command --params`
@@ -439,16 +571,10 @@ To get this to work you will need to create a `main_test.go` file with these con
439
571
 
440
572
  package main
441
573
 
442
- import (
443
- "testing"
444
-
445
- "github.com/your_location/cmd"
446
- )
574
+ import "testing"
447
575
 
448
576
  func TestFeatures(t *testing.T) {
449
- if err := cmd.Execute(); err != nil {
450
- t.Fatal(err.Error())
451
- }
577
+ main()
452
578
  }
453
579
  ```
454
580
 
@@ -458,8 +584,27 @@ Then to compile this binary you will need to do the following:
458
584
  go test -mod vendor -c -tags features -covermode=count -o your_binary -coverpkg=./... github.com/your_location
459
585
  ```
460
586
 
461
- Then to get an executable you do the following:
587
+ Setup it up programmatically:
462
588
 
463
589
  ```ruby
464
590
  Nonnative.go_executable('reports', 'your_binary', 'sub_command', '--config config.yaml')
465
591
  ```
592
+
593
+ Setup it up through configuration:
594
+
595
+ ```yaml
596
+ version: 1.0
597
+ strategy: startup
598
+ processes:
599
+ -
600
+ name: go
601
+ go:
602
+ output: reports
603
+ executable: your_binary
604
+ command: sub_command
605
+ parameters:
606
+ - --config config.yaml
607
+ timeout: 5
608
+ port: 8000
609
+ log: features/logs/go.log
610
+ ```
data/lib/nonnative.rb CHANGED
@@ -11,22 +11,26 @@ require 'rest-client'
11
11
  require 'puma'
12
12
  require 'puma/server'
13
13
  require 'concurrent'
14
+ require 'cucumber'
14
15
 
15
16
  require 'nonnative/version'
16
17
  require 'nonnative/error'
17
18
  require 'nonnative/start_error'
18
19
  require 'nonnative/stop_error'
20
+ require 'nonnative/not_found_error'
19
21
  require 'nonnative/timeout'
20
22
  require 'nonnative/port'
21
23
  require 'nonnative/configuration'
22
- require 'nonnative/configuration_service'
24
+ require 'nonnative/configuration_runner'
23
25
  require 'nonnative/configuration_process'
24
26
  require 'nonnative/configuration_server'
27
+ require 'nonnative/configuration_service'
25
28
  require 'nonnative/configuration_proxy'
26
- require 'nonnative/service'
29
+ require 'nonnative/runner'
27
30
  require 'nonnative/process'
28
- require 'nonnative/pool'
29
31
  require 'nonnative/server'
32
+ require 'nonnative/service'
33
+ require 'nonnative/pool'
30
34
  require 'nonnative/http_client'
31
35
  require 'nonnative/http_server'
32
36
  require 'nonnative/grpc_server'
@@ -42,17 +46,18 @@ require 'nonnative/invalid_data_socket_pair'
42
46
  require 'nonnative/socket_pair_factory'
43
47
  require 'nonnative/strategy'
44
48
  require 'nonnative/go_command'
49
+ require 'nonnative/cucumber'
45
50
 
46
51
  module Nonnative
47
52
  class << self
48
53
  attr_reader :pool
49
54
 
50
- def go_executable(output, exec, cmd, *params)
51
- Nonnative::GoCommand.new(exec, output).executable(cmd, params)
55
+ def log_lines(path, predicate)
56
+ File.readlines(path).select { |l| predicate.call(l) }
52
57
  end
53
58
 
54
- def load_configuration(path)
55
- @configuration ||= Nonnative::Configuration.load_file(path) # rubocop:disable Naming/MemoizedInstanceVariableName
59
+ def go_executable(output, exec, cmd, *params)
60
+ Nonnative::GoCommand.new(exec, output).executable(cmd, params)
56
61
  end
57
62
 
58
63
  def configuration
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cucumber'
4
-
5
3
  Before do
6
4
  Nonnative.start
7
5
  end
@@ -3,7 +3,6 @@
3
3
  module Nonnative
4
4
  class CloseAllSocketPair < SocketPair
5
5
  def connect(local_socket)
6
- ensure
7
6
  local_socket.close
8
7
  end
9
8
  end
@@ -2,72 +2,26 @@
2
2
 
3
3
  module Nonnative
4
4
  class Configuration
5
- class << self
6
- def load_file(path)
7
- file = YAML.load_file(path)
8
-
9
- new.tap do |c|
10
- c.strategy = file['strategy']
11
-
12
- processes(file, c)
13
- servers(file, c)
14
- end
15
- end
16
-
17
- private
18
-
19
- def processes(file, config)
20
- processes = file['processes'] || []
21
- processes.each do |fd|
22
- config.process do |d|
23
- d.name = fd['name']
24
- d.command = fd['command']
25
- d.timeout = fd['timeout']
26
- d.port = fd['port']
27
- d.log = fd['log']
28
- d.signal = fd['signal']
29
-
30
- proxy d, fd['proxy']
31
- end
32
- end
33
- end
34
-
35
- def servers(file, config)
36
- servers = file['servers'] || []
37
- servers.each do |fd|
38
- config.server do |s|
39
- s.name = fd['name']
40
- s.klass = Object.const_get(fd['klass'])
41
- s.timeout = fd['timeout']
42
- s.port = fd['port']
43
- s.log = fd['log']
44
-
45
- proxy s, fd['proxy']
46
- end
47
- end
48
- end
49
-
50
- def proxy(server, proxy)
51
- return unless proxy
52
-
53
- server.proxy = {
54
- type: proxy['type'],
55
- port: proxy['port'],
56
- log: proxy['log'],
57
- options: proxy['options']
58
- }
59
- end
60
- end
61
-
62
5
  def initialize
63
6
  @strategy = Strategy.new
64
7
  @processes = []
65
8
  @servers = []
9
+ @services = []
66
10
  end
67
11
 
68
- attr_accessor :processes, :servers
12
+ attr_accessor :processes, :servers, :services
69
13
  attr_reader :strategy
70
14
 
15
+ def load_file(path)
16
+ file = YAML.load_file(path)
17
+
18
+ self.strategy = file['strategy']
19
+
20
+ add_processes(file)
21
+ add_servers(file)
22
+ add_services(file)
23
+ end
24
+
71
25
  def strategy=(value)
72
26
  @strategy = Strategy.new(value)
73
27
  end
@@ -85,5 +39,80 @@ module Nonnative
85
39
 
86
40
  servers << server
87
41
  end
42
+
43
+ def service
44
+ service = Nonnative::ConfigurationService.new
45
+ yield service
46
+
47
+ services << service
48
+ end
49
+
50
+ private
51
+
52
+ def add_processes(file)
53
+ processes = file['processes'] || []
54
+ processes.each do |fd|
55
+ process do |d|
56
+ d.name = fd['name']
57
+ d.command = command(fd)
58
+ d.timeout = fd['timeout']
59
+ d.port = fd['port']
60
+ d.log = fd['log']
61
+ d.signal = fd['signal']
62
+
63
+ proxy d, fd['proxy']
64
+ end
65
+ end
66
+ end
67
+
68
+ def command(process)
69
+ go = process['go']
70
+ if go
71
+ params = go['parameters'] || []
72
+ Nonnative.go_executable(go['output'], go['executable'], go['command'], *params)
73
+ else
74
+ process['command']
75
+ end
76
+ end
77
+
78
+ def add_servers(file)
79
+ servers = file['servers'] || []
80
+ servers.each do |fd|
81
+ server do |s|
82
+ s.name = fd['name']
83
+ s.klass = Object.const_get(fd['class'])
84
+ s.timeout = fd['timeout']
85
+ s.port = fd['port']
86
+ s.log = fd['log']
87
+
88
+ proxy s, fd['proxy']
89
+ end
90
+ end
91
+ end
92
+
93
+ def add_services(file)
94
+ services = file['services'] || []
95
+ services.each do |fd|
96
+ service do |s|
97
+ s.name = fd['name']
98
+ s.timeout = fd['timeout']
99
+ s.port = fd['port']
100
+ s.log = fd['log']
101
+
102
+ proxy s, fd['proxy']
103
+ end
104
+ end
105
+ end
106
+
107
+ def proxy(runner, proxy)
108
+ return unless proxy
109
+
110
+ runner.proxy = {
111
+ type: proxy['type'],
112
+ port: proxy['port'],
113
+ log: proxy['log'],
114
+ options: proxy['options']
115
+ }
116
+ end
88
117
  end
89
118
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationProcess < ConfigurationService
4
+ class ConfigurationProcess < ConfigurationRunner
5
5
  attr_accessor :command, :signal
6
6
  end
7
7
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ConfigurationRunner
5
+ attr_accessor :name, :timeout, :port, :log
6
+ attr_reader :proxy
7
+
8
+ def initialize
9
+ @proxy = Nonnative::ConfigurationProxy.new
10
+ end
11
+
12
+ def proxy=(value)
13
+ proxy.type = value[:type]
14
+ proxy.port = value[:port]
15
+ proxy.log = value[:log]
16
+ proxy.options = value[:options]
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationServer < ConfigurationService
4
+ class ConfigurationServer < ConfigurationRunner
5
5
  attr_accessor :klass
6
6
  end
7
7
  end
@@ -1,19 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationService
5
- attr_accessor :name, :timeout, :port, :log
6
- attr_reader :proxy
7
-
8
- def initialize
9
- @proxy = Nonnative::ConfigurationProxy.new
10
- end
11
-
12
- def proxy=(value)
13
- proxy.type = value[:type]
14
- proxy.port = value[:port]
15
- proxy.log = value[:log]
16
- proxy.options = value[:options]
17
- end
4
+ class ConfigurationService < ConfigurationRunner
18
5
  end
19
6
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ Given('I set the proxy for process {string} to {string}') do |name, operation|
4
+ server = Nonnative.pool.process_by_name(name)
5
+ server.proxy.send(operation)
6
+ end
7
+
8
+ Given('I set the proxy for server {string} to {string}') do |name, operation|
9
+ server = Nonnative.pool.server_by_name(name)
10
+ server.proxy.send(operation)
11
+ end
12
+
13
+ Given('I set the proxy for service {string} to {string}') do |name, operation|
14
+ service = Nonnative.pool.service_by_name(name)
15
+ service.proxy.send(operation)
16
+ end
17
+
18
+ Then('I should reset the proxy for process {string}') do |name|
19
+ server = Nonnative.pool.process_by_name(name)
20
+ server.proxy.reset
21
+ end
22
+
23
+ Then('I should reset the proxy for server {string}') do |name|
24
+ server = Nonnative.pool.server_by_name(name)
25
+ server.proxy.reset
26
+ end
27
+
28
+ Then('I should reset the proxy for service {string}') do |name|
29
+ service = Nonnative.pool.service_by_name(name)
30
+ service.proxy.reset
31
+ end
@@ -17,8 +17,8 @@ module Nonnative
17
17
  end
18
18
 
19
19
  def stop
20
- thread.terminate
21
- tcp_server.close
20
+ thread&.terminate
21
+ tcp_server&.close
22
22
  end
23
23
 
24
24
  def close_all
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class NotFoundError < Nonnative::Error
5
+ end
6
+ end
@@ -7,39 +7,54 @@ module Nonnative
7
7
  end
8
8
 
9
9
  def start(&block)
10
+ services.each(&:start)
10
11
  [servers, processes].each { |t| process(t, :start, :open?, &block) }
11
12
  end
12
13
 
13
14
  def stop(&block)
14
15
  [processes, servers].each { |t| process(t, :stop, :closed?, &block) }
16
+ services.each(&:stop)
15
17
  end
16
18
 
17
19
  def process_by_name(name)
18
- index = configuration.processes.find_index { |s| s.name == name }
19
- processes[index].first
20
+ processes[runner_index(configuration.processes, name)].first
20
21
  end
21
22
 
22
23
  def server_by_name(name)
23
- index = configuration.servers.find_index { |s| s.name == name }
24
- servers[index].first
24
+ servers[runner_index(configuration.servers, name)].first
25
+ end
26
+
27
+ def service_by_name(name)
28
+ services[runner_index(configuration.services, name)]
25
29
  end
26
30
 
27
31
  private
28
32
 
29
33
  attr_reader :configuration
30
34
 
35
+ def runner_index(runners, name)
36
+ index = runners.find_index { |s| s.name == name }
37
+ raise NotFoundError, "Could not find runner with name '#{name}'" if index.nil?
38
+
39
+ index
40
+ end
41
+
31
42
  def processes
32
- @processes ||= configuration.processes.map do |d|
33
- [Nonnative::Process.new(d), Nonnative::Port.new(d)]
43
+ @processes ||= configuration.processes.map do |p|
44
+ [Nonnative::Process.new(p), Nonnative::Port.new(p)]
34
45
  end
35
46
  end
36
47
 
37
48
  def servers
38
- @servers ||= configuration.servers.map do |d|
39
- [d.klass.new(d), Nonnative::Port.new(d)]
49
+ @servers ||= configuration.servers.map do |s|
50
+ [s.klass.new(s), Nonnative::Port.new(s)]
40
51
  end
41
52
  end
42
53
 
54
+ def services
55
+ @services ||= configuration.services.map { |s| Nonnative::Service.new(s) }
56
+ end
57
+
43
58
  def process(all, type_method, port_method, &block)
44
59
  types = []
45
60
  pids = []
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Process < Nonnative::Service
4
+ class Process < Runner
5
5
  def start
6
6
  unless process_exists?
7
7
  proxy.start
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class Runner
5
+ attr_reader :proxy
6
+
7
+ def initialize(service)
8
+ @service = service
9
+ @timeout = Nonnative::Timeout.new(service.timeout)
10
+ @proxy = Nonnative::ProxyFactory.create(service)
11
+ end
12
+
13
+ def name
14
+ service.name
15
+ end
16
+
17
+ protected
18
+
19
+ attr_reader :service, :timeout
20
+
21
+ def wait_start
22
+ sleep 0.1
23
+ end
24
+
25
+ def wait_stop
26
+ sleep 0.1
27
+ end
28
+ end
29
+ end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Server < Nonnative::Service
5
- attr_reader :proxy
6
-
4
+ class Server < Runner
7
5
  def start
8
6
  unless thread
9
7
  proxy.start
@@ -1,29 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Service
5
- attr_reader :proxy
6
-
7
- def initialize(service)
8
- @service = service
9
- @timeout = Nonnative::Timeout.new(service.timeout)
10
- @proxy = Nonnative::ProxyFactory.create(service)
11
- end
12
-
13
- def name
14
- service.name
15
- end
16
-
17
- protected
18
-
19
- attr_reader :service, :timeout
20
-
21
- def wait_start
22
- sleep 0.1
4
+ class Service < Runner
5
+ def start
6
+ proxy.start
23
7
  end
24
8
 
25
- def wait_stop
26
- sleep 0.1
9
+ def stop
10
+ proxy.stop
27
11
  end
28
12
  end
29
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.41.0'
4
+ VERSION = '1.46.0'
5
5
  end
data/nonnative.gemspec CHANGED
@@ -8,7 +8,7 @@ require 'nonnative/version'
8
8
  Gem::Specification.new do |spec|
9
9
  spec.name = 'nonnative'
10
10
  spec.version = Nonnative::VERSION
11
- spec.authors = ['Alex Falkowski']
11
+ spec.authors = ['Alejandro Falkowski']
12
12
  spec.email = ['alexrfalkowski@gmail.com']
13
13
 
14
14
  spec.summary = 'Allows you to keep using the power of ruby to test other systems'
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
37
37
  spec.add_development_dependency 'coveralls', '~> 0.8.23'
38
- spec.add_development_dependency 'rubocop', '~> 1.12'
38
+ spec.add_development_dependency 'rubocop', '~> 1.14'
39
39
  spec.add_development_dependency 'solargraph', '~> 0.40.4'
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nonnative
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.41.0
4
+ version: 1.46.0
5
5
  platform: ruby
6
6
  authors:
7
- - Alex Falkowski
7
+ - Alejandro Falkowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: '1.12'
215
+ version: '1.14'
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: '1.12'
222
+ version: '1.14'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: solargraph
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -262,8 +262,10 @@ files:
262
262
  - lib/nonnative/configuration.rb
263
263
  - lib/nonnative/configuration_process.rb
264
264
  - lib/nonnative/configuration_proxy.rb
265
+ - lib/nonnative/configuration_runner.rb
265
266
  - lib/nonnative/configuration_server.rb
266
267
  - lib/nonnative/configuration_service.rb
268
+ - lib/nonnative/cucumber.rb
267
269
  - lib/nonnative/delay_socket_pair.rb
268
270
  - lib/nonnative/error.rb
269
271
  - lib/nonnative/fault_injection_proxy.rb
@@ -274,12 +276,14 @@ files:
274
276
  - lib/nonnative/invalid_data_socket_pair.rb
275
277
  - lib/nonnative/manual.rb
276
278
  - lib/nonnative/no_proxy.rb
279
+ - lib/nonnative/not_found_error.rb
277
280
  - lib/nonnative/observability.rb
278
281
  - lib/nonnative/pool.rb
279
282
  - lib/nonnative/port.rb
280
283
  - lib/nonnative/process.rb
281
284
  - lib/nonnative/proxy.rb
282
285
  - lib/nonnative/proxy_factory.rb
286
+ - lib/nonnative/runner.rb
283
287
  - lib/nonnative/server.rb
284
288
  - lib/nonnative/service.rb
285
289
  - lib/nonnative/socket_pair.rb