Class: ConfigurationService::Test::Orchestrator
- Inherits:
-
Object
- Object
- ConfigurationService::Test::Orchestrator
- Defined in:
- lib/configuration_service/test/orchestrator.rb
Overview
The declarative test orchestration API
This is the declarative API that describes what must be done to test a configuration service provider. It catalogues all the services that the cucumber step definitions expect from a test orchestration provider.
It keeps no domain state, because that would couple it to the service implementation. By making no assumptions at all about the API or data, it allows implementors to produce service implementations that do not adhere to the anticipated Client API, by writing their own test orchestration provider from scratch instead of extending OrchestrationProvider.
However, implementors who are trying to produce Client providers should extend OrchestrationProvider, which anticipates a compatible provider API.
Note that the @response instance variable is not domain state; it is a test artifact (Response or similar) that orchestration providers use to wrap responses from the configuration service.
Instance Method Summary collapse
-
#authorize(activity) ⇒ Object
Authorize the next publish or request activity.
-
#authorize_consumption ⇒ Object
Get credentials to consume a configuration.
-
#bootstrap_configuration_service_environmentally ⇒ Object
Bootstrap a configuration service environmentally.
-
#bootstrapped_configuration_service_functional? ⇒ Boolean
Tests that a bootstrapped configuration service is functional.
-
#configuration_found_for_identifier? ⇒ Boolean
Configuration for the requested identifier was found.
- #credentials_allow_consumption? ⇒ Boolean
- #credentials_allow_publication? ⇒ Boolean
- #credentials_allow_reference_consumption? ⇒ Boolean
- #credentials_allow_reference_publication? ⇒ Boolean
-
#deauthorize ⇒ Object
Remove any previous authorization.
-
#environmental_service_configuration_scrubbed? ⇒ Boolean
Tests that environmental service configuration is scrubbed.
-
#existing_revision ⇒ Object
Return the revision of a published configuration fixture.
- #given_configuration_should_be_resolved ⇒ Object
-
#given_environmental_service_configuration ⇒ Object
Arrange environmental service configuration.
-
#given_existing_configuration ⇒ Object
Arrange a published configuration fixture.
- #given_existing_configuration_containing_references ⇒ Object
-
#given_invalid_configuration ⇒ Object
Use invalid configuration data in the next publishing operation.
-
#given_metadata ⇒ Object
Include metadata in the next publishing operation.
-
#given_missing_configuration ⇒ Object
Delete any existing configuration.
-
#given_publication_failure ⇒ Object
Arrange for the next publication operation to fail.
- #given_referenced_configuration_exists ⇒ Object
-
#given_request_failure ⇒ Object
Arrange for the next consuming operation to fail.
-
#initialize(provider_class) ⇒ Orchestrator
constructor
A new instance of Orchestrator.
-
#publish_configuration ⇒ Object
Publish configuration through the service under test.
-
#published_configuration ⇒ Hash
(also: #requested_configuration)
The last published or consumed configuration data.
-
#published_metadata ⇒ Hash
The last published metadata.
-
#published_revision ⇒ String
The revision of the last published or consumed configuration metadata.
- #references_replaced_with_configuration_data? ⇒ Boolean
-
#request_allowed? ⇒ Boolean
Whether the last publish or request was allowed.
-
#request_configuration ⇒ Object
Request configuration from the service under test.
-
#request_failed? ⇒ Boolean
Whether the last publish or request was allowed but failed.
-
#request_not_found? ⇒ Boolean
True if the last request not return configuration data.
-
#request_not_matched? ⇒ Boolean
True if the last request did consuming operation did not return data.
- #requests_allowed? ⇒ Boolean
Constructor Details
#initialize(provider_class) ⇒ Orchestrator
Returns a new instance of Orchestrator.
36 37 38 |
# File 'lib/configuration_service/test/orchestrator.rb', line 36 def initialize(provider_class) @provider = provider_class.new end |
Instance Method Details
#authorize(activity) ⇒ Object
Authorize the next publish or request activity
Where possible, the test orchestration provider should authorize :nothing
by providing valid credentials that don’t allow operations on the configuration identifier
that it tests against.
105 106 107 108 |
# File 'lib/configuration_service/test/orchestrator.rb', line 105 def (activity) role = role_for(activity) or raise "unknown authorizable activity #{activity.inspect}" @provider.(role) end |
#authorize_consumption ⇒ Object
Get credentials to consume a configuration
142 143 144 |
# File 'lib/configuration_service/test/orchestrator.rb', line 142 def @provider. end |
#bootstrap_configuration_service_environmentally ⇒ Object
replace with declarative test that delegates to orchestration provider
Bootstrap a configuration service environmentally
Environmental service configuration (as arranged by #given_environmental_service_configuration) is given to an Factory::EnvironmentContext factory to create a service configuration instance.
303 304 305 306 |
# File 'lib/configuration_service/test/orchestrator.rb', line 303 def bootstrap_configuration_service_environmentally context = ConfigurationService::Factory::EnvironmentContext.new(@env, "CFGSRV") @service = ConfigurationService::Factory.create_client(context) end |
#bootstrapped_configuration_service_functional? ⇒ Boolean
replace with declarative test that delegates to orchestration provider
Tests that a bootstrapped configuration service is functional
313 314 315 316 317 318 319 320 |
# File 'lib/configuration_service/test/orchestrator.rb', line 313 def bootstrapped_configuration_service_functional? response = begin ConfigurationService::Test::Response::Success.new(@service.request_configuration(identifier: 'test')) rescue ConfigurationService::Error => e ConfigurationService::Test::Response::Failure.new(e) end !response.failed? end |
#configuration_found_for_identifier? ⇒ Boolean
Configuration for the requested identifier was found
The test orchestration provider should verify that the returned configuration is for the requested identifier.
171 172 173 |
# File 'lib/configuration_service/test/orchestrator.rb', line 171 def configuration_found_for_identifier? @provider.configuration_found_for_identifier? end |
#credentials_allow_consumption? ⇒ Boolean
146 147 148 149 |
# File 'lib/configuration_service/test/orchestrator.rb', line 146 def credentials_allow_consumption? @response = @provider.credentials_allow_consumption? request_allowed? end |
#credentials_allow_publication? ⇒ Boolean
151 152 153 154 |
# File 'lib/configuration_service/test/orchestrator.rb', line 151 def credentials_allow_publication? @response = @provider.credentials_allow_publication? request_allowed? end |
#credentials_allow_reference_consumption? ⇒ Boolean
156 157 158 159 |
# File 'lib/configuration_service/test/orchestrator.rb', line 156 def credentials_allow_reference_consumption? @responses = @provider.credentials_allow_reference_consumption? requests_allowed? end |
#credentials_allow_reference_publication? ⇒ Boolean
161 162 163 164 |
# File 'lib/configuration_service/test/orchestrator.rb', line 161 def credentials_allow_reference_publication? @responses = @provider.credentials_allow_reference_publication? requests_allowed? end |
#deauthorize ⇒ Object
Remove any previous authorization
E.g. as arranged by #authorize.
115 116 117 |
# File 'lib/configuration_service/test/orchestrator.rb', line 115 def @provider. end |
#environmental_service_configuration_scrubbed? ⇒ Boolean
replace with declarative test that delegates to orchestration provider
Tests that environmental service configuration is scrubbed
327 328 329 |
# File 'lib/configuration_service/test/orchestrator.rb', line 327 def environmental_service_configuration_scrubbed? !@env.include?("CFGSRV_TOKEN") end |
#existing_revision ⇒ Object
replace with predicate: this exposes domain state
Return the revision of a published configuration fixture
E.g. as arranged by #given_existing_configuration.
87 88 89 |
# File 'lib/configuration_service/test/orchestrator.rb', line 87 def existing_revision @provider.existing_revision end |
#given_configuration_should_be_resolved ⇒ Object
58 59 60 |
# File 'lib/configuration_service/test/orchestrator.rb', line 58 def given_configuration_should_be_resolved @provider.given_configuration_should_be_resolved end |
#given_environmental_service_configuration ⇒ Object
replace with declarative test that delegates to orchestration provider
Arrange environmental service configuration
Environmental service configuration is configuration for bootstrapping a configuration service and provider.
283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/configuration_service/test/orchestrator.rb', line 283 def given_environmental_service_configuration sp_env = @provider.service_provider_configuration.inject({}) do |m, (k, v)| m["CFGSRV_PROVIDER_#{k.to_s.upcase}"] = v m end @env = { "CFGSRV_IDENTIFIER" => "acme", "CFGSRV_TOKEN" => "ea81cbfb-221c-41ad-826e-d3eff6342345", "CFGSRV_PROVIDER" => @provider.service_provider_id, }.merge(sp_env) end |
#given_existing_configuration ⇒ Object
Arrange a published configuration fixture
50 51 52 |
# File 'lib/configuration_service/test/orchestrator.rb', line 50 def given_existing_configuration @provider.given_existing_configuration end |
#given_existing_configuration_containing_references ⇒ Object
54 55 56 |
# File 'lib/configuration_service/test/orchestrator.rb', line 54 def given_existing_configuration_containing_references @provider.given_existing_configuration_containing_references end |
#given_invalid_configuration ⇒ Object
Use invalid configuration data in the next publishing operation
69 70 71 |
# File 'lib/configuration_service/test/orchestrator.rb', line 69 def given_invalid_configuration @provider.given_invalid_configuration end |
#given_metadata ⇒ Object
Include metadata in the next publishing operation
43 44 45 |
# File 'lib/configuration_service/test/orchestrator.rb', line 43 def @provider. end |
#given_missing_configuration ⇒ Object
Delete any existing configuration
76 77 78 |
# File 'lib/configuration_service/test/orchestrator.rb', line 76 def given_missing_configuration @provider.given_missing_configuration end |
#given_publication_failure ⇒ Object
Arrange for the next publication operation to fail
264 265 266 |
# File 'lib/configuration_service/test/orchestrator.rb', line 264 def given_publication_failure @provider.fail_next_request end |
#given_referenced_configuration_exists ⇒ Object
62 63 64 |
# File 'lib/configuration_service/test/orchestrator.rb', line 62 def given_referenced_configuration_exists @provider.given_referenced_configuration_exists end |
#given_request_failure ⇒ Object
Arrange for the next consuming operation to fail
271 272 273 |
# File 'lib/configuration_service/test/orchestrator.rb', line 271 def given_request_failure @provider.fail_next_request end |
#publish_configuration ⇒ Object
Publish configuration through the service under test
The test orchestration provider is expected to wrap the response in a Response (or simimlar) and return that.
135 136 137 |
# File 'lib/configuration_service/test/orchestrator.rb', line 135 def publish_configuration @response = @provider.publish_configuration end |
#published_configuration ⇒ Hash Also known as: requested_configuration
replace with predicate: this exposes domain state
The last published or consumed configuration data
234 235 236 |
# File 'lib/configuration_service/test/orchestrator.rb', line 234 def published_configuration @response.data end |
#published_metadata ⇒ Hash
replace with predicate: this exposes domain state
The last published metadata
257 258 259 |
# File 'lib/configuration_service/test/orchestrator.rb', line 257 def @response. end |
#published_revision ⇒ String
replace with predicate: this exposes domain state
The revision of the last published or consumed configuration metadata
246 247 248 |
# File 'lib/configuration_service/test/orchestrator.rb', line 246 def published_revision @response.revision end |
#references_replaced_with_configuration_data? ⇒ Boolean
175 176 177 |
# File 'lib/configuration_service/test/orchestrator.rb', line 175 def references_replaced_with_configuration_data? @provider.references_replaced_with_configuration_data? end |
#request_allowed? ⇒ Boolean
Whether the last publish or request was allowed
185 186 187 |
# File 'lib/configuration_service/test/orchestrator.rb', line 185 def request_allowed? @response.allowed? end |
#request_configuration ⇒ Object
Request configuration from the service under test
The test orchestration provider is expected to wrap the response in a Response (or simimlar) and return that.
125 126 127 |
# File 'lib/configuration_service/test/orchestrator.rb', line 125 def request_configuration @response = @provider.request_configuration end |
#request_failed? ⇒ Boolean
Whether the last publish or request was allowed but failed
201 202 203 |
# File 'lib/configuration_service/test/orchestrator.rb', line 201 def request_failed? @response.failed? end |
#request_not_found? ⇒ Boolean
True if the last request not return configuration data
211 212 213 |
# File 'lib/configuration_service/test/orchestrator.rb', line 211 def request_not_found? not @response.found? end |
#request_not_matched? ⇒ Boolean
distinguish #request_not_matched? to mean “found data, but filtered out by metadata filter”
True if the last request did consuming operation did not return data
223 224 225 |
# File 'lib/configuration_service/test/orchestrator.rb', line 223 def request_not_matched? not @response.found? end |
#requests_allowed? ⇒ Boolean
189 190 191 192 193 |
# File 'lib/configuration_service/test/orchestrator.rb', line 189 def requests_allowed? @responses.all? { |response| response.allowed? } end |