Class: ConfigurationService::Test::Orchestrator

Inherits:
Object
  • Object
show all
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 ConfigurationService::Base API, by writing their own OrchestrationProvider from scratch.

However, implementors who are trying to produce ConfigurationService::Base 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 service provider.

Instance Method Summary collapse

Constructor Details

#initialize(provider_class) ⇒ Orchestrator

Return a new orchestrator initialized with a new instance of provider_class.

The provider is expected to use a consistent configuration identifier for all publishing and consuming operations.



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 consuming or publishing operation for activity

Valid activities (as per ACTIVITY_ROLE_MAP in ConfigurationService::Test::OrchestrationProvider) are:

  • :requesting_configurations

  • :publishing_configurations

  • :nothing

Where possible, the orchestration provider should authorize :nothing by providing valid credentials that don’t allow operations on the configuration identifier that it tests against.



103
104
105
106
# File 'lib/configuration_service/test/orchestrator.rb', line 103

def authorize(activity)
  role = role_for(activity) or raise "unknown authorizable activity #{activity.inspect}"
  @provider.authorize(role)
end

#bootstrap_configuration_service_environmentallyObject

Bootstrap a configuration service environmentally

Environmental service configuration (as arranged by #given_environmental_service_configuration) is given to an EnvironmentContext factory to create a service configuration instance.

TODO This method is imperative



237
238
239
240
# File 'lib/configuration_service/test/orchestrator.rb', line 237

def bootstrap_configuration_service_environmentally
  factory = ConfigurationService::Factory::EnvironmentContext.new(@env, "CFGSRV")
  @service = factory.create
end

#bootstrapped_configuration_service_functional?Boolean

Tests that a bootstrapped configuration service is functional

TODO This method is imperative

Returns:

  • (Boolean)


247
248
249
250
251
252
253
254
# File 'lib/configuration_service/test/orchestrator.rb', line 247

def bootstrapped_configuration_service_functional?
  response = begin
    ConfigurationService::Test::Response::Success.new(@service.request_configuration)
  rescue ConfigurationService::Error => e
    ConfigurationService::Test::Response::Failure.new(e)
  end
  !response.failed?
end

#deauthorizeObject

Remove any previous authorization

E.g. as arranged by #authorize.



113
114
115
# File 'lib/configuration_service/test/orchestrator.rb', line 113

def deauthorize
  @provider.deauthorize
end

#environmental_service_configuration_scrubbed?Boolean

Tests that environmental service configuration is scrubbed

TODO This method is imperative

Returns:

  • (Boolean)


261
262
263
# File 'lib/configuration_service/test/orchestrator.rb', line 261

def environmental_service_configuration_scrubbed?
  !@env.include?("CFGSRV_TOKEN")
end

#existing_configurationObject

Return a published configuration fixture

E.g. as arranged by #given_existing_configuration.

TODO remove; step definitions expect this to be Comparable



75
76
77
# File 'lib/configuration_service/test/orchestrator.rb', line 75

def existing_configuration
  @provider.existing_configuration
end

#existing_revisionObject

Return the revision of a published configuration fixture

E.g. as arranged by #given_existing_configuration.

TODO remove; step definitions expect this to be Comparable



86
87
88
# File 'lib/configuration_service/test/orchestrator.rb', line 86

def existing_revision
  @provider.existing_revision
end

#given_environmental_service_configurationObject

Arrange environmental service configuration

Environmental service configuration is configuration for bootstrapping a configuration service and provider.

TODO This method is imperative



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/configuration_service/test/orchestrator.rb', line 216

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_configurationObject

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_invalid_configurationObject

Use invalid configuration data in the next publishing operation



57
58
59
# File 'lib/configuration_service/test/orchestrator.rb', line 57

def given_invalid_configuration
  @provider.given_invalid_configuration
end

#given_metadataObject

Include metadata in the next publishing operation



43
44
45
# File 'lib/configuration_service/test/orchestrator.rb', line 43

def 
  @provider.
end

#given_missing_configurationObject

Delete any existing configuration



64
65
66
# File 'lib/configuration_service/test/orchestrator.rb', line 64

def given_missing_configuration
  @provider.given_missing_configuration
end

#given_publication_failureObject

Arrange for the next publication operation to fail



197
198
199
# File 'lib/configuration_service/test/orchestrator.rb', line 197

def given_publication_failure
  @provider.fail_next_request
end

#given_request_failureObject

Arrange for the next consuming operation to fail



204
205
206
# File 'lib/configuration_service/test/orchestrator.rb', line 204

def given_request_failure
  @provider.fail_next_request
end

#publish_configurationObject

Perform a publishing operation against the service under test

The provider is expected to wrap the response in a Response (or simimlar) and return that.



133
134
135
# File 'lib/configuration_service/test/orchestrator.rb', line 133

def publish_configuration
  @response = @provider.publish_configuration
end

#published_configurationObject Also known as: requested_configuration

The last published or consumed configuration data

Note that this is the data itself, not a Configuration object.



175
176
177
# File 'lib/configuration_service/test/orchestrator.rb', line 175

def published_configuration
  @response.data
end

#published_metadataObject

The last published metadata



190
191
192
# File 'lib/configuration_service/test/orchestrator.rb', line 190

def 
  @response.
end

#published_revisionObject

The revision of the last published or consumed configuration



183
184
185
# File 'lib/configuration_service/test/orchestrator.rb', line 183

def published_revision
  @response.revision
end

#request_allowed?Boolean

True if the last consuming or publishing operation was allowed

Returns:

  • (Boolean)


140
141
142
# File 'lib/configuration_service/test/orchestrator.rb', line 140

def request_allowed?
  @response.allowed?
end

#request_configurationObject

Perform a consuming operation against the service under test

The provider is expected to wrap the response in a Response (or simimlar) and return that.



123
124
125
# File 'lib/configuration_service/test/orchestrator.rb', line 123

def request_configuration
  @response = @provider.request_configuration
end

#request_failed?Boolean

True if the last consuming or publishing operation failed

Operations that were not allowed (as per #request_allowed?) or considered failed.

Returns:

  • (Boolean)


150
151
152
# File 'lib/configuration_service/test/orchestrator.rb', line 150

def request_failed?
  @response.failed?
end

#request_not_found?Boolean

True if the last consuming operation did not return data

Returns:

  • (Boolean)


157
158
159
# File 'lib/configuration_service/test/orchestrator.rb', line 157

def request_not_found?
  not @response.found?
end

#request_not_matched?Boolean

True if the last consuming operation did not return data

TODO: distinguish #request_not_matched? to mean “found data, but filtered out by metadata filter”

Returns:

  • (Boolean)


166
167
168
# File 'lib/configuration_service/test/orchestrator.rb', line 166

def request_not_matched?
  not @response.found?
end