Skip to content

Commit

Permalink
Switch to saver's new API (used in tests) and rename Model to Saver
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Aug 21, 2021
1 parent 947b06f commit ff3c75e
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 72 deletions.
6 changes: 3 additions & 3 deletions app/app_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def probe_compatible(name, result)
else
exception[:message] = error.message
end
diagnostic = json_pretty(info)
puts diagnostic
body diagnostic
diagnostic = JSON.pretty_generate(info)
puts(diagnostic)
body(diagnostic)
end

end
8 changes: 4 additions & 4 deletions app/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def diff_summary(id:, was_index:, now_index:)
private

def diff_plus(id, was_index, now_index, options)
was = model.kata_event(id, was_index.to_i)
now = model.kata_event(id, now_index.to_i)
was = saver.kata_event(id, was_index.to_i)
now = saver.kata_event(id, now_index.to_i)
was_files = files(was)
now_files = files(now)
diff_lines = GitDiffer.new(@externals).diff(id, was_files, now_files)
Expand Down Expand Up @@ -76,8 +76,8 @@ def same(lines)
end
end

def model
@externals.model
def saver
@externals.saver
end

end
4 changes: 2 additions & 2 deletions app/external/model.rb → app/external/saver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

module External

class Model
class Saver

def initialize(externals)
hostname = 'saver'
@port = ENV[port_env_var].to_i
@http = HttpJsonHash::service(self.class.name, externals.model_http, hostname, port)
@http = HttpJsonHash::service(self.class.name, externals.saver_http, hostname, port)
end

attr_reader :port
Expand Down
10 changes: 5 additions & 5 deletions app/externals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative 'external/disk_writer'
require_relative 'external/gitter'
require_relative 'external/http'
require_relative 'external/model'
require_relative 'external/saver'
require_relative 'external/sheller'

class Externals
Expand All @@ -21,11 +21,11 @@ def shell

# - - - - - - - - - - - - - - - - -

def model
@model ||= External::Model.new(self)
def saver
@saver ||= External::Saver.new(self)
end
def model_http
@model_http ||= External::Http.new
def saver_http
@saver_http ||= External::Http.new
end

end
2 changes: 1 addition & 1 deletion app/prober.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def alive
end

def ready
@externals.model.ready?
@externals.saver.ready?
end

end
3 changes: 1 addition & 2 deletions client/app/differ_service.rb → client/app/differ.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# frozen_string_literal: true
require_relative 'http_json_hash/service'

module External

class DifferService
class Differ

def initialize
hostname = 'differ_server'
Expand Down
12 changes: 3 additions & 9 deletions client/app/model_service.rb → client/app/saver.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# frozen_string_literal: true
require_relative 'http_json_hash/service'

module External

class ModelService
class Saver

def initialize
hostname = 'saver'
Expand All @@ -14,16 +13,11 @@ def initialize
# - - - - - - - - - - - - - - - - - - -

def kata_create(manifest)
@http.post(__method__, {
manifest:manifest,
options:{}
})
@http.post(__method__, { manifest:manifest })
end

def kata_manifest(id)
@http.get(__method__, {
id:id
})
@http.get(__method__, { id:id })
end

def kata_ran_tests(id, index, files, stdout, stderr, status, summary)
Expand Down
4 changes: 2 additions & 2 deletions client/config/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $stdout.sync = true
$stderr.sync = true

require_relative '../app/client'
require_relative '../app/differ_service'
require_relative '../app/differ'
require 'rack'

run Client.new(External::DifferService.new)
run Client.new(External::Differ.new)
4 changes: 2 additions & 2 deletions client/config/puma.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env puma

environment 'production'
rackup "#{__dir__}/config.ru"
environment('production')
rackup("#{__dir__}/config.ru")
10 changes: 5 additions & 5 deletions client/test/client_test_base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative 'lib/id58_test_base'
require_app 'differ_service'
require_app 'model_service'
require_app 'differ'
require_app 'saver'

class ClientTestBase < Id58TestBase

Expand All @@ -9,11 +9,11 @@ def initialize(arg)
end

def differ
@differ ||= External::DifferService.new
@differ ||= External::Differ.new
end

def model
@model ||= External::ModelService.new
def saver
@saver ||= External::Saver.new
end

end
6 changes: 3 additions & 3 deletions client/test/differ_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def assert_diff_summary(expected)
# - - - - - - - - - - - - - - - - - - - -

def run_diff_prepare
id = model.kata_create(starter_manifest)
id = saver.kata_create(starter_manifest)
kata_ran_tests(id, was_index=1, @old_files)
kata_ran_tests(id, now_index=2, @new_files)
[id, was_index, now_index]
Expand All @@ -756,7 +756,7 @@ def run_diff_prepare
# - - - - - - - - - - - - - - - - - - - -

def kata_ran_tests(id, index, files)
model.kata_ran_tests(
saver.kata_ran_tests(
id,
index,
plain(files),
Expand All @@ -780,7 +780,7 @@ def kata_ran_tests(id, index, files)
# - - - - - - - - - - - - - - - - - - - -

def starter_manifest
manifest = model.kata_manifest('5U2J18') # from test-data copied into saver
manifest = saver.kata_manifest('5U2J18') # from test-data copied into saver
%w( id created group_id group_index ).each {|key| manifest.delete(key) }
manifest
end
Expand Down
6 changes: 3 additions & 3 deletions client/test/lib/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

app: {
lines: {
total:125,
total:105,
missed:0,
},
branches: {
total:10,
total:8,
missed:0,
}
},

test: {
lines: {
total:300,
total:243,
missed:0,
},
branches: {
Expand Down
4 changes: 2 additions & 2 deletions config/puma.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env puma

environment 'production'
rackup "#{__dir__}/config.ru"
environment('production')
rackup("#{__dir__}/config.ru")
3 changes: 2 additions & 1 deletion scripts/test_in_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ run_tests()
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Tell caller where the results are...

echo "${TYPE} test branch-coverage report is at ${HOST_REPORTS_DIR}/index.html"
echo "${TYPE} test branch-coverage report is at"
echo "${HOST_REPORTS_DIR}/index.html"
echo "${TYPE} test status == ${STATUS}"
echo
if [ "${STATUS}" != 0 ]; then
Expand Down
6 changes: 3 additions & 3 deletions test/differ_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def diagnostic(type, expected, diff)
# - - - - - - - - - - - - - - - - - - - -

def run_diff_prepare
id = model.kata_create(starter_manifest)
id = saver.kata_create(starter_manifest)
kata_ran_tests(id, was_index=1, @was_files)
kata_ran_tests(id, now_index=2, @now_files)
[id, was_index, now_index]
Expand All @@ -295,15 +295,15 @@ def run_diff_prepare
# - - - - - - - - - - - - - - - - - - - -

def starter_manifest
manifest = model.kata_manifest('5U2J18') # from test-data copied into saver
manifest = saver.kata_manifest('5U2J18') # from test-data copied into saver
%w( id created group_id group_index ).each {|key| manifest.delete(key) }
manifest
end

# - - - - - - - - - - - - -

def kata_ran_tests(id, index, files)
model.kata_ran_tests(
saver.kata_ran_tests(
id,
index,
plain(files),
Expand Down
6 changes: 3 additions & 3 deletions test/differ_test_base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative 'lib/id58_test_base'
require_relative 'model_service'
require_relative 'saver'
require_app 'externals'
require_app 'differ'
require_app 'prober'
Expand All @@ -24,9 +24,9 @@ def prober
@prober ||= Prober.new(externals)
end

def model
def saver
# local because tests need more of model's API.
@model ||= ::Test::ModelService.new
@saver ||= ::Test::Saver.new
end

def disk
Expand Down
18 changes: 9 additions & 9 deletions test/http_proxy_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def self.id58_prefix
|which has a key matching the query-string (without the args)
|then it returns the value for that key in the JSON-Hash
) do
externals.instance_exec { @model_http = ::HttpAdapterStub.new('{"ready?":[42]}') }
model = ::External::Model.new(externals)
assert_equal [42], model.ready?
externals.instance_exec { @saver_http = ::HttpAdapterStub.new('{"ready?":[42]}') }
saver = ::External::Saver.new(externals)
assert_equal [42], saver.ready?
end

# - - - - - - - - - - - - - - - - -
Expand All @@ -28,7 +28,7 @@ def self.id58_prefix
|receives non-JSON in its response.body
|it raises an exception
) do
stub_model_http('xxxx')
stub_saver_http('xxxx')
ready_raises_exception('body is not JSON')
end

Expand All @@ -39,7 +39,7 @@ def self.id58_prefix
|receives JSON (but not a Hash) in its response.body
|it raises an exception
) do
stub_model_http('[]')
stub_saver_http('[]')
ready_raises_exception('body is not JSON Hash')
end

Expand All @@ -50,7 +50,7 @@ def self.id58_prefix
|receives JSON-Hash with an 'exception' key in its response.body
|it raises an exception
) do
stub_model_http(response='{"exception":42}')
stub_saver_http(response='{"exception":42}')
ready_raises_exception('body has embedded exception')
end

Expand All @@ -62,14 +62,14 @@ def self.id58_prefix
|which does not contain the requested method's key
|it raises an exception
) do
stub_model_http(response='{"wibble":42}')
stub_saver_http(response='{"wibble":42}')
ready_raises_exception('body is missing ready? key')
end

private

def stub_model_http(body)
externals.instance_exec { @model_http = HttpAdapterStub.new(body) }
def stub_saver_http(body)
externals.instance_exec { @saver_http = HttpAdapterStub.new(body) }
end

# - - - - - - - - - - - - - - - - -
Expand Down
6 changes: 3 additions & 3 deletions test/lib/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

app: {
lines: {
total:400,
total:360,
missed:0,
},
branches: {
total:60,
total:54,
missed:0,
}
},

test: {
lines: {
total:600,
total:527,
missed:0,
},
branches: {
Expand Down
4 changes: 2 additions & 2 deletions test/prober_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def self.id58_prefix
# - - - - - - - - - - - - - - - - -

test '604', %w(
|when model http-proxy is not ready
|when saver http-proxy is not ready
|then ready? is false
) do
externals.instance_exec { @model=STUB_READY_FALSE }
externals.instance_exec { @saver=STUB_READY_FALSE }
assert false?(prober.ready)
end

Expand Down
11 changes: 3 additions & 8 deletions test/model_service.rb → test/saver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module Test

class ModelService
class Saver

def initialize
hostname = 'saver'
Expand All @@ -12,16 +12,11 @@ def initialize
end

def kata_create(manifest)
@http.post(__method__, {
manifest:manifest,
options:{}
})
@http.post(__method__, { manifest:manifest })
end

def kata_manifest(id)
@http.get(__method__, {
id:id
})
@http.get(__method__, { id:id })
end

def kata_ran_tests(id, index, files, stdout, stderr, status, summary)
Expand Down

0 comments on commit ff3c75e

Please sign in to comment.