incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject Support for mocking client response
Date Wed, 15 Sep 2010 12:08:21 GMT
Hi,

This patch will add support for 'storing' response from client
to 'mock directory' and then read stored responses instead of
doing a API request.

This new feature could be used in testing for applications
which are using client library, to 'mock' communication
with API. (eg. for EC2).

Example usage:

<snip file="core/client/test.rb">
require 'rubygems'
require 'lib/deltacloud'
require 'lib/deltacloud_mock'

d = DeltaCloud.new('mockuser', 'mockpassword', 'http://localhost:3001/api', {
  :mock_root => "/var/tmp/deltacloud-client-mock",
  :mock_scenario => "default"
})

# This will try to read response from :mock_root
# If response is not 'mocked' then it will store it for next call.
puts d.image('img2')
# Will return mocked response instead of calling API
puts d.image('img2')
</snip>

To clarify what is ':mock_scenario' option I must explain one
issue with mocking.
When you 'mock' something (eg. store it for later use),
there could be another call which will modify original response
and your stored response will became 'outdated'. In this case,
you can use ':mock_scenario' in this way:

client.set_mock_scenario = "list-instances"
client.instances

client.set_mock_scenario = "create-instance"
client.create_instance(...)
client.instances

So now you will have mock for case when new instance is not
included in response and scenario for case when you
created a new instance and you want to list instances again
to see if newly created instance is here or not.

 -- Michal


Mime
View raw message