Skip to content

Commit

Permalink
Smoke tests v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Oct 2, 2023
1 parent 8eaf403 commit c509638
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 166 deletions.
39 changes: 39 additions & 0 deletions apis/acm/2015-12-08/smoke-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": 2,
"testCases": [
{
"id": "FailureExample",
"operationName": "TestOperation",
"input": {
"message": "foo"
},
"expectation": {"failure": {}},
"config": {
"region": "moon-dark-1"
},
"tags": ["connection"]
},
{
"id": "ErrorExample",
"operationName": "TestOperation",
"input": {
"message": "föö"
},
"expectation": {"failure": {"errorId": "InvalidMessageError"}},
"config": {
"region": "eu-central-1"
}
},
{
"id": "SuccessExample",
"operationName": "TestOperation",
"input": {
"message": "bar"
},
"expectation": {"success": {}},
"config": {
"region": "eu-central-1"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
require_relative 'aws-sdk-code-generator/views/errors_module'
require_relative 'aws-sdk-code-generator/views/features/env'
require_relative 'aws-sdk-code-generator/views/features/step_definitions'
require_relative 'aws-sdk-code-generator/views/features/smoke_step_definitions'
require_relative 'aws-sdk-code-generator/views/features/smoke'
require_relative 'aws-sdk-code-generator/views/gemspec'
require_relative 'aws-sdk-code-generator/views/resource_class'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def each(&block)
y.yield('features/step_definitions.rb', features_step_definitions_file)
if @service.smoke_tests
y.yield('features/smoke.feature', smoke_file)
y.yield('features/smoke_step_definitions.rb', smoke_step_definitions_file)
end
y.yield('VERSION', version_file)
y.yield('LICENSE.txt', license_file)
Expand Down Expand Up @@ -54,10 +53,6 @@ def smoke_file
Views::Features::Smoke.new(options).render
end

def smoke_step_definitions_file
Views::Features::SmokeStepDefinitions.new(options).render
end

def features_step_definitions_file
Views::Features::StepDefinitions.new(options).render
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,109 @@ class Smoke < View
def initialize(options)
service = options.fetch(:service)
@custom = service.protocol == 'api-gateway'
@service = service.name
@service_name = service.name
@service_module = service.module_name

# This will only be called if this is defined
smoke_json = service.smoke_tests
@client_region = smoke_json["defaultRegion"]
@client_endpoint = smoke_json["defaultEndpoint"]
@smoke_tests = smoke_json["testCases"].map do |test|
h = {
operation: underscore(test["operationName"]),
smoke_test_tags: "@#{service.identifier} @smoke",
}
if test["errorExpectedFromService"]
h[:error_expectation] = "I expect an error was raised"
h[:scenario_string] = "Call Aws::#{service.module_name}::Client##{h[:operation]} and expect it to fail"
else
h[:error_expectation] = "I expect an error was not raised"
h[:scenario_string] = "Call #{service.module_name}::Client##{h[:operation]} and expect it to succeed"
end
h[:param_hash] = test["input"].inject({}) do |acc, kv|
raw_key, value = kv
key = underscore(raw_key)
acc[key] = value
acc
end.to_json
h
@smoke_tests = smoke_json['testCases'].map do |test|
SmokeTest.new(
service: service,
id: test['id'],
operation_name: test['operationName'],
input: test['input'],
expectation: test['expectation'],
config: test['config'],
tags: test['tags']
)
end
end

attr_reader :service, :client_region, :client_endpoint, :smoke_tests
attr_reader :service_name, :smoke_tests, :service_module

# @return [String|nil]
def generated_src_warning
return if @custom
GENERATED_SRC_WARNING
end

class SmokeTest < View
def initialize(options)
@service = options.fetch(:service)
@id = options.fetch(:id)
@operation_name = underscore(options.fetch(:operation_name))
@input = options.fetch(:input)
@expectation = expectation_str(options.fetch(:expectation))
@config = options.fetch(:config)

tags = options.fetch(:tags) || []
tags = tags.map { |t| "@#{t}" }.join(' ')
@tags = "@smoke @#{@service.identifier} #{tags}".chomp
end

attr_reader :id, :operation_name, :expectation, :tags

# TODO: this only assumes top level? but may be nested
def param_hash
@input.each_with_object({}) do |(raw_key, value), acc|
key = underscore(raw_key)
acc[key] = value
end.to_json
end

def config_hash
@config.each_with_object({}) do |(raw_key, raw_value), acc|
key, value = config_map(raw_key, raw_value)
acc[key] = value unless key.nil?
end.to_json
end

private

def config_map(raw_key, raw_value)
case raw_key
# generic
when 'region' then ['region', raw_value]
when 'sigv4aRegionSet' then nil # TODO
when 'uri' then ['endpoint', raw_value]
when 'useFips' then ['use_fips_endpoint', raw_value]
when 'useDualStack' then ['use_dualstack_endpoint', raw_value]
# service specific
when 'useGlobalEndpoint'
value = raw_value == 'true' ? 'legacy' : 'regional'
if @service.name == 'S3'
['s3_us_east_1_regional_endpoint', value]
elsif @service.name == 'STS'
['sts_regional_endpoints', value]
end
# s3 specific
when 'useAccelerate' then ['use_accelerate_endpoint', raw_value]
when 'useArnRegion' then ['s3_use_arn_region', raw_value]
when 'useMultiRegionAccessPoints'
value = raw_value == 'true' ? 'false' : 'true'
['s3_disable_multiregion_access_points', value]
when 'forcePathStyle' then ['force_path_style', raw_value]
when 'useAccountIdRouting' then nil # TODO
else
# catch all, possible code generated config options
[downcase(raw_key), raw_value]
end
end

def expectation_str(expectation)
if expectation.key?('success')
'I expect an error was not raised'
elsif expectation.key?('failure')
if (error_id = expectation['failure']['errorId'])
error_class = "#{@service.module_name}::Errors::#{error_id}"
"I expect a '#{error_class}' was raised"
else
'I expect an error was raised'
end
end
end
end

end
end
end
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ def initialize(options)
service = options.fetch(:service)
@var_name = service.identifier
@module_name = service.module_name
if service.smoke_tests
@client_endpoint = service.smoke_tests['defaultEndpoint']
end
end

attr_reader :var_name, :module_name, :client_endpoint
attr_reader :var_name, :module_name

end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{{#generated_src_warning}}
{{generated_src_warning}}
{{/generated_src_warning}}
Feature: Smoke tests for {{service}}

Background:
{{#client_endpoint}}
Given I create a client with endpoint '{{client_endpoint}}'
{{/client_endpoint}}
{{^client_endpoint}}
Given I create a client in region '{{client_region}}'
{{/client_endpoint}}
Feature: Smoke tests for {{service_name}}
{{#smoke_tests}}

{{smoke_test_tags}}
Scenario: {{scenario_string}}
When I call the operation '{{operation}}' with params:
"""
{{tags}}
Scenario: {{id}}
Given I create a '{{service_module}}' client with config:
"""
{{&config_hash}}
"""
When I call the operation '{{operation_name}}' with params:
"""
{{&param_hash}}
"""
Then {{error_expectation}}
"""
Then {{&expectation}}
{{/smoke_tests}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
Before("@{{var_name}}") do
{{#client_endpoint}}
@service = {{module_name}}::Resource.new(endpoint: '{{client_endpoint}}')
{{/client_endpoint}}
{{^client_endpoint}}
@service = {{module_name}}::Resource.new
{{/client_endpoint}}
@client = @service.client
end

Expand Down
2 changes: 1 addition & 1 deletion build_tools/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_examples(svc_name, models_dir)
end

def load_smoke(svc_name, models_dir)
path = model_path('smoke.json', models_dir)
path = model_path('smoke-2.json', models_dir)
if path
smoke = JSON.load(File.read(path))
BuildTools::Customizations.apply_smoke_customizations(svc_name, smoke)
Expand Down
49 changes: 33 additions & 16 deletions gems/aws-sdk-acm/features/smoke.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,38 @@

Feature: Smoke tests for ACM

Background:
Given I create a client in region 'us-west-2'
@smoke @acm @connection
Scenario: FailureExample
Given I create a 'Aws::ACM' client with config:
"""
{"region":"moon-dark-1"}
"""
When I call the operation 'test_operation' with params:
"""
{"message":"foo"}
"""
Then I expect an error was raised

@acm @smoke
Scenario: Call Aws::ACM::Client#list_certificates and expect it to succeed
When I call the operation 'list_certificates' with params:
"""
{}
"""
Then I expect an error was not raised
@smoke @acm
Scenario: ErrorExample
Given I create a 'Aws::ACM' client with config:
"""
{"region":"eu-central-1"}
"""
When I call the operation 'test_operation' with params:
"""
{"message":"föö"}
"""
Then I expect a 'Aws::ACM::Errors::InvalidMessageError' was raised

@acm @smoke
Scenario: Call Aws::Aws::ACM::Client#get_certificate and expect it to fail
When I call the operation 'get_certificate' with params:
"""
{"certificate_arn":"arn:aws:acm:region:123456789012:certificate/12345678-1234-1234-1234-123456789012"}
"""
Then I expect an error was raised
@smoke @acm
Scenario: SuccessExample
Given I create a 'Aws::ACM' client with config:
"""
{"region":"eu-central-1"}
"""
When I call the operation 'test_operation' with params:
"""
{"message":"bar"}
"""
Then I expect an error was not raised
Loading

0 comments on commit c509638

Please sign in to comment.