Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deps): add config (5.0.0) #279

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AllCops:
Exclude:
- 'bin/**/*'
- 'vendor/**/*'
- 'test/grpc/**/*'

Layout/LineLength:
Max: 150
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ gemspec
gem 'bundler'
gem 'coveralls_reborn'
gem 'rubocop'
gem 'solargraph'
87 changes: 49 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
nonnative (1.74.1)
nonnative (1.75.0)
concurrent-ruby (~> 1.0, >= 1.0.5)
config (~> 5.0)
cucumber (>= 7, < 10)
get_process_mem (~> 0.2.1)
grpc (>= 1, < 2)
Expand All @@ -16,13 +17,14 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
backport (1.2.0)
benchmark (0.3.0)
benchmark-malloc (0.2.0)
benchmark-perf (0.6.0)
benchmark-trend (0.4.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
config (5.0.0)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
coveralls_reborn (0.28.0)
simplecov (~> 0.22.0)
term-ansicolor (~> 1.7)
Expand Down Expand Up @@ -52,28 +54,63 @@ GEM
cucumber-messages (>= 18.0, < 22.1)
cucumber-messages (22.0.0)
cucumber-tag-expressions (5.0.6)
deep_merge (1.2.2)
diff-lcs (1.5.0)
docile (1.4.0)
domain_name (0.6.20231109)
e2mmap (0.1.0)
dry-configurable (1.1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-core (1.0.1)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
dry-inflector (1.0.0)
dry-initializer (3.1.1)
dry-logic (1.5.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-schema (1.13.3)
concurrent-ruby (~> 1.0)
dry-configurable (~> 1.0, >= 1.0.1)
dry-core (~> 1.0, < 2)
dry-initializer (~> 3.0)
dry-logic (>= 1.4, < 2)
dry-types (>= 1.7, < 2)
zeitwerk (~> 2.6)
dry-types (1.7.1)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0)
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
dry-validation (1.10.0)
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
dry-initializer (~> 3.0)
dry-schema (>= 1.12, < 2)
zeitwerk (~> 2.6)
ffi (1.16.3)
get_process_mem (0.2.7)
ffi (~> 1.0)
google-protobuf (3.25.0-x86_64-darwin)
google-protobuf (3.25.1-arm64-darwin)
google-protobuf (3.25.1-x86_64-darwin)
google-protobuf (3.25.1-x86_64-linux)
googleapis-common-protos-types (1.10.0)
google-protobuf (~> 3.18)
grpc (1.59.2)
google-protobuf (~> 3.24)
googleapis-common-protos-types (~> 1.0)
grpc (1.59.2-x86_64-darwin)
google-protobuf (~> 3.24)
googleapis-common-protos-types (~> 1.0)
grpc (1.59.2-x86_64-linux)
google-protobuf (~> 3.24)
googleapis-common-protos-types (~> 1.0)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
jaro_winkler (1.5.6)
json (2.6.3)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
mime-types (3.5.1)
mime-types-data (~> 3.2015)
Expand All @@ -83,13 +120,7 @@ GEM
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
netrc (0.11.0)
nio4r (2.5.9)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
nio4r (2.6.0)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
Expand All @@ -101,15 +132,12 @@ GEM
rack-protection (3.1.0)
rack (~> 2.2, >= 2.2.4)
rainbow (3.1.1)
rbs (2.8.4)
regexp_parser (2.8.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down Expand Up @@ -155,22 +183,6 @@ GEM
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.1.0)
tilt (~> 2.0)
solargraph (0.49.0)
backport (~> 1.2)
benchmark
bundler (~> 2.0)
diff-lcs (~> 1.4)
e2mmap
jaro_winkler (~> 1.5)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
parser (~> 3.0)
rbs (~> 2.0)
reverse_markdown (~> 2.0)
rubocop (~> 1.38)
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
sync (0.5.0)
sys-uname (1.2.3)
ffi (~> 1.1)
Expand All @@ -181,7 +193,7 @@ GEM
tins (1.32.1)
sync
unicode-display_width (2.5.0)
yard (0.9.34)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-22
Expand All @@ -193,7 +205,6 @@ DEPENDENCIES
coveralls_reborn
nonnative!
rubocop
solargraph

BUNDLED WITH
2.3.9
2 changes: 1 addition & 1 deletion features/step_definitions/servers_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
urls = ['localhost:9002', 'localhost:9003']

urls.each do |u|
stub = Nonnative::Features::GreeterService::Stub.new(u, :this_channel_is_insecure)
stub = Nonnative::Features::GreeterService::Stub.new(u, :this_channel_is_insecure, channel_args: Nonnative::Header.grpc_user_agent('test 1.0'))

@responses << stub.say_hello(Nonnative::Features::SayHelloRequest.new(name: 'Hello World!'))
end
Expand Down
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(formatters)
SimpleCov.start do
add_filter '/features/'
add_filter '/test/'
coverage_dir 'reports'
end

Expand Down
12 changes: 9 additions & 3 deletions features/support/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ module Nonnative
module Features
class HTTPClient < Nonnative::HTTPClient
def hello_get
get('hello', { headers: { content_type: :json, accept: :json }, read_timeout: 1, open_timeout: 1 })
headers = Nonnative::Header.http_user_agent('test 1.0').merge({ content_type: :json, accept: :json })

get('hello', { headers:, read_timeout: 1, open_timeout: 1 })
end

def hello_post
post('hello', 'Hello World!', { headers: { content_type: :json, accept: :json }, read_timeout: 1, open_timeout: 1 })
headers = Nonnative::Header.auth_basic('test:test').merge({ content_type: :json, accept: :json })

post('hello', 'Hello World!', { headers:, read_timeout: 1, open_timeout: 1 })
end

def hello_put
put('hello', 'Hello World!', { headers: { content_type: :json, accept: :json }, read_timeout: 1, open_timeout: 1 })
headers = Nonnative::Header.auth_bearer('token').merge({ content_type: :json, accept: :json })

put('hello', 'Hello World!', { headers:, read_timeout: 1, open_timeout: 1 })
end

def hello_delete
Expand Down
6 changes: 6 additions & 0 deletions lib/nonnative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'puma'
require 'puma/server'
require 'concurrent'
require 'config'
require 'cucumber'
require 'get_process_mem'
require 'rspec-benchmark'
Expand Down Expand Up @@ -49,11 +50,16 @@
require 'nonnative/socket_pair_factory'
require 'nonnative/go_command'
require 'nonnative/cucumber'
require 'nonnative/header'

module Nonnative
class << self
attr_reader :pool

def configurations(*files)
Config.load_files(files)
end

def log_lines(path, predicate)
File.readlines(path).select { |l| predicate.call(l) }
end
Expand Down
74 changes: 37 additions & 37 deletions lib/nonnative/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def initialize
attr_accessor :processes, :servers, :services

def load_file(path)
file = YAML.load_file(path)
cfg = Nonnative.configurations(path)

add_processes(file)
add_servers(file)
add_services(file)
add_processes(cfg)
add_servers(cfg)
add_services(cfg)
end

def process
Expand Down Expand Up @@ -48,59 +48,59 @@ def process_by_name(name)

private

def add_processes(file)
processes = file['processes'] || []
def add_processes(cfg)
processes = cfg.processes || []
processes.each do |fd|
process do |d|
d.name = fd['name']
d.name = fd.name
d.command = command(fd)
d.timeout = fd['timeout']
d.port = fd['port']
d.log = fd['log']
d.signal = fd['signal']
d.environment = fd['environment']
d.timeout = fd.timeout
d.port = fd.port
d.log = fd.log
d.signal = fd.signal
d.environment = fd.environment

proxy d, fd['proxy']
proxy d, fd.proxy
end
end
end

def command(process)
go = process['go']
go = process.go
if go
params = go['parameters'] || []
tools = go['tools'] || []
params = go.parameters || []
tools = go.tools || []

-> { Nonnative.go_executable(tools, go['output'], go['executable'], go['command'], *params) }
-> { Nonnative.go_executable(tools, go.output, go.executable, go.command, *params) }
else
-> { process['command'] }
-> { process.command }
end
end

def add_servers(file)
servers = file['servers'] || []
def add_servers(cfg)
servers = cfg.servers || []
servers.each do |fd|
server do |s|
s.name = fd['name']
s.klass = Object.const_get(fd['class'])
s.timeout = fd['timeout']
s.port = fd['port']
s.log = fd['log']
s.name = fd.name
s.klass = Object.const_get(fd.class)
s.timeout = fd.timeout
s.port = fd.port
s.log = fd.log

proxy s, fd['proxy']
proxy s, fd.proxy
end
end
end

def add_services(file)
services = file['services'] || []
def add_services(cfg)
services = cfg.services || []
services.each do |fd|
service do |s|
s.name = fd['name']
s.host = fd['host'] if fd['host']
s.port = fd['port']
s.name = fd.name
s.host = fd.host if fd.host
s.port = fd.port

proxy s, fd['proxy']
proxy s, fd.proxy
end
end
end
Expand All @@ -109,13 +109,13 @@ def proxy(runner, proxy)
return unless proxy

p = {
kind: proxy['kind'],
port: proxy['port'],
log: proxy['log'],
options: proxy['options']
kind: proxy.kind,
port: proxy.port,
log: proxy.log,
options: proxy.options
}

p[:host] = proxy['host'] if proxy['host']
p[:host] = proxy.host if proxy.host

runner.proxy = p
end
Expand Down
23 changes: 23 additions & 0 deletions lib/nonnative/header.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Nonnative
class Header
class << self
def http_user_agent(user_agent)
{ user_agent: }
end

def grpc_user_agent(user_agent)
{ 'grpc.primary_user_agent' => user_agent }
end

def auth_basic(credentials)
{ authorization: "Basic #{Base64.strict_encode64(credentials)}" }
end

def auth_bearer(token)
{ authorization: "Bearer #{token}" }
end
end
end
end
Loading