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 Base API, by writing their own test orchestration provider from scratch instead of extending OrchestrationProvider.

However, implementors who are trying to produce 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 configuration service.

Instance Method Summary collapse

Constructor Details

#initialize(provider_class) ⇒ Orchestrator

Returns a new instance of Orchestrator.

Parameters:

  • provider_class (Class)

    the test orchestration provider class, which should have a default/nullary constructor



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.

Parameters:



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

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

#bootstrap_configuration_service_environmentallyObject

TODO:

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.



256
257
258
259
# File 'lib/configuration_service/test/orchestrator.rb', line 256

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

#bootstrapped_configuration_service_functional?Boolean

TODO:

replace with declarative test that delegates to orchestration provider

Tests that a bootstrapped configuration service is functional

Returns:

  • (Boolean)


266
267
268
269
270
271
272
273
# File 'lib/configuration_service/test/orchestrator.rb', line 266

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.



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

def deauthorize
  @provider.deauthorize
end

#environmental_service_configuration_scrubbed?Boolean

TODO:

replace with declarative test that delegates to orchestration provider

Tests that environmental service configuration is scrubbed

Returns:

  • (Boolean)


280
281
282
# File 'lib/configuration_service/test/orchestrator.rb', line 280

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

#existing_configurationObject

TODO:

replace with predicate: this exposes domain state

Return a published configuration fixture

E.g. as arranged by #given_existing_configuration.



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

def existing_configuration
  @provider.existing_configuration
end

#existing_revisionObject

TODO:

replace with predicate: this exposes domain state

Return the revision of a published configuration fixture

E.g. as arranged by #given_existing_configuration.



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

def existing_revision
  @provider.existing_revision
end

#given_environmental_service_configurationObject

TODO:

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.



236
237
238
239
240
241
242
243
244
245
246
# File 'lib/configuration_service/test/orchestrator.rb', line 236

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



217
218
219
# File 'lib/configuration_service/test/orchestrator.rb', line 217

def given_publication_failure
  @provider.fail_next_request
end

#given_request_failureObject

Arrange for the next consuming operation to fail



224
225
226
# File 'lib/configuration_service/test/orchestrator.rb', line 224

def given_request_failure
  @provider.fail_next_request
end

#publish_configurationObject

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.



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

def publish_configuration
  @response = @provider.publish_configuration
end

#published_configurationHash Also known as: requested_configuration

TODO:

replace with predicate: this exposes domain state

The last published or consumed configuration data

Returns:



187
188
189
# File 'lib/configuration_service/test/orchestrator.rb', line 187

def published_configuration
  @response.data
end

#published_metadataHash

TODO:

replace with predicate: this exposes domain state

The last published metadata

Returns:

  • (Hash)

    configuration metadata



210
211
212
# File 'lib/configuration_service/test/orchestrator.rb', line 210

def 
  @response.
end

#published_revisionString

TODO:

replace with predicate: this exposes domain state

The revision of the last published or consumed configuration metadata

Returns:

  • (String)

    metadata revision



199
200
201
# File 'lib/configuration_service/test/orchestrator.rb', line 199

def published_revision
  @response.revision
end

#request_allowed?Boolean

Whether the last publish or request was allowed



144
145
146
# File 'lib/configuration_service/test/orchestrator.rb', line 144

def request_allowed?
  @response.allowed?
end

#request_configurationObject

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.



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

def request_configuration
  @response = @provider.request_configuration
end

#request_failed?Boolean

Whether the last publish or request was allowed but failed



154
155
156
# File 'lib/configuration_service/test/orchestrator.rb', line 154

def request_failed?
  @response.failed?
end

#request_not_found?Boolean

True if the last request not return configuration data

Returns:

  • (Boolean)

See Also:



164
165
166
# File 'lib/configuration_service/test/orchestrator.rb', line 164

def request_not_found?
  not @response.found?
end

#request_not_matched?Boolean

TODO:

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

Returns:

  • (Boolean)

See Also:



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

def request_not_matched?
  not @response.found?
end