nonnative 1.40.0 → 1.45.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: 870143059910a181598b40406aebc0e8d7882133aa01b82091da14436dee664a
4
- data.tar.gz: 6a1e9449a4eb21b1c58c6c5b3a8256546956f84db8cd5c09c7a939ea09f33cbc
3
+ metadata.gz: 85f5fe8fb5f61dce67f48ddf86ea0d2b76a6446e0e249af0f5afd22229bf3d3d
4
+ data.tar.gz: 178d46b667d50d4f8b68b0e18946ca2aa265e41fd3f8c869229a6e464ddf6e41
5
5
  SHA512:
6
- metadata.gz: 38f4f40a6460548a9470f707c66e1b5067c3a336a97f49de4415ffdcbb85f07c7f626b61f5948485c630ddcb9d8235b0a6ed069cbd1c6844bfd25b4e9109879c
7
- data.tar.gz: a19898c50a83a2f7d3d330eec829d7420236f87f0f00919256ebe1ab34c4bffd175124cd5ed832b09275942707b9a15fc3f84a7b14e82d85a5d9437e89bcbadf
6
+ metadata.gz: 782d41b50946ad3741bdf1deedaff39c47db9d890d00f6e2d3ea854c8dff0a9ca3e96d3960f6e2c9d8776b41f4dc6170ca7d0fd65fb86fb65809922258b9f2df
7
+ data.tar.gz: 317a75048db20140a4cd99dfc87ab8001fa4bcbfda7fc750fc3fb00ab8bfb7f7e25e16a38be17faff2c100c683281fac4f1fa9054cc4a39f510baabf6f174bb6
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: x3EcMK4Nr770BeIFZengeQ2DLDCDjNfNo
data/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
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.45.0](https://github.com/alexfalkowski/nonnative/compare/v1.44.1...v1.45.0) (2021-05-10)
6
+
7
+
8
+ ### Features
9
+
10
+ * add loading go command through config ([#86](https://github.com/alexfalkowski/nonnative/issues/86)) ([2f500d3](https://github.com/alexfalkowski/nonnative/commit/2f500d34ef6eb536b223651f84213f4f3d10c496))
11
+
12
+ ### [1.44.1](https://github.com/alexfalkowski/nonnative/compare/v1.44.0...v1.44.1) (2021-05-06)
13
+
14
+ ## [1.44.0](https://github.com/alexfalkowski/nonnative/compare/v1.43.0...v1.44.0) (2021-05-01)
15
+
16
+
17
+ ### Features
18
+
19
+ * move to reusable steps ([#84](https://github.com/alexfalkowski/nonnative/issues/84)) ([37b6175](https://github.com/alexfalkowski/nonnative/commit/37b6175e920dfb70f3d6f13226240dd045c2db3d))
20
+
21
+ ## [1.43.0](https://github.com/alexfalkowski/nonnative/compare/v1.42.2...v1.43.0) (2021-04-30)
22
+
23
+
24
+ ### Features
25
+
26
+ * release version 1.43.0 ([#83](https://github.com/alexfalkowski/nonnative/issues/83)) ([b51526d](https://github.com/alexfalkowski/nonnative/commit/b51526d99d24522a26f534d28769cc8cdee4af04))
27
+
28
+ ### [1.42.2](https://github.com/alexfalkowski/nonnative/compare/v1.42.1...v1.42.2) (2021-04-30)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * make sure we parse services config ([#82](https://github.com/alexfalkowski/nonnative/issues/82)) ([2a52af7](https://github.com/alexfalkowski/nonnative/commit/2a52af74b75443674a2235c424d69f15516ab60f))
34
+
35
+ ### [1.42.1](https://github.com/alexfalkowski/nonnative/compare/v1.42.0...v1.42.1) (2021-04-30)
36
+
37
+ ## [1.42.0](https://github.com/alexfalkowski/nonnative/compare/v1.41.0...v1.42.0) (2021-04-30)
38
+
39
+
40
+ ### Features
41
+
42
+ * add services ([#80](https://github.com/alexfalkowski/nonnative/issues/80)) ([454980e](https://github.com/alexfalkowski/nonnative/commit/454980e1eb141995c96203fcf9254bfe2cb0133e))
43
+
44
+ ## [1.41.0](https://github.com/alexfalkowski/nonnative/compare/v1.40.2...v1.41.0) (2021-04-30)
45
+
46
+
47
+ ### Features
48
+
49
+ * add proxy to processes ([#79](https://github.com/alexfalkowski/nonnative/issues/79)) ([d52b2bb](https://github.com/alexfalkowski/nonnative/commit/d52b2bb6fad91612f9b9a64817c861d1c227ef0b))
50
+
51
+ ### [1.40.2](https://github.com/alexfalkowski/nonnative/compare/v1.40.1...v1.40.2) (2021-04-27)
52
+
53
+ ### [1.40.1](https://github.com/alexfalkowski/nonnative/compare/v1.40.0...v1.40.1) (2021-04-27)
54
+
5
55
  ## [1.40.0](https://github.com/alexfalkowski/nonnative/compare/v1.39.0...v1.40.0) (2021-04-25)
6
56
 
7
57
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.40.0)
4
+ nonnative (1.45.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)
@@ -29,6 +29,12 @@ GEM
29
29
  benchmark-trend (0.4.0)
30
30
  builder (3.2.4)
31
31
  concurrent-ruby (1.1.8)
32
+ coveralls (0.8.23)
33
+ json (>= 1.8, < 3)
34
+ simplecov (~> 0.16.1)
35
+ term-ansicolor (~> 1.3)
36
+ thor (>= 0.19.4, < 2.0)
37
+ tins (~> 1.6)
32
38
  cucumber (6.0.0)
33
39
  builder (~> 3.2, >= 3.2.4)
34
40
  cucumber-core (~> 9.0, >= 9.0.0)
@@ -67,19 +73,20 @@ GEM
67
73
  unf (>= 0.0.5, < 1.0.0)
68
74
  e2mmap (0.1.0)
69
75
  ffi (1.15.0)
70
- google-protobuf (3.15.8)
76
+ google-protobuf (3.16.0)
71
77
  googleapis-common-protos-types (1.0.6)
72
78
  google-protobuf (~> 3.14)
73
- grpc (1.37.0)
79
+ grpc (1.37.1)
74
80
  google-protobuf (~> 3.15)
75
81
  googleapis-common-protos-types (~> 1.0)
76
- grpc-tools (1.37.0)
82
+ grpc-tools (1.37.1)
77
83
  http-accept (1.7.0)
78
84
  http-cookie (1.0.3)
79
85
  domain_name (~> 0.5)
80
86
  i18n (1.8.10)
81
87
  concurrent-ruby (~> 1.0)
82
88
  jaro_winkler (1.5.4)
89
+ json (2.5.1)
83
90
  kramdown (2.3.1)
84
91
  rexml
85
92
  kramdown-parser-gfm (1.1.0)
@@ -99,14 +106,14 @@ GEM
99
106
  mini_portile2 (~> 2.5.0)
100
107
  racc (~> 1.4)
101
108
  parallel (1.20.1)
102
- parser (3.0.1.0)
109
+ parser (3.0.1.1)
103
110
  ast (~> 2.4.1)
104
111
  protobuf-cucumber (3.10.8)
105
112
  activesupport (>= 3.2)
106
113
  middleware
107
114
  thor
108
115
  thread_safe
109
- puma (5.2.2)
116
+ puma (5.3.0)
110
117
  nio4r (~> 2.0)
111
118
  racc (1.5.2)
112
119
  rack (2.2.3)
@@ -140,25 +147,24 @@ GEM
140
147
  diff-lcs (>= 1.2.0, < 2.0)
141
148
  rspec-support (~> 3.10.0)
142
149
  rspec-support (3.10.2)
143
- rubocop (1.13.0)
150
+ rubocop (1.14.0)
144
151
  parallel (~> 1.10)
145
152
  parser (>= 3.0.0.0)
146
153
  rainbow (>= 2.2.2, < 4.0)
147
154
  regexp_parser (>= 1.8, < 3.0)
148
155
  rexml
149
- rubocop-ast (>= 1.2.0, < 2.0)
156
+ rubocop-ast (>= 1.5.0, < 2.0)
150
157
  ruby-progressbar (~> 1.7)
151
158
  unicode-display_width (>= 1.4.0, < 3.0)
152
- rubocop-ast (1.4.1)
153
- parser (>= 2.7.1.5)
159
+ rubocop-ast (1.5.0)
160
+ parser (>= 3.0.1.1)
154
161
  ruby-progressbar (1.11.0)
155
162
  ruby2_keywords (0.0.4)
156
- simplecov (0.21.2)
163
+ simplecov (0.16.1)
157
164
  docile (~> 1.1)
158
- simplecov-html (~> 0.11)
159
- simplecov_json_formatter (~> 0.1)
160
- simplecov-html (0.12.3)
161
- simplecov_json_formatter (0.1.2)
165
+ json (>= 1.8, < 3)
166
+ simplecov-html (~> 0.10.0)
167
+ simplecov-html (0.10.2)
162
168
  sinatra (2.1.0)
163
169
  mustermann (~> 1.0)
164
170
  rack (~> 2.2)
@@ -178,11 +184,16 @@ GEM
178
184
  thor (~> 1.0)
179
185
  tilt (~> 2.0)
180
186
  yard (~> 0.9, >= 0.9.24)
187
+ sync (0.5.0)
181
188
  sys-uname (1.2.2)
182
189
  ffi (~> 1.1)
190
+ term-ansicolor (1.7.1)
191
+ tins (~> 1.0)
183
192
  thor (1.0.1)
184
193
  thread_safe (0.3.6)
185
194
  tilt (2.0.10)
195
+ tins (1.28.0)
196
+ sync
186
197
  tzinfo (2.0.4)
187
198
  concurrent-ruby (~> 1.0)
188
199
  unf (0.1.4)
@@ -197,9 +208,9 @@ PLATFORMS
197
208
 
198
209
  DEPENDENCIES
199
210
  bundler (~> 2.1, >= 2.1.4)
211
+ coveralls (~> 0.8.23)
200
212
  nonnative!
201
- rubocop (~> 1.12)
202
- simplecov (~> 0.21.2)
213
+ rubocop (~> 1.14)
203
214
  solargraph (~> 0.40.4)
204
215
 
205
216
  BUNDLED WITH
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![CircleCI](https://circleci.com/gh/alexfalkowski/nonnative.svg?style=svg)](https://circleci.com/gh/alexfalkowski/nonnative)
2
+ [![Coverage Status](https://coveralls.io/repos/github/alexfalkowski/nonnative/badge.svg?branch=master)](https://coveralls.io/github/alexfalkowski/nonnative?branch=master)
2
3
 
3
4
  # Nonnative
4
5
 
@@ -32,12 +33,12 @@ Or install it yourself as:
32
33
 
33
34
  Configure nonnative with the following:
34
35
 
35
- - Process/Server that you want to start.
36
+ - Process, Server or Service that you want to start.
36
37
  - A timeout value.
37
38
  - Port to verify.
38
39
  - The class for servers.
39
40
  - The log for servers/processes
40
- - The strategy for processes/servers.
41
+ - The strategy for processes, servers and services.
41
42
 
42
43
  ### Strategy
43
44
 
@@ -52,6 +53,8 @@ This can be overridden by the following environment variables:
52
53
 
53
54
  ### Processes
54
55
 
56
+ A process is some sort of command that you would run locally.
57
+
55
58
  Setup it up programmatically:
56
59
 
57
60
  ```ruby
@@ -60,21 +63,21 @@ require 'nonnative'
60
63
  Nonnative.configure do |config|
61
64
  config.strategy = :startup
62
65
 
63
- config.process do |d|
64
- d.name = 'start_1'
65
- d.command = 'features/support/bin/start 12_321'
66
- d.timeout = config.strategy.timeout
67
- d.port = 12_321
68
- d.log = 'features/logs/12_321.log'
69
- d.signal = 'INT' # Possible values are described in Signal.list.keys
66
+ config.process do |p|
67
+ p.name = 'start_1'
68
+ p.command = 'features/support/bin/start 12_321'
69
+ p.timeout = config.strategy.timeout
70
+ p.port = 12_321
71
+ p.log = 'features/logs/12_321.log'
72
+ p.signal = 'INT' # Possible values are described in Signal.list.keys
70
73
  end
71
74
 
72
- config.process do |d|
73
- d.name = 'start_2'
74
- d.command = 'features/support/bin/start 12_322'
75
- d.timeout = 0.5
76
- d.port = 12_322
77
- d.log = 'features/logs/12_322.log'
75
+ config.process do |p|
76
+ p.name = 'start_2'
77
+ p.command = 'features/support/bin/start 12_322'
78
+ p.timeout = 0.5
79
+ p.port = 12_322
80
+ p.log = 'features/logs/12_322.log'
78
81
  end
79
82
  end
80
83
  ```
@@ -83,7 +86,7 @@ Setup it up through configuration:
83
86
 
84
87
  ```yaml
85
88
  version: 1.0
86
- strategy: manual
89
+ strategy: startup
87
90
  processes:
88
91
  -
89
92
  name: start_1
@@ -110,6 +113,8 @@ Nonnative.load_configuration('configuration.yml')
110
113
 
111
114
  ### Servers
112
115
 
116
+ A server is a dependency to some external API.
117
+
113
118
  Define your server:
114
119
 
115
120
  ```ruby
@@ -139,7 +144,7 @@ Setup it up programmatically:
139
144
  require 'nonnative'
140
145
 
141
146
  Nonnative.configure do |config|
142
- config.strategy = :manual
147
+ config.strategy = :startup
143
148
 
144
149
  config.server do |s|
145
150
  s.name = 'server_1'
@@ -163,17 +168,17 @@ Setup it up through configuration:
163
168
 
164
169
  ```yaml
165
170
  version: 1.0
166
- strategy: manual
171
+ strategy: startup
167
172
  servers:
168
173
  -
169
174
  name: server_1
170
- klass: Nonnative::EchoServer
175
+ class: Nonnative::EchoServer
171
176
  timeout: 1
172
177
  port: 12323
173
178
  log: features/logs/server_1.log
174
179
  -
175
180
  name: server_2
176
- klass: Nonnative::EchoServer
181
+ class: Nonnative::EchoServer
177
182
  timeout: 1
178
183
  port: 12324
179
184
  log: features/logs/server_2.log
@@ -219,7 +224,7 @@ Setup it up programmatically:
219
224
  require 'nonnative'
220
225
 
221
226
  Nonnative.configure do |config|
222
- config.strategy = :manual
227
+ config.strategy = :startup
223
228
 
224
229
  config.server do |s|
225
230
  s.name = 'http_server_1'
@@ -235,11 +240,11 @@ Setup it up through configuration:
235
240
 
236
241
  ```yaml
237
242
  version: 1.0
238
- strategy: manual
243
+ strategy: startup
239
244
  servers:
240
245
  -
241
246
  name: http_server_1
242
- klass: Nonnative::Features::HTTPServer
247
+ class: Nonnative::Features::HTTPServer
243
248
  timeout: 1
244
249
  port: 4567
245
250
  log: features/logs/http_server_1.log
@@ -281,7 +286,7 @@ Setup it up programmatically:
281
286
  require 'nonnative'
282
287
 
283
288
  Nonnative.configure do |config|
284
- config.strategy = :manual
289
+ config.strategy = :startup
285
290
 
286
291
  config.server do |s|
287
292
  s.name = 'grpc_server_1'
@@ -297,11 +302,11 @@ Setup it up through configuration:
297
302
 
298
303
  ```yaml
299
304
  version: 1.0
300
- strategy: manual
305
+ strategy: startup
301
306
  servers:
302
307
  -
303
308
  name: grpc_server_1
304
- klass: Nonnative::Features::GRPCServer
309
+ class: Nonnative::Features::GRPCServer
305
310
  timeout: 1
306
311
  port: 9002
307
312
  log: features/logs/grpc_server_1.log
@@ -314,22 +319,109 @@ require 'nonnative'
314
319
 
315
320
  Nonnative.load_configuration('configuration.yml')
316
321
  ```
322
+
323
+ ### Services
324
+
325
+ 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.
326
+
327
+ Setup it up programmatically:
328
+
329
+ ```ruby
330
+ require 'nonnative'
331
+
332
+ Nonnative.configure do |config|
333
+ config.strategy = :startup
334
+
335
+ config.service do |s|
336
+ s.name = 'postgres'
337
+ p.port = 5432
338
+ end
339
+
340
+ config.service do |s|
341
+ s.name = 'redis'
342
+ s.port = 6379
343
+ end
344
+ end
345
+ ```
346
+
347
+ Setup it up through configuration:
348
+
349
+ ```yaml
350
+ version: 1.0
351
+ strategy: startup
352
+ processes:
353
+ -
354
+ name: postgres
355
+ port: 5432
356
+ -
357
+ name: redis
358
+ port: 6379
359
+ ```
360
+
361
+ Then load the file with
362
+
363
+ ```ruby
364
+ require 'nonnative'
365
+
366
+ Nonnative.load_configuration('configuration.yml')
367
+ ```
368
+
317
369
  #### Proxies
318
370
 
319
371
  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:
320
372
  - `none` (this is the default)
321
373
  - `fault_injection`
322
374
 
375
+ ##### Processes
376
+
377
+ Setup it up programmatically:
378
+
379
+ ```ruby
380
+ require 'nonnative'
381
+
382
+ Nonnative.configure do |config|
383
+ config.strategy = :startup
384
+
385
+ config.process do |p|
386
+ p.proxy = {
387
+ type: 'fault_injection',
388
+ port: 20_000,
389
+ log: 'features/logs/proxy_server.log',
390
+ options: {
391
+ delay: 5
392
+ }
393
+ }
394
+ end
395
+ end
396
+ ```
397
+
398
+ Setup it up through configuration:
399
+
400
+ ```yaml
401
+ version: 1.0
402
+ strategy: startup
403
+ processes:
404
+ -
405
+ proxy:
406
+ type: fault_injection
407
+ port: 20000
408
+ log: features/logs/proxy_server.log
409
+ options:
410
+ delay: 5
411
+ ```
412
+
413
+ ##### Servers
414
+
323
415
  Setup it up programmatically:
324
416
 
325
417
  ```ruby
326
418
  require 'nonnative'
327
419
 
328
420
  Nonnative.configure do |config|
329
- config.strategy = :manual
421
+ config.strategy = :startup
330
422
 
331
- config.server do |d|
332
- d.proxy = {
423
+ config.server do |s|
424
+ s.proxy = {
333
425
  type: 'fault_injection',
334
426
  port: 20_000,
335
427
  log: 'features/logs/proxy_server.log',
@@ -345,7 +437,7 @@ Setup it up through configuration:
345
437
 
346
438
  ```yaml
347
439
  version: 1.0
348
- strategy: manual
440
+ strategy: startup
349
441
  servers:
350
442
  -
351
443
  proxy:
@@ -356,6 +448,44 @@ servers:
356
448
  delay: 5
357
449
  ```
358
450
 
451
+ ##### Services
452
+
453
+ Setup it up programmatically:
454
+
455
+ ```ruby
456
+ require 'nonnative'
457
+
458
+ Nonnative.configure do |config|
459
+ config.strategy = :startup
460
+
461
+ config.service do |s|
462
+ s.proxy = {
463
+ type: 'fault_injection',
464
+ port: 20_000,
465
+ log: 'features/logs/proxy_server.log',
466
+ options: {
467
+ delay: 5
468
+ }
469
+ }
470
+ end
471
+ end
472
+ ```
473
+
474
+ Setup it up through configuration:
475
+
476
+ ```yaml
477
+ version: 1.0
478
+ strategy: startup
479
+ services:
480
+ -
481
+ proxy:
482
+ type: fault_injection
483
+ port: 20000
484
+ log: features/logs/proxy_server.log
485
+ options:
486
+ delay: 5
487
+ ```
488
+
359
489
  ##### Fault Injection
360
490
 
361
491
  The `fault_injection` proxy allows you to simulate failures by injecting them. We currently support the following:
@@ -363,6 +493,27 @@ The `fault_injection` proxy allows you to simulate failures by injecting them. W
363
493
  - `delay` - This delays the communication between the connection. Default is 2 secs can be configured through options.
364
494
  - `invalid_data` - This takes the input and rearranges it to produce invalid data.
365
495
 
496
+ ###### Processes
497
+
498
+ Setup it up programmatically:
499
+
500
+ ```ruby
501
+ name = 'name of process in configuration'
502
+ server = Nonnative.pool.process_by_name(name)
503
+
504
+ server.proxy.close_all # To use close_all.
505
+ server.proxy.reset # To reset it back to a good state.
506
+ ```
507
+
508
+ With cucumber:
509
+
510
+ ```cucumber
511
+ Given I set the proxy for process 'process_1' to 'close_all'
512
+ Then And I should reset the proxy for process 'process_1'
513
+ ```
514
+
515
+ ###### Servers
516
+
366
517
  Setup it up programmatically:
367
518
 
368
519
  ```ruby
@@ -373,6 +524,32 @@ server.proxy.close_all # To use close_all.
373
524
  server.proxy.reset # To reset it back to a good state.
374
525
  ```
375
526
 
527
+ With cucumber:
528
+
529
+ ```cucumber
530
+ Given I set the proxy for server 'server_1' to 'close_all'
531
+ Then And I should reset the proxy for server 'server_1'
532
+ ```
533
+
534
+ ###### Services
535
+
536
+ Setup it up programmatically:
537
+
538
+ ```ruby
539
+ name = 'name of service in configuration'
540
+ service = Nonnative.pool.service_by_name(name)
541
+
542
+ service.proxy.close_all # To use close_all.
543
+ service.proxy.reset # To reset it back to a good state.
544
+ ```
545
+
546
+ With cucumber:
547
+
548
+ ```cucumber
549
+ Given I set the proxy for service 'service_1' to 'close_all'
550
+ Then And I should reset the proxy for service 'service_1'
551
+ ```
552
+
376
553
  ### Go
377
554
 
378
555
  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`
@@ -380,15 +557,12 @@ As we love using go as a language for services we have added support to start bi
380
557
  To get this to work you will need to create a `main_test.go` file with these contents:
381
558
 
382
559
  ```go
560
+ // +build features
561
+
383
562
  package main
384
563
 
385
- import (
386
- "testing"
387
- )
564
+ import "testing"
388
565
 
389
- // TestFeatures is a hack that allows us to figure out what the coverage is during
390
- // integration tests. I would not recommend that you use a binary built using
391
- // this hack outside of a test suite.
392
566
  func TestFeatures(t *testing.T) {
393
567
  main()
394
568
  }
@@ -397,11 +571,30 @@ func TestFeatures(t *testing.T) {
397
571
  Then to compile this binary you will need to do the following:
398
572
 
399
573
  ```sh
400
- go test -mod vendor -c -covermode=count -o your_binary -coverpkg=./... github.com/your_location
574
+ go test -mod vendor -c -tags features -covermode=count -o your_binary -coverpkg=./... github.com/your_location
401
575
  ```
402
576
 
403
- Then to get an executable you do the following:
577
+ Setup it up programmatically:
404
578
 
405
579
  ```ruby
406
580
  Nonnative.go_executable('reports', 'your_binary', 'sub_command', '--config config.yaml')
407
581
  ```
582
+
583
+ Setup it up through configuration:
584
+
585
+ ```yaml
586
+ version: 1.0
587
+ strategy: startup
588
+ processes:
589
+ -
590
+ name: go
591
+ go:
592
+ output: reports
593
+ executable: your_binary
594
+ command: sub_command
595
+ parameters:
596
+ - --config config.yaml
597
+ timeout: 5
598
+ port: 8000
599
+ log: features/logs/go.log
600
+ ```
data/lib/nonnative.rb CHANGED
@@ -11,21 +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'
24
+ require 'nonnative/configuration_runner'
22
25
  require 'nonnative/configuration_process'
23
26
  require 'nonnative/configuration_server'
27
+ require 'nonnative/configuration_service'
24
28
  require 'nonnative/configuration_proxy'
29
+ require 'nonnative/runner'
30
+ require 'nonnative/process'
31
+ require 'nonnative/server'
25
32
  require 'nonnative/service'
26
- require 'nonnative/command'
27
33
  require 'nonnative/pool'
28
- require 'nonnative/server'
29
34
  require 'nonnative/http_client'
30
35
  require 'nonnative/http_server'
31
36
  require 'nonnative/grpc_server'
@@ -41,11 +46,16 @@ require 'nonnative/invalid_data_socket_pair'
41
46
  require 'nonnative/socket_pair_factory'
42
47
  require 'nonnative/strategy'
43
48
  require 'nonnative/go_command'
49
+ require 'nonnative/cucumber'
44
50
 
45
51
  module Nonnative
46
52
  class << self
47
53
  attr_reader :pool
48
54
 
55
+ def log_lines(path, predicate)
56
+ File.readlines(path).select { |l| predicate.call(l) }
57
+ end
58
+
49
59
  def go_executable(output, exec, cmd, *params)
50
60
  Nonnative::GoCommand.new(exec, output).executable(cmd, params)
51
61
  end
@@ -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
@@ -11,6 +11,7 @@ module Nonnative
11
11
 
12
12
  processes(file, c)
13
13
  servers(file, c)
14
+ services(file, c)
14
15
  end
15
16
  end
16
17
 
@@ -21,21 +22,46 @@ module Nonnative
21
22
  processes.each do |fd|
22
23
  config.process do |d|
23
24
  d.name = fd['name']
24
- d.command = fd['command']
25
+ d.command = command(fd)
25
26
  d.timeout = fd['timeout']
26
27
  d.port = fd['port']
27
28
  d.log = fd['log']
28
29
  d.signal = fd['signal']
30
+
31
+ proxy d, fd['proxy']
29
32
  end
30
33
  end
31
34
  end
32
35
 
36
+ def command(process)
37
+ go = process['go']
38
+ if go
39
+ Nonnative.go_executable(go['output'], go['executable'], go['command'], *go['parameters'])
40
+ else
41
+ process['command']
42
+ end
43
+ end
44
+
33
45
  def servers(file, config)
34
46
  servers = file['servers'] || []
35
47
  servers.each do |fd|
36
48
  config.server do |s|
37
49
  s.name = fd['name']
38
- s.klass = Object.const_get(fd['klass'])
50
+ s.klass = Object.const_get(fd['class'])
51
+ s.timeout = fd['timeout']
52
+ s.port = fd['port']
53
+ s.log = fd['log']
54
+
55
+ proxy s, fd['proxy']
56
+ end
57
+ end
58
+ end
59
+
60
+ def services(file, config)
61
+ services = file['services'] || []
62
+ services.each do |fd|
63
+ config.service do |s|
64
+ s.name = fd['name']
39
65
  s.timeout = fd['timeout']
40
66
  s.port = fd['port']
41
67
  s.log = fd['log']
@@ -61,9 +87,10 @@ module Nonnative
61
87
  @strategy = Strategy.new
62
88
  @processes = []
63
89
  @servers = []
90
+ @services = []
64
91
  end
65
92
 
66
- attr_accessor :processes, :servers
93
+ attr_accessor :processes, :servers, :services
67
94
  attr_reader :strategy
68
95
 
69
96
  def strategy=(value)
@@ -83,5 +110,12 @@ module Nonnative
83
110
 
84
111
  servers << server
85
112
  end
113
+
114
+ def service
115
+ service = Nonnative::ConfigurationService.new
116
+ yield service
117
+
118
+ services << service
119
+ end
86
120
  end
87
121
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationProcess
5
- attr_accessor :name, :command, :timeout, :port, :log, :signal
4
+ class ConfigurationProcess < ConfigurationRunner
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,19 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class ConfigurationServer
5
- attr_accessor :name, :klass, :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 ConfigurationServer < ConfigurationRunner
5
+ attr_accessor :klass
18
6
  end
19
7
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nonnative
4
+ class ConfigurationService < ConfigurationRunner
5
+ end
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,34 +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)
17
+ end
18
+
19
+ def process_by_name(name)
20
+ processes[runner_index(configuration.processes, name)].first
15
21
  end
16
22
 
17
23
  def server_by_name(name)
18
- index = configuration.servers.find_index { |s| s.name == name }
19
- 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)]
20
29
  end
21
30
 
22
31
  private
23
32
 
24
33
  attr_reader :configuration
25
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
+
26
42
  def processes
27
- @processes ||= configuration.processes.map do |d|
28
- [Nonnative::Command.new(d), Nonnative::Port.new(d)]
43
+ @processes ||= configuration.processes.map do |p|
44
+ [Nonnative::Process.new(p), Nonnative::Port.new(p)]
29
45
  end
30
46
  end
31
47
 
32
48
  def servers
33
- @servers ||= configuration.servers.map do |d|
34
- [d.klass.new(d), Nonnative::Port.new(d)]
49
+ @servers ||= configuration.servers.map do |s|
50
+ [s.klass.new(s), Nonnative::Port.new(s)]
35
51
  end
36
52
  end
37
53
 
54
+ def services
55
+ @services ||= configuration.services.map { |s| Nonnative::Service.new(s) }
56
+ end
57
+
38
58
  def process(all, type_method, port_method, &block)
39
59
  types = []
40
60
  pids = []
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Command < Nonnative::Service
4
+ class Process < Runner
5
5
  def start
6
- unless command_exists?
7
- @pid = command_spawn
6
+ unless process_exists?
7
+ proxy.start
8
+ @pid = process_spawn
8
9
  wait_start
9
10
  end
10
11
 
@@ -12,8 +13,9 @@ module Nonnative
12
13
  end
13
14
 
14
15
  def stop
15
- if command_exists?
16
- command_kill
16
+ if process_exists?
17
+ process_kill
18
+ proxy.stop
17
19
  wait_stop
18
20
  end
19
21
 
@@ -24,7 +26,7 @@ module Nonnative
24
26
 
25
27
  def wait_stop
26
28
  timeout.perform do
27
- Process.waitpid2(pid)
29
+ ::Process.waitpid2(pid)
28
30
  end
29
31
  end
30
32
 
@@ -32,20 +34,20 @@ module Nonnative
32
34
 
33
35
  attr_reader :pid
34
36
 
35
- def command_kill
37
+ def process_kill
36
38
  signal = Signal.list[service.signal || 'INT'] || Signal.list['INT']
37
- Process.kill(signal, pid)
39
+ ::Process.kill(signal, pid)
38
40
  end
39
41
 
40
- def command_spawn
42
+ def process_spawn
41
43
  spawn(service.command, %i[out err] => [service.log, 'a'])
42
44
  end
43
45
 
44
- def command_exists?
46
+ def process_exists?
45
47
  return false if pid.nil?
46
48
 
47
49
  signal = Signal.list['EXIT']
48
- Process.kill(signal, pid)
50
+ ::Process.kill(signal, pid)
49
51
  true
50
52
  rescue Errno::ESRCH
51
53
  false
@@ -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,15 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Server < Nonnative::Service
5
- attr_reader :proxy
6
-
7
- def initialize(service)
8
- @proxy = Nonnative::ProxyFactory.create(service)
9
-
10
- super service
11
- end
12
-
4
+ class Server < Runner
13
5
  def start
14
6
  unless thread
15
7
  proxy.start
@@ -1,26 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- class Service
5
- def initialize(service)
6
- @service = service
7
- @timeout = Nonnative::Timeout.new(service.timeout)
4
+ class Service < Runner
5
+ def start
6
+ proxy.start
8
7
  end
9
8
 
10
- def name
11
- service.name
12
- end
13
-
14
- protected
15
-
16
- attr_reader :service, :timeout
17
-
18
- def wait_start
19
- sleep 0.1
20
- end
21
-
22
- def wait_stop
23
- sleep 0.1
9
+ def stop
10
+ proxy.stop
24
11
  end
25
12
  end
26
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.40.0'
4
+ VERSION = '1.45.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'
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'sinatra', '~> 2.0', '>= 2.0.8.1'
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
37
- spec.add_development_dependency 'rubocop', '~> 1.12'
38
- spec.add_development_dependency 'simplecov', '~> 0.21.2'
37
+ spec.add_development_dependency 'coveralls', '~> 0.8.23'
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.40.0
4
+ version: 1.45.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-25 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
@@ -193,33 +193,33 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: 2.1.4
195
195
  - !ruby/object:Gem::Dependency
196
- name: rubocop
196
+ name: coveralls
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '1.12'
201
+ version: 0.8.23
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '1.12'
208
+ version: 0.8.23
209
209
  - !ruby/object:Gem::Dependency
210
- name: simplecov
210
+ name: rubocop
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 0.21.2
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: 0.21.2
222
+ version: '1.14'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: solargraph
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -243,6 +243,7 @@ extra_rdoc_files: []
243
243
  files:
244
244
  - ".circleci/config.yml"
245
245
  - ".config/cucumber.yml"
246
+ - ".coveralls.yml"
246
247
  - ".editorconfig"
247
248
  - ".gitignore"
248
249
  - ".rubocop.yml"
@@ -258,11 +259,13 @@ files:
258
259
  - lib/nonnative.rb
259
260
  - lib/nonnative/before.rb
260
261
  - lib/nonnative/close_all_socket_pair.rb
261
- - lib/nonnative/command.rb
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
267
+ - lib/nonnative/configuration_service.rb
268
+ - lib/nonnative/cucumber.rb
266
269
  - lib/nonnative/delay_socket_pair.rb
267
270
  - lib/nonnative/error.rb
268
271
  - lib/nonnative/fault_injection_proxy.rb
@@ -273,11 +276,14 @@ files:
273
276
  - lib/nonnative/invalid_data_socket_pair.rb
274
277
  - lib/nonnative/manual.rb
275
278
  - lib/nonnative/no_proxy.rb
279
+ - lib/nonnative/not_found_error.rb
276
280
  - lib/nonnative/observability.rb
277
281
  - lib/nonnative/pool.rb
278
282
  - lib/nonnative/port.rb
283
+ - lib/nonnative/process.rb
279
284
  - lib/nonnative/proxy.rb
280
285
  - lib/nonnative/proxy_factory.rb
286
+ - lib/nonnative/runner.rb
281
287
  - lib/nonnative/server.rb
282
288
  - lib/nonnative/service.rb
283
289
  - lib/nonnative/socket_pair.rb