vcloud-tools-tester 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  Gemfile.lock
2
+ /coverage/
data/.travis.yml CHANGED
@@ -2,8 +2,7 @@
2
2
  language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
- branches:
6
- except:
7
- - master
5
+ - 2.0.0
6
+ - 2.1.2
8
7
  notifications:
9
8
  email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.1.0 (2014-06-23)
2
+
3
+ Features:
4
+
5
+ - Test parameters should now be accessed by calling:
6
+
7
+ ```ruby
8
+ test_params = Vcloud::Tools::Tester::TestSetup.new(config_file, expected_user_params).test_params
9
+ ```
10
+ - Vcloud::Tools::Tester::TestSetup now creates network fixtures if not already
11
+ present in the environment and sets the network ID parameters by quering the API.
12
+ - Now possible to specify which user-defined parameters should be defined in the
13
+ YAML-formatted configuration file; passed as an array to TestSetup#initialize.
14
+
1
15
  ## 0.0.6 (2014-05-28)
2
16
 
3
17
  Features:
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,61 @@
1
+ # Contributing to vCloud Tools Tester
2
+
3
+ We really welcome contributions.
4
+
5
+ ## A quick guide on how to contribute
6
+
7
+ 1. Clone the repo:
8
+
9
+ git clone git@github.com:gds-operations/vcloud-tools-tester.git
10
+
11
+ 2. Run `bundle` to get the required dependecies
12
+
13
+ 3. Run the tests. Pull requests that add features must include unit tests,
14
+ so it is good to ensure you've got them passing to begin with.
15
+
16
+ bundle exec rake
17
+
18
+ 4. Add your functionality or bug fix and a test for your change. Only refactoring and
19
+ documentation changes do not require tests. If the functionality is at all complicated
20
+ then it is likely that more than one test will be required. If you would like help
21
+ with writing tests please do ask us.
22
+
23
+ 5. Make sure all the tests pass.
24
+
25
+ 6. Update the [CHANGELOG](https://github.com/gds-operations/vcloud-tools-tester/blob/master/CHANGELOG.md)
26
+ with a short description of what the change is. This may be a feature, a bugfix, or an
27
+ API change. If your change is documenation or refactoring, you do not need to add a line
28
+ to the CHANGELOG.
29
+
30
+ 7. Fork the repo, push to your fork, and submit a pull request.
31
+
32
+ ## How soon will we respond?
33
+
34
+ We will comment on your pull request within two working days. However, we might not be able to review it immediately.
35
+
36
+ We may come back to you with comments and suggestions, and if we would like you to make changes, we will close the pull request as well as adding details of the changes we'd like you to make.
37
+
38
+ If you feel your pull request has been outstanding too long, please feel free to bump it by making a comment on it.
39
+
40
+ ## Guidelines for making a pull request
41
+
42
+ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
43
+ "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
44
+ interpreted as described in RFC 2119.
45
+
46
+ ## In order for a pull request to be accepted, it MUST
47
+
48
+ - Include at least one test (unless it is documentation or refactoring). If you have any questions about how to write tests, please ask us, we will be happy to help
49
+ - Follow our [Git style guide](https://github.com/alphagov/styleguides/blob/master/git.md)
50
+ - Include a clear summary in the pull request comments as to what the change is and why
51
+ you are making it
52
+ - Be readable - we might ask you to change unclear variable names or obscure syntactic sugar
53
+ - Have [good commit messages](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
54
+ that explain the change being made in that commit. Don't be afraid to write a lot in the
55
+ detail.
56
+
57
+ ## In order for a pull request to be accepted, it SHOULD
58
+
59
+ - Include a line in the CHANGELOG unless it is a refactoring or documentation change
60
+ - If it is code, follow our [Ruby style guide](https://github.com/alphagov/styleguides/blob/master/ruby.md)
61
+ - If it is documentation, follow the [GDS content style guide](https://www.gov.uk/design-principles/style-guide/style-points)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # vCloud Tools Tester
2
2
 
3
- The integration tests for [vCloud Tools](https://github.com/alphagov/vcloud-tools) require a lot of parameters that are specific to your environment, and not ones you want to make public.
3
+ The integration tests for [vCloud Tools](https://github.com/gds-operations/vcloud-tools) require a lot of parameters that are specific to your environment, and not ones you want to make public.
4
4
 
5
5
  vCloud tools Tester makes it easy to run the vCloud Tools integration tests using a config file.
6
6
 
data/Rakefile CHANGED
@@ -14,6 +14,6 @@ end
14
14
 
15
15
  require 'rubocop/rake_task'
16
16
 
17
- Rubocop::RakeTask.new(:rubocop) do |task|
17
+ RuboCop::RakeTask.new(:rubocop) do |task|
18
18
  task.options = ['--lint']
19
19
  end
@@ -0,0 +1,154 @@
1
+ module Vcloud
2
+ module Tools
3
+ module Tester
4
+ class FixtureParameters
5
+ attr_reader :fixture_params
6
+
7
+ def initialize(user_params)
8
+ @vcloud_api = Vcloud::Fog::ModelInterface.new
9
+ @user_params = user_params
10
+ ensure_vcloud_fixtures
11
+ extract_fixture_params
12
+ end
13
+
14
+ private
15
+
16
+ def ensure_vcloud_fixtures
17
+ generate_fixtures_config
18
+ correct_networks = ensure_networks_correct(@expected_fixtures_config[:networks])
19
+ @fixtures = correct_networks
20
+ end
21
+
22
+ def generate_fixtures_config
23
+ @expected_fixtures_config = {
24
+ :networks => {
25
+ :network_1 => {
26
+ :edge_gateway => @user_params["edge_gateway"],
27
+ :vdc_name => @user_params["vdc_1_name"],
28
+ :name => @user_params["network_1"],
29
+ :type => 'application/vnd.vmware.vcloud.orgVdcNetwork+xml',
30
+ :description => '',
31
+ :is_inherited => 'false',
32
+ :is_shared => 'true',
33
+ :fence_mode => 'natRouted',
34
+ :gateway => '192.168.1.1',
35
+ :netmask => '255.255.255.0',
36
+ :dns1 => nil,
37
+ :dns2 => nil,
38
+ :dns_suffix => nil,
39
+ :ip_ranges => [
40
+ {
41
+ :start_address => "192.168.1.2",
42
+ :end_address => "192.168.1.254"
43
+ }
44
+ ],
45
+ },
46
+ :network_2 => {
47
+ :edge_gateway => @user_params["edge_gateway"],
48
+ :vdc_name => @user_params["vdc_2_name"],
49
+ :name => @user_params["network_2"],
50
+ :type => 'application/vnd.vmware.vcloud.orgVdcNetwork+xml',
51
+ :description => '',
52
+ :is_inherited => 'false',
53
+ :is_shared => 'true',
54
+ :fence_mode => 'isolated',
55
+ :gateway => '10.0.0.1',
56
+ :netmask => '255.255.0.0',
57
+ :dns1 => nil,
58
+ :dns2 => nil,
59
+ :dns_suffix => nil,
60
+ :ip_ranges => [
61
+ {
62
+ :start_address => "10.0.0.2",
63
+ :end_address => "10.0.255.254"
64
+ }
65
+ ],
66
+ },
67
+ },
68
+ }
69
+ end
70
+
71
+ def ensure_networks_correct(expected_network_config)
72
+ existing_networks = @vcloud_api.current_organization.networks.all(false)
73
+
74
+ correct_networks = []
75
+
76
+ expected_network_config.each_value do |expected_config|
77
+ # find an existing network matching the expected configuration
78
+ found_network = existing_networks.detect { |n| n.name == expected_config[:name] }
79
+
80
+ unless found_network
81
+ new_network = Vcloud::Core::OrgVdcNetwork.provision(expected_config)
82
+ correct_networks << new_network
83
+ next
84
+ end
85
+
86
+ unless network_matches_expected?(found_network, expected_config)
87
+ raise "Network '#{expected_config[:name]}' already exists but is not configured as expected.
88
+ You should delete this network before re-running the tests; it will be re-created by the tests."
89
+ end
90
+
91
+ correct_networks << found_network
92
+ end
93
+
94
+ correct_networks
95
+ end
96
+
97
+ def extract_fixture_params
98
+ raise "No fixtures present" if @fixtures.empty?
99
+
100
+ @fixture_params = {}
101
+ expected_networks = @expected_fixtures_config[:networks]
102
+
103
+ @fixtures.each do |fixture|
104
+ case fixture
105
+ when ::Fog::Compute::VcloudDirector::Network
106
+ expected_networks.each do |network_ref, expected_network_config|
107
+ if expected_network_config[:name] == fixture.name
108
+ @fixture_params["#{network_ref}_id"] = fixture.id
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ def network_matches_expected?(found_network, expected_network_config)
116
+ network_config_matches_expected?(found_network, expected_network_config) &&
117
+ network_available_to_correct_vdc?(found_network, expected_network_config)
118
+ end
119
+
120
+ def network_config_matches_expected?(found_network, expected_network_config)
121
+ found_network_config = found_network.instance_variable_get(:@attributes)
122
+
123
+ expected_network_config = expected_network_config.reject do |key|
124
+ %w{edge_gateway vdc_name}.include?(key.to_s)
125
+ end
126
+
127
+ found_network_config = found_network_config.reject do |key|
128
+ %w{id edge_gateway href}.include?(key.to_s)
129
+ end
130
+
131
+ # sort hashes ready for comparison
132
+ found_network_config = Hash[found_network_config.sort]
133
+ expected_network_config = Hash[expected_network_config.sort]
134
+
135
+ found_network_config == expected_network_config
136
+ end
137
+
138
+ def network_available_to_correct_vdc?(found_network, expected_network_config)
139
+ vdcs = @vcloud_api.current_organization.vdcs.all(false)
140
+
141
+ vdcs.each do |vdc|
142
+ next unless vdc.name == expected_network_config[:vdc_name]
143
+
144
+ matching_network = vdc.available_networks.detect { |n| n[:href].split('/').last == found_network.id }
145
+
146
+ return true if matching_network
147
+ end
148
+
149
+ false
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -4,102 +4,29 @@ module Vcloud
4
4
  module Tools
5
5
  module Tester
6
6
  class TestParameters
7
+ def initialize(user_params, fixture_params)
8
+ raise "No user parameters received" if user_params.empty?
9
+ raise "No fixture parameters received" if fixture_params.empty?
7
10
 
8
- def initialize(config_file)
9
- load_config(config_file)
10
- end
11
-
12
- def load_config(config_file)
13
- unless File.exist?(config_file)
14
- raise ArgumentError.new("Missing required file: #{config_file}")
15
- end
16
- organization = ENV.fetch('FOG_CREDENTIAL') do
17
- raise "Must set FOG_CREDENTIAL envvar"
18
- end
19
- all_config = YAML::load(File.open(config_file))
20
- @input_config = all_config.fetch(organization) do
21
- raise "Invalid FOG_CREDENTIAL value '#{organization}'"
22
- end
23
- end
24
-
25
- def vdc_1_name
26
- @input_config["vdc_1_name"]
27
- end
28
-
29
- def vdc_2_name
30
- @input_config["vdc_2_name"]
31
- end
11
+ @user_params = user_params
12
+ @fixture_params = fixture_params
32
13
 
33
- def catalog
34
- @input_config["catalog"]
14
+ define_attr_readers
35
15
  end
36
16
 
37
- def vapp_template
38
- @input_config["vapp_template"]
39
- end
40
-
41
- def network_1
42
- @input_config["network_1"]
43
- end
44
-
45
- def network_1_id
46
- @input_config["network_1_id"]
47
- end
17
+ private
48
18
 
49
- def network_1_ip
50
- @input_config["network_1_ip"]
51
- end
52
-
53
- def network_2
54
- @input_config["network_2"]
55
- end
56
-
57
- def network_2_id
58
- @input_config["network_2_id"]
59
- end
19
+ def define_attr_readers
20
+ test_params = @user_params.merge(@fixture_params)
60
21
 
61
- def network_2_ip
62
- @input_config["network_2_ip"]
63
- end
64
-
65
- def storage_profile
66
- @input_config["storage_profile"]
67
- end
68
-
69
- def default_storage_profile_name
70
- @input_config["default_storage_profile_name"]
71
- end
72
-
73
- def default_storage_profile_href
74
- @input_config["default_storage_profile_href"]
75
- end
76
-
77
- def vdc_1_storage_profile_href
78
- @input_config["vdc_1_storage_profile_href"]
79
- end
80
-
81
- def vdc_2_storage_profile_href
82
- @input_config["vdc_2_storage_profile_href"]
83
- end
84
-
85
- def edge_gateway
86
- @input_config["edge_gateway"]
87
- end
88
-
89
- def edge_gateway_id
90
- @input_config["edge_gateway_id"]
91
- end
92
-
93
- def provider_network
94
- @input_config["provider_network"]
95
- end
96
-
97
- def provider_network_id
98
- @input_config["provider_network_id"]
22
+ # Use +send+ because +define_method+ is private
23
+ test_params.each_key do |param|
24
+ self.class.send(:define_method, param) { test_params[param] }
25
+ end
99
26
  end
100
27
 
101
- def provider_network_ip
102
- @input_config["provider_network_ip"]
28
+ def method_missing (method_name)
29
+ raise "Method TestParameters##{method_name} not defined"
103
30
  end
104
31
  end
105
32
  end
@@ -0,0 +1,18 @@
1
+ require 'yaml'
2
+
3
+ module Vcloud
4
+ module Tools
5
+ module Tester
6
+ class TestSetup
7
+ attr_reader :test_params
8
+
9
+ def initialize(config_file, expected_user_params)
10
+ user_params = Vcloud::Tools::Tester::UserParameters.new(config_file, expected_user_params).user_params
11
+ fixture_params = Vcloud::Tools::Tester::FixtureParameters.new(user_params).fixture_params
12
+
13
+ @test_params = Vcloud::Tools::Tester::TestParameters.new(user_params, fixture_params)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require 'yaml'
2
+
3
+ module Vcloud
4
+ module Tools
5
+ module Tester
6
+ class UserParameters
7
+ attr_reader :user_params
8
+
9
+ def initialize(config_file, expected_user_params)
10
+ @config_file = config_file
11
+ @expected_user_params = expected_user_params || []
12
+
13
+ parse_config
14
+ end
15
+
16
+ private
17
+
18
+ def parse_config
19
+ unless File.exist?(@config_file)
20
+ raise ArgumentError.new("Missing required file: #{@config_file}")
21
+ end
22
+
23
+ organization = ENV.fetch('FOG_CREDENTIAL') do
24
+ raise "Must set FOG_CREDENTIAL environment variable"
25
+ end
26
+
27
+ all_config = YAML::load_file(@config_file)
28
+
29
+ @user_params = all_config.fetch(organization) do
30
+ raise "Invalid FOG_CREDENTIAL environment variable value '#{organization}'"
31
+ end
32
+
33
+ defined_keys = @user_params.keys
34
+ missing_params = @expected_user_params - defined_keys
35
+ if missing_params.any?
36
+ raise "Required parameters not defined in #{@config_file}: " + missing_params.join(", ")
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,7 +1,7 @@
1
1
  module Vcloud
2
2
  module Tools
3
3
  module Tester
4
- VERSION = "0.0.6"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,2 +1,8 @@
1
+ require "vcloud/core"
2
+ require "vcloud/fog"
3
+
1
4
  require "vcloud/tools/tester/version"
5
+ require "vcloud/tools/tester/fixture_parameters"
2
6
  require "vcloud/tools/tester/test_parameters"
7
+ require "vcloud/tools/tester/test_setup"
8
+ require "vcloud/tools/tester/user_parameters"
@@ -0,0 +1,30 @@
1
+ # SimpleCov must run _first_ according to its README
2
+ if ENV['COVERAGE']
3
+ require 'simplecov'
4
+
5
+ # monkey-patch to prevent SimpleCov from reporting coverage percentage
6
+ class SimpleCov::Formatter::HTMLFormatter
7
+ def output_message(_message)
8
+ nil
9
+ end
10
+ end
11
+
12
+ SimpleCov.adapters.define 'gem' do
13
+ add_filter '/spec/'
14
+ add_filter '/features/'
15
+ add_filter '/vendor/'
16
+
17
+ add_group 'Libraries', '/lib/'
18
+ end
19
+
20
+ SimpleCov.minimum_coverage(100)
21
+ SimpleCov.start 'gem'
22
+ end
23
+
24
+ require 'rspec'
25
+
26
+ RSpec.configure do |config|
27
+ config.expect_with :rspec do |c|
28
+ c.syntax = :expect
29
+ end
30
+ end
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+ require 'vcloud/tools/tester'
3
+
4
+ describe Vcloud::Tools::Tester::FixtureParameters do
5
+ subject { Vcloud::Tools::Tester::FixtureParameters.new(user_params) }
6
+
7
+ before(:each) do
8
+ stub_const("Fog::Compute::VcloudDirector::Network", Object)
9
+ Vcloud::Fog::ModelInterface.stub_chain(:new, :current_organization, :networks, :all).and_return(mock_found_interfaces)
10
+ Vcloud::Fog::ModelInterface.stub_chain(:new, :current_organization, :vdcs, :all).and_return(mock_found_vdcs)
11
+ end
12
+
13
+ let(:edge_gateway_name) { "Test edge gateway" }
14
+ let(:vdc_1_name) { "Foo vDC" }
15
+ let(:vdc_2_name) { "Bar vDC" }
16
+ let(:network_1_name) { "Test network 1" }
17
+ let(:network_2_name) { "Test network 2" }
18
+ let(:network_1_id) { "12345678-1234-1234-1234-000000111111" }
19
+ let(:network_2_id) { "12345678-1234-1234-1234-000000222222" }
20
+ let(:network_1_href) { "https://example.com/admin/network/" + network_1_id }
21
+ let(:network_2_href) { "https://example.com/admin/network/" + network_2_id }
22
+
23
+ let(:user_params) do
24
+ {
25
+ "edge_gateway" => edge_gateway_name,
26
+ "vdc_1_name" => vdc_1_name,
27
+ "vdc_2_name" => vdc_2_name,
28
+ "network_1" => network_1_name,
29
+ "network_2" => network_2_name,
30
+ }
31
+ end
32
+
33
+ let(:mock_found_vdcs) do
34
+ [
35
+ mock_vdc_1,
36
+ mock_vdc_2
37
+ ]
38
+ end
39
+
40
+ let(:mock_vdc_1) do
41
+ double(:vdc, :name => vdc_1_name, :available_networks => [ { :href => network_1_href } ])
42
+ end
43
+
44
+ let(:mock_vdc_2) do
45
+ double(:vdc, :name => vdc_2_name, :available_networks => [ { :href => network_2_href } ])
46
+ end
47
+
48
+ let(:mock_found_interfaces) do
49
+ [
50
+ mock_fixture_network_1,
51
+ mock_fixture_network_2,
52
+ ]
53
+ end
54
+
55
+ let(:mock_fixture_network_1) do
56
+ double(:network, :id => network_1_id, :name => network_1_name)
57
+ end
58
+
59
+ let(:mock_fixture_network_2) do
60
+ double(:network, :id => network_2_id, :name => network_2_name)
61
+ end
62
+
63
+ let(:mock_fixture_uuids) { [ network_1_id, network_2_id ] }
64
+
65
+ let(:network_config_1) do
66
+ {
67
+ :id => network_1_id,
68
+ :href => "https://example.com/admin/network/" + network_1_id,
69
+ :edge_gateway => edge_gateway_name,
70
+ :name => network_1_name,
71
+ :type => "application/vnd.vmware.vcloud.orgVdcNetwork+xml",
72
+ :description => "",
73
+ :is_inherited => "false",
74
+ :is_shared => "true",
75
+ :fence_mode => "natRouted",
76
+ :gateway => "192.168.1.1",
77
+ :netmask => "255.255.255.0",
78
+ :dns1 => nil,
79
+ :dns2 => nil,
80
+ :dns_suffix => nil,
81
+ :ip_ranges =>
82
+ [
83
+ {
84
+ :start_address => "192.168.1.2",
85
+ :end_address => "192.168.1.254"
86
+ },
87
+ ]
88
+ }
89
+ end
90
+
91
+ let(:network_config_2) do
92
+ {
93
+ :id => network_2_id,
94
+ :href => "https://example.com/admin/network/" + network_2_id,
95
+ :edge_gateway => edge_gateway_name,
96
+ :name => network_2_name,
97
+ :type => "application/vnd.vmware.vcloud.orgVdcNetwork+xml",
98
+ :description => "",
99
+ :is_inherited => "false",
100
+ :is_shared => "true",
101
+ :fence_mode => "isolated",
102
+ :gateway => "10.0.0.1",
103
+ :netmask => "255.255.0.0",
104
+ :dns1 => nil,
105
+ :dns2 => nil,
106
+ :dns_suffix => nil,
107
+ :ip_ranges =>
108
+ [
109
+ {
110
+ :start_address => "10.0.0.2",
111
+ :end_address => "10.0.255.254"
112
+ },
113
+ ]
114
+ }
115
+ end
116
+
117
+ context "correct fixture networks exist" do
118
+ before(:each) do
119
+ expect(mock_fixture_network_1).to receive(:instance_variable_get).with(:@attributes).and_return(network_config_1)
120
+ expect(mock_fixture_network_2).to receive(:instance_variable_get).with(:@attributes).and_return(network_config_2)
121
+ end
122
+
123
+ it "doesn't provision new networks" do
124
+ expect(Vcloud::Core::OrgVdcNetwork).not_to receive(:provision)
125
+ subject
126
+ end
127
+
128
+ it "returns the correct fixture parameters" do
129
+ expect(subject.fixture_params.values).to eq(mock_fixture_uuids)
130
+ end
131
+ end
132
+
133
+ describe "correct fixture networks exist but aren't available to the appropriate vDCs" do
134
+ let(:mock_found_vdcs) do
135
+ [
136
+ double(:vdc, :name => vdc_1_name, :available_networks => [ { :href => "https://example.com/admin/network/garbage" } ]),
137
+ mock_vdc_2
138
+ ]
139
+ end
140
+
141
+ it "raises an error" do
142
+ expect(mock_fixture_network_1).to receive(:instance_variable_get).with(:@attributes).and_return(network_config_1)
143
+ expect{ subject }.to raise_error(/already exists but is not configured as expected/)
144
+ end
145
+ end
146
+
147
+ context "fixture networks don't yet exist" do
148
+ let(:mock_found_interfaces) do
149
+ [
150
+ double(:network, :id => "55555555-1234-1234-1234-000000111111", :name => "rubbish"),
151
+ double(:network, :id => "55555555-1234-1234-1234-000000222222", :name => "trash"),
152
+ ]
153
+ end
154
+
155
+ it "tries to create them and returns the appropriate fixture parameters" do
156
+ expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).and_return(mock_fixture_network_1)
157
+ expect(Vcloud::Core::OrgVdcNetwork).to receive(:provision).and_return(mock_fixture_network_2)
158
+ expect(subject.fixture_params.values).to eq(mock_fixture_uuids)
159
+ end
160
+ end
161
+ end
@@ -1,106 +1,58 @@
1
+ require 'spec_helper'
1
2
  require 'vcloud/tools/tester'
2
3
 
3
- module Vcloud::Tools::Tester
4
+ describe Vcloud::Tools::Tester::TestParameters do
5
+ before(:all) do
6
+ @data_dir = File.join(File.dirname(__FILE__), "/data")
7
+ end
4
8
 
5
- describe TestParameters do
9
+ subject(:parameters) do
10
+ Vcloud::Tools::Tester::TestParameters.new(user_params, fixture_params)
11
+ end
6
12
 
7
- before(:all) do
8
- @data_dir = File.join(File.dirname(__FILE__), "/data")
13
+ let(:config_file) { "#{@data_dir}/test_launcher_config.yaml" }
14
+ let(:vdc_1_name) { "launcher-vdc-1-name" }
15
+ let(:network_1_id) { "12345678-1234-1234-1234-000000111111" }
16
+ let(:user_params) {
17
+ {
18
+ :vdc_1_name => vdc_1_name,
19
+ }
20
+ }
21
+ let(:fixture_params) {
22
+ {
23
+ :network_1_id => network_1_id,
24
+ }
25
+ }
26
+
27
+ context "parameters required for integration tests" do
28
+ it "gives a useful error when the parameter is not set" do
29
+ expect{parameters.doesnotexist}.to raise_error("Method TestParameters#doesnotexist not defined")
9
30
  end
10
31
 
11
- context "loading config file" do
12
-
13
- it "loads input yaml when intialized" do
14
- stub_const('ENV', {'FOG_CREDENTIAL' => 'test-organisation'})
15
- parameters = TestParameters.new("#{@data_dir}/test_config.yaml")
16
- test_vdc = parameters.vdc_1_name
17
- expect(test_vdc).to eq("test-vdc-name")
18
- end
19
-
20
- it "loads a different organization's yaml when env var changes" do
21
- stub_const('ENV', {'FOG_CREDENTIAL' => 'other-organisation'})
22
- parameters = TestParameters.new("#{@data_dir}/test_config.yaml")
23
- test_vdc = parameters.vdc_1_name
24
- expect(test_vdc).to eq("other-vdc-name")
25
- end
26
-
27
- it "input yaml file can be changed" do
28
- stub_const('ENV', {'FOG_CREDENTIAL' => 'minimal-organisation'})
29
- parameters = TestParameters.new("#{@data_dir}/test_minimal_config.yaml")
30
- test_vdc = parameters.vdc_1_name
31
- expect(test_vdc).to eq("minimal-vdc-name")
32
- end
33
-
34
- it "gives a useful error when FOG_CREDENTIAL is unset" do
35
- stub_const('ENV', {})
36
- expect {
37
- TestParameters.new("#{@data_dir}/test_minimal_config.yaml")
38
- }.to raise_error(RuntimeError, /Must set FOG_CREDENTIAL envvar/)
39
- end
32
+ it "returns the correct value for the user-defined parameters" do
33
+ test_vdc_1_name = parameters.vdc_1_name
34
+ expect(test_vdc_1_name).to eq(vdc_1_name)
35
+ end
40
36
 
41
- it "gives a useful error when the FOG_CREDENTIAL is missing from the config" do
42
- stub_const('ENV', {'FOG_CREDENTIAL' => 'bogus-fog-credential'})
43
- expect {
44
- TestParameters.new("#{@data_dir}/test_config.yaml")
45
- }.to raise_error(RuntimeError, /Invalid FOG_CREDENTIAL value/)
46
- end
37
+ it "returns the correct value for the fixture parameters" do
38
+ test_network_1_id = parameters.network_1_id
39
+ expect(test_network_1_id).to eq(network_1_id)
40
+ end
41
+ end
47
42
 
48
- it "gives a useful error when there is no config file" do
49
- stub_const('ENV', {'FOG_CREDENTIAL' => 'minimal-organisation'})
50
- expect {
51
- TestParameters.new("#{@data_dir}/non_existent_testing_config.yaml")
52
- }.to raise_error(ArgumentError, /Missing required file/)
43
+ context "sanity checks" do
44
+ context "no user-defined parameters passed in" do
45
+ let(:user_params) {{}}
46
+ it "raises an error if it receives no user-defined parameters" do
47
+ expect{ parameters }.to raise_error("No user parameters received")
53
48
  end
54
-
55
49
  end
56
50
 
57
- context "parameters required for integration tests" do
58
-
59
- it "contains all the parameters required for the vCloud Launcher tests" do
60
- ENV['FOG_CREDENTIAL'] = "launcher-testing-organisation"
61
- parameters = TestParameters.new("#{@data_dir}/test_launcher_config.yaml")
62
-
63
- test_vdc_1_name = parameters.vdc_1_name
64
- expect(test_vdc_1_name).to eq("launcher-vdc-1-name")
65
-
66
- test_vdc_2_name = parameters.vdc_2_name
67
- expect(test_vdc_2_name).to eq("launcher-vdc-2-name")
68
-
69
- test_catalog = parameters.catalog
70
- expect(test_catalog).to eq("launcher-catalog")
71
-
72
- test_vapp_template = parameters.vapp_template
73
- expect(test_vapp_template).to eq("launcher-vapp-template")
74
-
75
- test_network_1 = parameters.network_1
76
- expect(test_network_1).to eq("launcher-network-1")
77
-
78
- test_network_1_ip = parameters.network_1_ip
79
- expect(test_network_1_ip).to eq("launcher-network-1-ip")
80
-
81
- test_network_2 = parameters.network_2
82
- expect(test_network_2).to eq("launcher-network-2")
83
-
84
- test_network_2_ip = parameters.network_2_ip
85
- expect(test_network_2_ip).to eq("launcher-network-2-ip")
86
-
87
- test_storage_profile = parameters.storage_profile
88
- expect(test_storage_profile).to eq("launcher-storage-profile")
89
-
90
- test_default_storage_profile_name = parameters.default_storage_profile_name
91
- expect(test_default_storage_profile_name).to eq("launcher-default-sp-name")
92
-
93
- test_default_storage_profile_href = parameters.default_storage_profile_href
94
- expect(test_default_storage_profile_href).to eq("launcher-default-sp-href")
95
-
96
- test_vdc_1_storage_profile_href = parameters.vdc_1_storage_profile_href
97
- expect(test_vdc_1_storage_profile_href).to eq("launcher-vdc-1-sp-href")
98
-
99
- test_vdc_2_storage_profile_href = parameters.vdc_2_storage_profile_href
100
- expect(test_vdc_2_storage_profile_href).to eq("launcher-vdc-2-sp-href")
51
+ context "no fixture parameters passed in" do
52
+ let(:fixture_params) {{}}
53
+ it "raises an error if it receives no fixture parameters" do
54
+ expect{ parameters }.to raise_error("No fixture parameters received")
101
55
  end
102
-
103
56
  end
104
-
105
57
  end
106
58
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'vcloud/tools/tester'
3
+
4
+ describe Vcloud::Tools::Tester::TestSetup do
5
+ before(:each) do
6
+ Vcloud::Tools::Tester::UserParameters.stub(:new).and_return(mock_user_parameters)
7
+ Vcloud::Tools::Tester::FixtureParameters.stub(:new).and_return(mock_fixture_parameters)
8
+ Vcloud::Tools::Tester::TestParameters.stub(:new).and_return(mock_test_parameters)
9
+ end
10
+
11
+ let(:example_filename) { "example_filename.yaml" }
12
+ let(:expected_user_params) { [] }
13
+
14
+ let(:mock_user_parameters) do
15
+ double(:user_parameters, :user_params => {})
16
+ end
17
+
18
+ let(:mock_fixture_parameters) do
19
+ double(:fixture_parameters, :fixture_params => {})
20
+ end
21
+
22
+ let(:mock_test_parameters) do
23
+ double(:test_parameters, :test_params => {})
24
+ end
25
+
26
+ subject do
27
+ Vcloud::Tools::Tester::TestSetup.new(example_filename, expected_user_params)
28
+ end
29
+
30
+ it "responds with test parameters" do
31
+ expect(subject).to respond_to(:test_params)
32
+ end
33
+
34
+ it "calls the appropriate methods" do
35
+ expect(Vcloud::Tools::Tester::UserParameters).to receive(:new).with(example_filename, expected_user_params)
36
+ expect(Vcloud::Tools::Tester::FixtureParameters).to receive(:new).with({})
37
+ expect(Vcloud::Tools::Tester::TestParameters).to receive(:new).with({}, {})
38
+
39
+ subject.test_params
40
+ end
41
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'vcloud/tools/tester'
3
+
4
+ describe Vcloud::Tools::Tester::UserParameters do
5
+ subject(:parameters) do
6
+ Vcloud::Tools::Tester::UserParameters.new(config_file, expected_user_params).user_params
7
+ end
8
+
9
+ before(:each) do
10
+ stub_const('ENV', {'FOG_CREDENTIAL' => 'test-organisation'})
11
+ end
12
+
13
+ let(:data_dir) do
14
+ File.join(File.dirname(__FILE__), "/data")
15
+ end
16
+
17
+ let(:config_file) do
18
+ "#{data_dir}/test_config.yaml"
19
+ end
20
+
21
+ let(:expected_user_params) {[]}
22
+ context "loading standard config file" do
23
+ it "loads input yaml when intialized" do
24
+ test_vdc = parameters["vdc_1_name"]
25
+ expect(test_vdc).to eq("test-vdc-name")
26
+ end
27
+
28
+ it "loads a different organization's parameters when FOG_CREDENTIAL changes" do
29
+ stub_const('ENV', {'FOG_CREDENTIAL' => 'other-organisation'})
30
+ test_vdc = parameters["vdc_1_name"]
31
+ expect(test_vdc).to eq("other-vdc-name")
32
+ end
33
+
34
+ it "gives a useful error when the FOG_CREDENTIAL is missing from the config" do
35
+ stub_const('ENV', {'FOG_CREDENTIAL' => 'bogus-fog-credential'})
36
+ expect { parameters }.to raise_error(RuntimeError, /Invalid FOG_CREDENTIAL environment variable value/)
37
+ end
38
+ end
39
+
40
+ context "when an expected user-defined parameter is missing from the config file" do
41
+ let(:expected_user_params) { [ "vdc_1_name", "bar" ] }
42
+
43
+ it "raises an error if an expected user-defined parameter is not present" do
44
+ expect{ parameters }.to raise_error(RuntimeError, "Required parameters not defined in #{config_file}: bar")
45
+ end
46
+ end
47
+
48
+ context "loading minimal config file" do
49
+ subject(:parameters) do
50
+ Vcloud::Tools::Tester::UserParameters.new("#{data_dir}/test_minimal_config.yaml", expected_user_params).user_params
51
+ end
52
+
53
+ it "input yaml file can be changed" do
54
+ stub_const('ENV', {'FOG_CREDENTIAL' => 'minimal-organisation'})
55
+ test_vdc = parameters["vdc_1_name"]
56
+ expect(test_vdc).to eq("minimal-vdc-name")
57
+ end
58
+
59
+ it "gives a useful error when FOG_CREDENTIAL is unset" do
60
+ stub_const('ENV', {})
61
+ expect { parameters }.to raise_error(RuntimeError, /Must set FOG_CREDENTIAL environment variable/)
62
+ end
63
+ end
64
+
65
+ context "loading non-existent config file" do
66
+ subject(:parameters) do
67
+ Vcloud::Tools::Tester::UserParameters.new("#{data_dir}/nonexistent_config_file.yaml", expected_user_params).user_params
68
+ end
69
+
70
+ it "gives a useful error when there is no config file" do
71
+ stub_const('ENV', {'FOG_CREDENTIAL' => 'minimal-organisation'})
72
+ expect { parameters }.to raise_error(ArgumentError, /Missing required file/)
73
+ end
74
+ end
75
+ end
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["anna.shipman@digital.cabinet-office.gov.uk"]
11
11
  spec.description = %q{Tool to facilitate testing of vCloud Tools}
12
12
  spec.summary = %q{vCloud Tools integration tests require secret parameters. This helps you manage them.}
13
+ spec.homepage = "https://github.com/gds-operations/vcloud-tools-tester"
13
14
  spec.license = "MIT"
14
15
 
15
16
  spec.files = `git ls-files`.split($/)
@@ -17,8 +18,14 @@ Gem::Specification.new do |spec|
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ["lib"]
19
20
 
20
- spec.add_development_dependency 'rubocop'
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
21
23
  spec.add_development_dependency 'gem_publisher', '1.2.0'
24
+ spec.add_development_dependency 'pry'
22
25
  spec.add_development_dependency 'rake'
23
26
  spec.add_development_dependency 'rspec', '~> 2.14.1'
27
+ spec.add_development_dependency 'rubocop', '~> 0.23.0'
28
+ spec.add_development_dependency 'simplecov', '~> 0.7.1'
29
+
30
+ spec.add_runtime_dependency 'vcloud-core', '~> 0.5.0'
24
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcloud-tools-tester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-28 00:00:00.000000000 Z
12
+ date: 2014-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rubocop
15
+ name: gem_publisher
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.2.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 1.2.0
30
30
  - !ruby/object:Gem::Dependency
31
- name: gem_publisher
31
+ name: pry
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.2.0
37
+ version: '0'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - '='
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.2.0
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,54 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 2.14.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: rubocop
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.23.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.23.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.7.1
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.7.1
110
+ - !ruby/object:Gem::Dependency
111
+ name: vcloud-core
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.5.0
78
126
  description: Tool to facilitate testing of vCloud Tools
79
127
  email:
80
128
  - anna.shipman@digital.cabinet-office.gov.uk
@@ -85,20 +133,28 @@ files:
85
133
  - .gitignore
86
134
  - .travis.yml
87
135
  - CHANGELOG.md
136
+ - CONTRIBUTING.md
88
137
  - Gemfile
89
138
  - LICENSE.txt
90
139
  - README.md
91
140
  - Rakefile
92
141
  - jenkins.sh
93
142
  - lib/vcloud/tools/tester.rb
143
+ - lib/vcloud/tools/tester/fixture_parameters.rb
94
144
  - lib/vcloud/tools/tester/test_parameters.rb
145
+ - lib/vcloud/tools/tester/test_setup.rb
146
+ - lib/vcloud/tools/tester/user_parameters.rb
95
147
  - lib/vcloud/tools/tester/version.rb
148
+ - spec/spec_helper.rb
96
149
  - spec/vcloud/tools/tester/data/test_config.yaml
97
150
  - spec/vcloud/tools/tester/data/test_launcher_config.yaml
98
151
  - spec/vcloud/tools/tester/data/test_minimal_config.yaml
152
+ - spec/vcloud/tools/tester/fixture_parameters_spec.rb
99
153
  - spec/vcloud/tools/tester/test_parameters_spec.rb
154
+ - spec/vcloud/tools/tester/test_setup_spec.rb
155
+ - spec/vcloud/tools/tester/user_parameters_spec.rb
100
156
  - vcloud-tools-tester.gemspec
101
- homepage:
157
+ homepage: https://github.com/gds-operations/vcloud-tools-tester
102
158
  licenses:
103
159
  - MIT
104
160
  post_install_message:
@@ -110,10 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
166
  requirements:
111
167
  - - ! '>='
112
168
  - !ruby/object:Gem::Version
113
- version: '0'
114
- segments:
115
- - 0
116
- hash: 3857862846260560705
169
+ version: 1.9.3
117
170
  required_rubygems_version: !ruby/object:Gem::Requirement
118
171
  none: false
119
172
  requirements:
@@ -122,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
175
  version: '0'
123
176
  segments:
124
177
  - 0
125
- hash: 3857862846260560705
178
+ hash: -2901022177601151726
126
179
  requirements: []
127
180
  rubyforge_project:
128
181
  rubygems_version: 1.8.23
@@ -131,7 +184,11 @@ specification_version: 3
131
184
  summary: vCloud Tools integration tests require secret parameters. This helps you
132
185
  manage them.
133
186
  test_files:
187
+ - spec/spec_helper.rb
134
188
  - spec/vcloud/tools/tester/data/test_config.yaml
135
189
  - spec/vcloud/tools/tester/data/test_launcher_config.yaml
136
190
  - spec/vcloud/tools/tester/data/test_minimal_config.yaml
191
+ - spec/vcloud/tools/tester/fixture_parameters_spec.rb
137
192
  - spec/vcloud/tools/tester/test_parameters_spec.rb
193
+ - spec/vcloud/tools/tester/test_setup_spec.rb
194
+ - spec/vcloud/tools/tester/user_parameters_spec.rb