vcloud-core 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.0.1 (2015-01-29)
2
+
3
+ Documentation:
4
+
5
+ - Update integration test details in README
6
+ - Update Gem ownership details
7
+
8
+ Fixes:
9
+
10
+ - Tighten dependency on vcloud-tools-tester
11
+ - Refactored test namespacing
12
+
1
13
  ## 1.0.0 (2015-01-22)
2
14
 
3
15
  - Release 1.0.0 since the public API is now stable
@@ -12,7 +24,7 @@ Bugfixes:
12
24
 
13
25
  Features:
14
26
 
15
- - New `vlcoud-logout` command line utility to revoke session tokens.
27
+ - New `vcloud-logout` command line utility to revoke session tokens.
16
28
  - New `Vcloud::Core::Fog.logout` method to revoke session tokens.
17
29
 
18
30
  ## 0.15.0 (2014-11-26)
data/README.md CHANGED
@@ -137,14 +137,19 @@ Run the default suite of tests (e.g. lint, unit, features):
137
137
 
138
138
  bundle exec rake
139
139
 
140
- Run the integration tests (slower and requires a real environment):
141
-
142
- bundle exec rake integration
143
-
144
- You need access to a suitable vCloud Director organization to run the
145
- integration tests. See the [integration tests README](/spec/integration/README.md) for
146
- further details.
147
-
140
+ There are also integration tests. These are slower and require a real environment.
141
+ See the [vCloud Tools website](http://gds-operations.github.io/vcloud-tools/testing/) for details of how to set up and run the integration tests.
142
+
143
+ The parameters required to run the vCloud Core integration tests are:
144
+
145
+ ````
146
+ default: # This is the fog credential that refers to your testing environment, e.g. `test_credential`
147
+ vdc_1_name: # The name of a VDC
148
+ catalog: # A catalog
149
+ vapp_template: # A vApp Template within that catalog
150
+ network_1: # The name of the primary network
151
+ network_1_ip: # The IP address of the primary network
152
+ ````
148
153
  ## Contributing
149
154
 
150
155
  1. Fork it
@@ -1,5 +1,5 @@
1
1
  module Vcloud
2
2
  module Core
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -1,164 +1,160 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Vcloud
4
- module Core
5
- describe ConfigLoader do
6
-
7
- before(:all) do
8
- @data_dir = File.join(File.dirname(__FILE__), "/data")
9
- end
10
-
11
- describe 'basic config loading' do
12
- it "should create a valid hash when input is JSON" do
13
- input_file = "#{@data_dir}/working.json"
14
- loader = ConfigLoader.new
15
- actual_config = loader.load_config(input_file)
16
- expect(valid_config).to eq(actual_config)
17
- end
18
-
19
- it "should create a valid hash when input is YAML" do
20
- input_file = "#{@data_dir}/working.yaml"
21
- loader = ConfigLoader.new
22
- actual_config = loader.load_config(input_file)
23
- expect(valid_config).to eq(actual_config)
24
- end
25
-
26
- it "should create a valid hash when input is YAML with anchor defaults" do
27
- input_file = "#{@data_dir}/working_with_defaults.yaml"
28
- loader = ConfigLoader.new
29
- actual_config = loader.load_config(input_file)
30
- expect(valid_config['vapps']).to eq(actual_config['vapps'])
31
- end
32
- end
33
-
34
- describe 'config loading with variable interpolation' do
35
- it "should create a valid hash when input is YAML with variable file" do
36
- input_file = "#{@data_dir}/working_template.yaml"
37
- vars_file = "#{@data_dir}/working_variables.yaml"
38
- loader = ConfigLoader.new
39
- actual_config = loader.load_config(input_file, nil, vars_file)
40
- expect(valid_config).to eq(actual_config)
41
- end
42
- end
43
-
44
- describe 'config loading with schema validation' do
45
- it "should validate correctly against a schema" do
46
- input_file = "#{@data_dir}/working_with_defaults.yaml"
47
- loader = ConfigLoader.new
48
- schema = vapp_config_schema
49
- actual_config = loader.load_config(input_file, schema)
50
- expect(valid_config['vapps']).to eq(actual_config['vapps'])
51
- end
52
-
53
- it "should raise an error if checked against an invalid schema" do
54
- input_file = "#{@data_dir}/working_with_defaults.yaml"
55
- loader = ConfigLoader.new
56
- expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
57
- expect { loader.load_config(input_file, invalid_schema) }.
58
- to raise_error('Supplied configuration does not match supplied schema')
59
- end
60
-
61
- it "should not log warnings if there are none" do
62
- input_file = "#{@data_dir}/working_with_defaults.yaml"
63
- loader = ConfigLoader.new
64
-
65
- expect(Vcloud::Core.logger).not_to receive(:warn)
66
- loader.load_config(input_file, vapp_config_schema)
67
- end
68
-
69
- it "should log warnings if checked against a deprecated schema" do
70
- input_file = "#{@data_dir}/working_with_defaults.yaml"
71
- loader = ConfigLoader.new
72
-
73
- expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
74
- loader.load_config(input_file, deprecated_schema)
75
- end
76
-
77
- it "should log warning before raising error against an invalid and deprecated schema" do
78
- input_file = "#{@data_dir}/working_with_defaults.yaml"
79
- loader = ConfigLoader.new
80
-
81
- expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
82
- expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
83
- expect { loader.load_config(input_file, invalid_and_deprecated_schema) }.
84
- to raise_error('Supplied configuration does not match supplied schema')
85
- end
86
- end
87
-
88
- def vapp_config_schema
89
- {
90
- type: 'hash',
91
- allowed_empty: false,
92
- permit_unknown_parameters: true,
93
- internals: {
94
- vapps: {
95
- type: 'array',
96
- required: false,
97
- allowed_empty: true,
98
- },
99
- }
100
- }
101
- end
102
-
103
- def invalid_schema
104
- {
105
- type: Hash,
106
- permit_unknown_parameters: true,
107
- internals: {
108
- vapps: { type: Hash },
109
- }
110
- }
111
- end
112
-
113
- def invalid_and_deprecated_schema
114
- {
115
- type: 'hash',
116
- permit_unknown_parameters: true,
117
- internals: {
118
- vapps: { type: Hash, deprecated_by: 'vapps_new' },
119
- vapps_new: { type: 'array' },
120
- }
121
- }
122
- end
123
-
124
- def deprecated_schema
125
- {
126
- type: 'hash',
127
- permit_unknown_parameters: true,
128
- internals: {
129
- vapps: { type: 'array', deprecated_by: 'vapps_new' },
130
- vapps_new: { type: 'array' },
131
- }
132
- }
133
- end
134
-
135
- def valid_config
136
- {
137
- :vapps=>[{
138
- :name=>"vapp-vcloud-tools-tests",
139
- :vdc_name=>"VDC_NAME",
140
- :catalog=>"CATALOG_NAME",
141
- :vapp_template=>"VAPP_TEMPLATE",
142
- :vm=>{
143
- :hardware_config=>{:memory=>"4096", :cpu=>"2"},
144
- :extra_disks=>[{:size=>"8192"}],
145
- :network_connections=>[{
146
- :name=>"Default",
147
- :ip_address=>"192.168.2.10"
148
- },
149
- {
150
- :name=>"NetworkTest2",
151
- :ip_address=>"192.168.1.10"
152
- }],
153
- :bootstrap=>{
154
- :script_path=>"spec/data/basic_preamble_test.erb",
155
- :vars=>{:message=>"hello world"}
156
- },
157
- :metadata=>{}
158
- }
159
- }]
160
- }
161
- end
3
+ describe Vcloud::Core::ConfigLoader do
4
+
5
+ before(:all) do
6
+ @data_dir = File.join(File.dirname(__FILE__), "/data")
7
+ end
8
+
9
+ describe 'basic config loading' do
10
+ it "should create a valid hash when input is JSON" do
11
+ input_file = "#{@data_dir}/working.json"
12
+ loader = Vcloud::Core::ConfigLoader.new
13
+ actual_config = loader.load_config(input_file)
14
+ expect(valid_config).to eq(actual_config)
15
+ end
16
+
17
+ it "should create a valid hash when input is YAML" do
18
+ input_file = "#{@data_dir}/working.yaml"
19
+ loader = Vcloud::Core::ConfigLoader.new
20
+ actual_config = loader.load_config(input_file)
21
+ expect(valid_config).to eq(actual_config)
22
+ end
23
+
24
+ it "should create a valid hash when input is YAML with anchor defaults" do
25
+ input_file = "#{@data_dir}/working_with_defaults.yaml"
26
+ loader = Vcloud::Core::ConfigLoader.new
27
+ actual_config = loader.load_config(input_file)
28
+ expect(valid_config['vapps']).to eq(actual_config['vapps'])
29
+ end
30
+ end
31
+
32
+ describe 'config loading with variable interpolation' do
33
+ it "should create a valid hash when input is YAML with variable file" do
34
+ input_file = "#{@data_dir}/working_template.yaml"
35
+ vars_file = "#{@data_dir}/working_variables.yaml"
36
+ loader = Vcloud::Core::ConfigLoader.new
37
+ actual_config = loader.load_config(input_file, nil, vars_file)
38
+ expect(valid_config).to eq(actual_config)
39
+ end
40
+ end
41
+
42
+ describe 'config loading with schema validation' do
43
+ it "should validate correctly against a schema" do
44
+ input_file = "#{@data_dir}/working_with_defaults.yaml"
45
+ loader = Vcloud::Core::ConfigLoader.new
46
+ schema = vapp_config_schema
47
+ actual_config = loader.load_config(input_file, schema)
48
+ expect(valid_config['vapps']).to eq(actual_config['vapps'])
49
+ end
50
+
51
+ it "should raise an error if checked against an invalid schema" do
52
+ input_file = "#{@data_dir}/working_with_defaults.yaml"
53
+ loader = Vcloud::Core::ConfigLoader.new
54
+ expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
55
+ expect { loader.load_config(input_file, invalid_schema) }.
56
+ to raise_error('Supplied configuration does not match supplied schema')
57
+ end
58
+
59
+ it "should not log warnings if there are none" do
60
+ input_file = "#{@data_dir}/working_with_defaults.yaml"
61
+ loader = Vcloud::Core::ConfigLoader.new
62
+
63
+ expect(Vcloud::Core.logger).not_to receive(:warn)
64
+ loader.load_config(input_file, vapp_config_schema)
162
65
  end
66
+
67
+ it "should log warnings if checked against a deprecated schema" do
68
+ input_file = "#{@data_dir}/working_with_defaults.yaml"
69
+ loader = Vcloud::Core::ConfigLoader.new
70
+
71
+ expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
72
+ loader.load_config(input_file, deprecated_schema)
73
+ end
74
+
75
+ it "should log warning before raising error against an invalid and deprecated schema" do
76
+ input_file = "#{@data_dir}/working_with_defaults.yaml"
77
+ loader = Vcloud::Core::ConfigLoader.new
78
+
79
+ expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
80
+ expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
81
+ expect { loader.load_config(input_file, invalid_and_deprecated_schema) }.
82
+ to raise_error('Supplied configuration does not match supplied schema')
83
+ end
84
+ end
85
+
86
+ def vapp_config_schema
87
+ {
88
+ type: 'hash',
89
+ allowed_empty: false,
90
+ permit_unknown_parameters: true,
91
+ internals: {
92
+ vapps: {
93
+ type: 'array',
94
+ required: false,
95
+ allowed_empty: true,
96
+ },
97
+ }
98
+ }
99
+ end
100
+
101
+ def invalid_schema
102
+ {
103
+ type: Hash,
104
+ permit_unknown_parameters: true,
105
+ internals: {
106
+ vapps: { type: Hash },
107
+ }
108
+ }
109
+ end
110
+
111
+ def invalid_and_deprecated_schema
112
+ {
113
+ type: 'hash',
114
+ permit_unknown_parameters: true,
115
+ internals: {
116
+ vapps: { type: Hash, deprecated_by: 'vapps_new' },
117
+ vapps_new: { type: 'array' },
118
+ }
119
+ }
120
+ end
121
+
122
+ def deprecated_schema
123
+ {
124
+ type: 'hash',
125
+ permit_unknown_parameters: true,
126
+ internals: {
127
+ vapps: { type: 'array', deprecated_by: 'vapps_new' },
128
+ vapps_new: { type: 'array' },
129
+ }
130
+ }
131
+ end
132
+
133
+ def valid_config
134
+ {
135
+ :vapps=>[{
136
+ :name=>"vapp-vcloud-tools-tests",
137
+ :vdc_name=>"VDC_NAME",
138
+ :catalog=>"CATALOG_NAME",
139
+ :vapp_template=>"VAPP_TEMPLATE",
140
+ :vm=>{
141
+ :hardware_config=>{:memory=>"4096", :cpu=>"2"},
142
+ :extra_disks=>[{:size=>"8192"}],
143
+ :network_connections=>[{
144
+ :name=>"Default",
145
+ :ip_address=>"192.168.2.10"
146
+ },
147
+ {
148
+ :name=>"NetworkTest2",
149
+ :ip_address=>"192.168.1.10"
150
+ }],
151
+ :bootstrap=>{
152
+ :script_path=>"spec/data/basic_preamble_test.erb",
153
+ :vars=>{:message=>"hello world"}
154
+ },
155
+ :metadata=>{}
156
+ }
157
+ }]
158
+ }
163
159
  end
164
160
  end
@@ -1,697 +1,693 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Vcloud
4
- module Core
5
- describe ConfigValidator do
3
+ describe Vcloud::Core::ConfigValidator do
6
4
 
7
- context "sanitize type" do
5
+ context "sanitize type" do
8
6
 
9
- it "should be ok with type as bare String" do
10
- data = "hello world"
11
- schema = { type: String }
12
- v = ConfigValidator.validate(:base, data, schema)
13
- expect(v.valid?).to be_true
14
- end
7
+ it "should be ok with type as bare String" do
8
+ data = "hello world"
9
+ schema = { type: String }
10
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
11
+ expect(v.valid?).to be_true
12
+ end
15
13
 
16
- it "should be ok with type as string 'String'" do
17
- data = "hello world"
18
- schema = { type: 'String' }
19
- v = ConfigValidator.validate(:base, data, schema)
20
- expect(v.valid?).to be_true
21
- end
14
+ it "should be ok with type as string 'String'" do
15
+ data = "hello world"
16
+ schema = { type: 'String' }
17
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
18
+ expect(v.valid?).to be_true
19
+ end
22
20
 
23
- it "should be ok with type as string 'string'" do
24
- data = "hello world"
25
- schema = { type: 'string' }
26
- v = ConfigValidator.validate(:base, data, schema)
27
- expect(v.valid?).to be_true
28
- end
21
+ it "should be ok with type as string 'string'" do
22
+ data = "hello world"
23
+ schema = { type: 'string' }
24
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
25
+ expect(v.valid?).to be_true
26
+ end
29
27
 
30
- end
28
+ end
31
29
 
32
- context "string validations" do
30
+ context "string validations" do
33
31
 
34
- it "should validate a basic string" do
35
- data = "hello world"
36
- schema = { type: 'string' }
37
- v = ConfigValidator.validate(:base, data, schema)
38
- expect(v.valid?).to be_true
39
- end
32
+ it "should validate a basic string" do
33
+ data = "hello world"
34
+ schema = { type: 'string' }
35
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
36
+ expect(v.valid?).to be_true
37
+ end
40
38
 
41
- it "should not validate a number as a basic string" do
42
- data = 42
43
- schema = { type: 'string' }
44
- v = ConfigValidator.validate(:base, data, schema)
45
- expect(v.valid?).to be_false
46
- end
39
+ it "should not validate a number as a basic string" do
40
+ data = 42
41
+ schema = { type: 'string' }
42
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
43
+ expect(v.valid?).to be_false
44
+ end
47
45
 
48
- it "should log error with number as a basic string" do
49
- data = 42
50
- schema = { type: 'string' }
51
- v = ConfigValidator.validate(:base, data, schema)
52
- expect(v.errors).to eq([ 'base: 42 is not a string'] )
53
- end
46
+ it "should log error with number as a basic string" do
47
+ data = 42
48
+ schema = { type: 'string' }
49
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
50
+ expect(v.errors).to eq([ 'base: 42 is not a string'] )
51
+ end
54
52
 
55
- it "should return error with empty string (by default)" do
56
- data = ""
57
- schema = { type: 'string' }
58
- v = ConfigValidator.validate(:base, data, schema)
59
- expect(v.errors).to eq([ 'base: cannot be empty string'] )
60
- end
53
+ it "should return error with empty string (by default)" do
54
+ data = ""
55
+ schema = { type: 'string' }
56
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
57
+ expect(v.errors).to eq([ 'base: cannot be empty string'] )
58
+ end
61
59
 
62
- it "should return error with empty string with allowed_empty: false)" do
63
- data = ""
64
- schema = { type: 'string', allowed_empty: false }
65
- v = ConfigValidator.validate(:base, data, schema)
66
- expect(v.errors).to eq([ 'base: cannot be empty string'] )
67
- end
60
+ it "should return error with empty string with allowed_empty: false)" do
61
+ data = ""
62
+ schema = { type: 'string', allowed_empty: false }
63
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
64
+ expect(v.errors).to eq([ 'base: cannot be empty string'] )
65
+ end
68
66
 
69
- it "should validate ok with empty string with allowed_empty: true)" do
70
- data = ""
71
- schema = { type: 'string', allowed_empty: true }
72
- v = ConfigValidator.validate(:base, data, schema)
73
- expect(v.valid?).to be_true
74
- end
67
+ it "should validate ok with empty string with allowed_empty: true)" do
68
+ data = ""
69
+ schema = { type: 'string', allowed_empty: true }
70
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
71
+ expect(v.valid?).to be_true
72
+ end
75
73
 
76
- it "should return error for nil value with allowed_empty: true)" do
77
- data = nil
78
- schema = { type: 'string', allowed_empty: true }
79
- v = ConfigValidator.validate(:base, data, schema)
80
- expect(v.errors).to eq([ 'base: is not a string'] )
81
- end
74
+ it "should return error for nil value with allowed_empty: true)" do
75
+ data = nil
76
+ schema = { type: 'string', allowed_empty: true }
77
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
78
+ expect(v.errors).to eq([ 'base: is not a string'] )
79
+ end
82
80
 
83
- it "should validate ok with a :matcher regex specified" do
84
- data = "name-1234"
85
- schema = { type: 'string', matcher: /^name-\d+$/ }
86
- v = ConfigValidator.validate(:base, data, schema)
87
- expect(v.valid?).to be_true
88
- end
81
+ it "should validate ok with a :matcher regex specified" do
82
+ data = "name-1234"
83
+ schema = { type: 'string', matcher: /^name-\d+$/ }
84
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
85
+ expect(v.valid?).to be_true
86
+ end
89
87
 
90
- it "should return errror with a :matcher regex not matching" do
91
- data = "name-123a"
92
- schema = { type: 'string', matcher: /^name-\d+$/ }
93
- v = ConfigValidator.validate(:base, data, schema)
94
- expect(v.errors).to eq(['base: name-123a does not match'])
95
- end
88
+ it "should return errror with a :matcher regex not matching" do
89
+ data = "name-123a"
90
+ schema = { type: 'string', matcher: /^name-\d+$/ }
91
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
92
+ expect(v.errors).to eq(['base: name-123a does not match'])
93
+ end
96
94
 
97
- end
95
+ end
98
96
 
99
- context "hash validations" do
100
-
101
- it "should validate a basic hash" do
102
- data = { name: "santa", address: "north pole" }
103
- schema = {
104
- type: "Hash",
105
- internals: {
106
- name: { type: 'string' },
107
- address: { type: 'string' },
108
- }
109
- }
110
- v = ConfigValidator.validate(:base, data, schema)
111
- expect(v.valid?).to be_true
112
- end
97
+ context "hash validations" do
98
+
99
+ it "should validate a basic hash" do
100
+ data = { name: "santa", address: "north pole" }
101
+ schema = {
102
+ type: "Hash",
103
+ internals: {
104
+ name: { type: 'string' },
105
+ address: { type: 'string' },
106
+ }
107
+ }
108
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
109
+ expect(v.valid?).to be_true
110
+ end
113
111
 
114
- it "should not validate a bogus hash" do
115
- data = { name: 42, address: 42 }
116
- schema = {
117
- type: "Hash",
118
- internals: {
119
- name: { type: "string" },
120
- address: { type: "string" },
121
- }
122
- }
123
- v = ConfigValidator.validate(:base, data, schema)
124
- expect(v.valid?).to be_false
125
- end
112
+ it "should not validate a bogus hash" do
113
+ data = { name: 42, address: 42 }
114
+ schema = {
115
+ type: "Hash",
116
+ internals: {
117
+ name: { type: "string" },
118
+ address: { type: "string" },
119
+ }
120
+ }
121
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
122
+ expect(v.valid?).to be_false
123
+ end
126
124
 
127
- it "should return correct errors validating a bogus hash" do
128
- data = { name: 42, address: 42 }
129
- schema = {
130
- type: "Hash",
131
- internals: {
132
- name: { type: "string" },
133
- address: { type: "string" },
134
- }
135
- }
136
- v = ConfigValidator.validate(:base, data, schema)
137
- expect(v.errors).to eq([
138
- "name: 42 is not a string",
139
- "address: 42 is not a string",
140
- ])
141
- end
125
+ it "should return correct errors validating a bogus hash" do
126
+ data = { name: 42, address: 42 }
127
+ schema = {
128
+ type: "Hash",
129
+ internals: {
130
+ name: { type: "string" },
131
+ address: { type: "string" },
132
+ }
133
+ }
134
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
135
+ expect(v.errors).to eq([
136
+ "name: 42 is not a string",
137
+ "address: 42 is not a string",
138
+ ])
139
+ end
142
140
 
143
- it "should return error with empty hash (by default)" do
144
- data = {}
145
- schema = { type: 'hash' }
146
- v = ConfigValidator.validate(:base, data, schema)
147
- expect(v.errors).to eq([ 'base: cannot be empty hash'] )
148
- end
141
+ it "should return error with empty hash (by default)" do
142
+ data = {}
143
+ schema = { type: 'hash' }
144
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
145
+ expect(v.errors).to eq([ 'base: cannot be empty hash'] )
146
+ end
149
147
 
150
- it "should return error with empty hash with allowed_empty: false)" do
151
- data = {}
152
- schema = { type: 'hash', allowed_empty: false }
153
- v = ConfigValidator.validate(:base, data, schema)
154
- expect(v.errors).to eq([ 'base: cannot be empty hash'] )
155
- end
148
+ it "should return error with empty hash with allowed_empty: false)" do
149
+ data = {}
150
+ schema = { type: 'hash', allowed_empty: false }
151
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
152
+ expect(v.errors).to eq([ 'base: cannot be empty hash'] )
153
+ end
156
154
 
157
- it "should validate ok with empty hash with allowed_empty: true)" do
158
- data = {}
159
- schema = { type: 'hash', allowed_empty: true }
160
- v = ConfigValidator.validate(:base, data, schema)
161
- expect(v.valid?).to be_true
162
- end
155
+ it "should validate ok with empty hash with allowed_empty: true)" do
156
+ data = {}
157
+ schema = { type: 'hash', allowed_empty: true }
158
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
159
+ expect(v.valid?).to be_true
160
+ end
163
161
 
164
- it "should validate ok with a missing parameter, when marked :required => false" do
165
- data = {
166
- name: 'hello'
167
- }
168
- schema = {
169
- type: 'hash',
170
- internals: {
171
- name: { type: 'string' },
172
- optional_param: { type: 'string', required: false },
173
- }
174
- }
175
- v = ConfigValidator.validate(:base, data, schema)
176
- expect(v.valid?).to be_true
177
- end
162
+ it "should validate ok with a missing parameter, when marked :required => false" do
163
+ data = {
164
+ name: 'hello'
165
+ }
166
+ schema = {
167
+ type: 'hash',
168
+ internals: {
169
+ name: { type: 'string' },
170
+ optional_param: { type: 'string', required: false },
171
+ }
172
+ }
173
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
174
+ expect(v.valid?).to be_true
175
+ end
178
176
 
179
- it "should return error with a missing :required => true param" do
180
- data = {
181
- name: 'hello'
182
- }
183
- schema = {
184
- type: 'hash',
185
- internals: {
186
- name: { type: 'string' },
187
- not_optional_param: { type: 'string', required: true },
188
- }
189
- }
190
- v = ConfigValidator.validate(:base, data, schema)
191
- expect(v.errors).to eq(["base: missing 'not_optional_param' parameter"])
192
- end
177
+ it "should return error with a missing :required => true param" do
178
+ data = {
179
+ name: 'hello'
180
+ }
181
+ schema = {
182
+ type: 'hash',
183
+ internals: {
184
+ name: { type: 'string' },
185
+ not_optional_param: { type: 'string', required: true },
186
+ }
187
+ }
188
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
189
+ expect(v.errors).to eq(["base: missing 'not_optional_param' parameter"])
190
+ end
193
191
 
194
- it "should return error if a bogus parameter is specified" do
195
- data = {
196
- name: 'hello',
197
- bogus_parameter: [ 'wibble' ],
198
- bogus_parameter2: 'hello',
199
- }
200
- schema = {
201
- type: 'hash',
202
- internals: {
203
- name: { type: 'string' },
204
- },
205
- }
206
- v = ConfigValidator.validate(:base, data, schema)
207
- expect(v.errors).to eq([
208
- "base: parameter 'bogus_parameter' is invalid",
209
- "base: parameter 'bogus_parameter2' is invalid",
210
- ])
211
- end
192
+ it "should return error if a bogus parameter is specified" do
193
+ data = {
194
+ name: 'hello',
195
+ bogus_parameter: [ 'wibble' ],
196
+ bogus_parameter2: 'hello',
197
+ }
198
+ schema = {
199
+ type: 'hash',
200
+ internals: {
201
+ name: { type: 'string' },
202
+ },
203
+ }
204
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
205
+ expect(v.errors).to eq([
206
+ "base: parameter 'bogus_parameter' is invalid",
207
+ "base: parameter 'bogus_parameter2' is invalid",
208
+ ])
209
+ end
212
210
 
213
- it "should validate ok if a bogus parameter is specified, when :permit_unknown_parameters is true" do
214
- data = {
215
- name: 'hello',
216
- bogus_parameter: [ 'wibble' ],
217
- bogus_parameter2: 'hello',
218
- }
219
- schema = {
220
- type: 'hash',
221
- permit_unknown_parameters: true,
222
- internals: {
223
- name: { type: 'string' },
224
- },
225
- }
226
- v = ConfigValidator.validate(:base, data, schema)
227
- expect(v.valid?).to be_true
228
- end
211
+ it "should validate ok if a bogus parameter is specified, when :permit_unknown_parameters is true" do
212
+ data = {
213
+ name: 'hello',
214
+ bogus_parameter: [ 'wibble' ],
215
+ bogus_parameter2: 'hello',
216
+ }
217
+ schema = {
218
+ type: 'hash',
219
+ permit_unknown_parameters: true,
220
+ internals: {
221
+ name: { type: 'string' },
222
+ },
223
+ }
224
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
225
+ expect(v.valid?).to be_true
226
+ end
229
227
 
230
- end
228
+ end
231
229
 
232
- context "array validations" do
230
+ context "array validations" do
233
231
 
234
- it "should validate a basic array" do
235
- data = [ "santa", "north pole" ]
236
- schema = {
237
- type: "Array",
238
- each_element_is: { type: "string" }
239
- }
240
- v = ConfigValidator.validate(:base, data, schema)
241
- expect(v.valid?).to be_true
242
- end
232
+ it "should validate a basic array" do
233
+ data = [ "santa", "north pole" ]
234
+ schema = {
235
+ type: "Array",
236
+ each_element_is: { type: "string" }
237
+ }
238
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
239
+ expect(v.valid?).to be_true
240
+ end
243
241
 
244
- it "should validate a bogus array" do
245
- data = [ 42, 43 ]
246
- schema = {
247
- type: "Array",
248
- each_element_is: { type: "string" }
249
- }
250
- v = ConfigValidator.validate(:base, data, schema)
251
- expect(v.valid?).to be_false
252
- end
242
+ it "should validate a bogus array" do
243
+ data = [ 42, 43 ]
244
+ schema = {
245
+ type: "Array",
246
+ each_element_is: { type: "string" }
247
+ }
248
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
249
+ expect(v.valid?).to be_false
250
+ end
253
251
 
254
- it "should return correct errors validating a bogus array" do
255
- data = [ 42, 43 ]
256
- schema = {
257
- type: "Array",
258
- each_element_is: { type: "string" }
259
- }
260
- v = ConfigValidator.validate(:base, data, schema)
261
- expect(v.errors).to eq([
262
- "base: 42 is not a string",
263
- "base: 43 is not a string",
264
- ])
265
- end
252
+ it "should return correct errors validating a bogus array" do
253
+ data = [ 42, 43 ]
254
+ schema = {
255
+ type: "Array",
256
+ each_element_is: { type: "string" }
257
+ }
258
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
259
+ expect(v.errors).to eq([
260
+ "base: 42 is not a string",
261
+ "base: 43 is not a string",
262
+ ])
263
+ end
266
264
 
267
- it "should return error with empty array (by default)" do
268
- data = []
269
- schema = { type: 'array' }
270
- v = ConfigValidator.validate(:base, data, schema)
271
- expect(v.errors).to eq([ 'base: cannot be empty array'] )
272
- end
265
+ it "should return error with empty array (by default)" do
266
+ data = []
267
+ schema = { type: 'array' }
268
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
269
+ expect(v.errors).to eq([ 'base: cannot be empty array'] )
270
+ end
273
271
 
274
- it "should return error with empty array with allowed_empty: false)" do
275
- data = []
276
- schema = { type: 'array', allowed_empty: false }
277
- v = ConfigValidator.validate(:base, data, schema)
278
- expect(v.errors).to eq([ 'base: cannot be empty array'] )
279
- end
272
+ it "should return error with empty array with allowed_empty: false)" do
273
+ data = []
274
+ schema = { type: 'array', allowed_empty: false }
275
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
276
+ expect(v.errors).to eq([ 'base: cannot be empty array'] )
277
+ end
280
278
 
281
- it "should validate ok with empty array with allowed_empty: true)" do
282
- data = []
283
- schema = { type: 'array', allowed_empty: true }
284
- v = ConfigValidator.validate(:base, data, schema)
285
- expect(v.valid?).to be_true
286
- end
279
+ it "should validate ok with empty array with allowed_empty: true)" do
280
+ data = []
281
+ schema = { type: 'array', allowed_empty: true }
282
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
283
+ expect(v.valid?).to be_true
284
+ end
287
285
 
288
- end
286
+ end
289
287
 
290
- context "array of hashes validations" do
291
-
292
- it "should validate an array of hashes" do
293
- data = [
294
- { name: "santa", address: "north pole" },
295
- { name: "mole", address: "1 hole street" },
296
- ]
297
- schema = {
298
- type: "array",
299
- each_element_is: {
300
- type: "hash",
301
- internals: {
302
- name: { type: 'string' },
303
- address: { type: 'string' },
304
- }
305
- }
306
- }
307
- v = ConfigValidator.validate(:base, data, schema)
308
- expect(v.valid?).to be_true
309
- end
288
+ context "array of hashes validations" do
289
+
290
+ it "should validate an array of hashes" do
291
+ data = [
292
+ { name: "santa", address: "north pole" },
293
+ { name: "mole", address: "1 hole street" },
294
+ ]
295
+ schema = {
296
+ type: "array",
297
+ each_element_is: {
298
+ type: "hash",
299
+ internals: {
300
+ name: { type: 'string' },
301
+ address: { type: 'string' },
302
+ }
303
+ }
304
+ }
305
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
306
+ expect(v.valid?).to be_true
307
+ end
310
308
 
311
- it "should correctly error on an invalid an array of hashes" do
312
- data = [
313
- { name: "santa", address: [] },
314
- { name: 43, address: "1 hole street" },
315
- ]
316
- schema = {
317
- type: "array",
318
- each_element_is: {
319
- type: "hash",
320
- internals: {
321
- name: { type: 'string' },
322
- address: { type: 'string' },
323
- }
324
- }
325
- }
326
- v = ConfigValidator.validate(:base, data, schema)
327
- expect(v.errors).to eq([
328
- "address: [] is not a string",
329
- "name: 43 is not a string",
330
- ])
331
- end
309
+ it "should correctly error on an invalid an array of hashes" do
310
+ data = [
311
+ { name: "santa", address: [] },
312
+ { name: 43, address: "1 hole street" },
313
+ ]
314
+ schema = {
315
+ type: "array",
316
+ each_element_is: {
317
+ type: "hash",
318
+ internals: {
319
+ name: { type: 'string' },
320
+ address: { type: 'string' },
321
+ }
322
+ }
323
+ }
324
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
325
+ expect(v.errors).to eq([
326
+ "address: [] is not a string",
327
+ "name: 43 is not a string",
328
+ ])
329
+ end
332
330
 
333
- end
331
+ end
334
332
 
335
- context "hash of arrays validations" do
336
-
337
- it "should validate a hash of arrays" do
338
- data = {
339
- boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
340
- girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
341
- }
342
- schema = {
343
- type: "Hash",
344
- internals: {
345
- boys_names: {
346
- type: "Array",
347
- each_element_is: { type: 'String' }
348
- },
349
- girls_names: {
350
- type: "Array",
351
- each_element_is: { type: 'String' }
352
- }
353
- }
354
- }
355
- v = ConfigValidator.validate(:base, data, schema)
356
- expect(v.valid?).to be_true
357
- end
333
+ context "hash of arrays validations" do
334
+
335
+ it "should validate a hash of arrays" do
336
+ data = {
337
+ boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
338
+ girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
339
+ }
340
+ schema = {
341
+ type: "Hash",
342
+ internals: {
343
+ boys_names: {
344
+ type: "Array",
345
+ each_element_is: { type: 'String' }
346
+ },
347
+ girls_names: {
348
+ type: "Array",
349
+ each_element_is: { type: 'String' }
350
+ }
351
+ }
352
+ }
353
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
354
+ expect(v.valid?).to be_true
355
+ end
358
356
 
359
- it "should correctly error on an invalid hash of arrays" do
360
- data = {
361
- boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
362
- girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
363
- }
364
- schema = {
365
- type: "Hash",
366
- internals: {
367
- boys_names: {
368
- type: "Array",
369
- each_element_is: { type: 'String' },
370
- },
371
- girls_names: {
372
- type: "Array",
373
- each_element_is: { type: 'String' },
374
- }
375
- },
376
- }
377
- v = ConfigValidator.validate(:base, data, schema)
378
- expect(v.valid?).to be_true
379
- end
357
+ it "should correctly error on an invalid hash of arrays" do
358
+ data = {
359
+ boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
360
+ girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
361
+ }
362
+ schema = {
363
+ type: "Hash",
364
+ internals: {
365
+ boys_names: {
366
+ type: "Array",
367
+ each_element_is: { type: 'String' },
368
+ },
369
+ girls_names: {
370
+ type: "Array",
371
+ each_element_is: { type: 'String' },
372
+ }
373
+ },
374
+ }
375
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
376
+ expect(v.valid?).to be_true
377
+ end
380
378
 
381
- end
379
+ end
382
380
 
383
- context "string_or_number validations" do
381
+ context "string_or_number validations" do
384
382
 
385
- it "should correctly validate an Integer" do
386
- data = 2
387
- schema = { type: 'string_or_number' }
388
- v = ConfigValidator.validate(:base, data, schema)
389
- expect(v.valid?).to be_true
390
- end
383
+ it "should correctly validate an Integer" do
384
+ data = 2
385
+ schema = { type: 'string_or_number' }
386
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
387
+ expect(v.valid?).to be_true
388
+ end
391
389
 
392
- it "should correctly validate a String" do
393
- data = '2'
394
- schema = { type: 'string_or_number' }
395
- v = ConfigValidator.validate(:base, data, schema)
396
- expect(v.valid?).to be_true
397
- end
390
+ it "should correctly validate a String" do
391
+ data = '2'
392
+ schema = { type: 'string_or_number' }
393
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
394
+ expect(v.valid?).to be_true
395
+ end
398
396
 
399
- it "should correctly error if not a string or numeric" do
400
- data = []
401
- schema = { type: 'string_or_number' }
402
- v = ConfigValidator.validate(:base, data, schema)
403
- expect(v.errors).to eq(["base: [] is not a string_or_number"])
404
- end
397
+ it "should correctly error if not a string or numeric" do
398
+ data = []
399
+ schema = { type: 'string_or_number' }
400
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
401
+ expect(v.errors).to eq(["base: [] is not a string_or_number"])
402
+ end
405
403
 
406
- end
404
+ end
407
405
 
408
- context "ip_address validations" do
406
+ context "ip_address validations" do
409
407
 
410
- it "should correctly validate an IP address" do
411
- data = '192.168.100.100'
412
- schema = { type: 'ip_address' }
413
- v = ConfigValidator.validate(:base, data, schema)
414
- expect(v.valid?).to be_true
415
- end
408
+ it "should correctly validate an IP address" do
409
+ data = '192.168.100.100'
410
+ schema = { type: 'ip_address' }
411
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
412
+ expect(v.valid?).to be_true
413
+ end
416
414
 
417
- it "should correctly error on an invalid IP address" do
418
- data = '256.168.100.100'
419
- schema = { type: 'ip_address' }
420
- v = ConfigValidator.validate(:base, data, schema)
421
- expect(v.errors).to eq(['base: 256.168.100.100 is not a valid ip_address'])
422
- end
415
+ it "should correctly error on an invalid IP address" do
416
+ data = '256.168.100.100'
417
+ schema = { type: 'ip_address' }
418
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
419
+ expect(v.errors).to eq(['base: 256.168.100.100 is not a valid ip_address'])
420
+ end
423
421
 
424
- it "should error if ip address have wrong octets" do
425
- data = '192.168.100.100/33/33/33'
426
- schema = { type: 'ip_address' }
427
- v = ConfigValidator.validate(:base, data, schema)
428
- expect(v.errors).to eq(['base: 192.168.100.100/33/33/33 is not a valid ip_address'])
429
- end
422
+ it "should error if ip address have wrong octets" do
423
+ data = '192.168.100.100/33/33/33'
424
+ schema = { type: 'ip_address' }
425
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
426
+ expect(v.errors).to eq(['base: 192.168.100.100/33/33/33 is not a valid ip_address'])
427
+ end
430
428
 
429
+ end
430
+
431
+ context "ip_address_range validations" do
432
+ context "validate CIDR" do
433
+ it "should validate OK if CIDR is correct" do
434
+ data = '192.168.100.100/24'
435
+ schema = { type: 'ip_address_range' }
436
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
437
+ expect(v.valid?).to be_true
431
438
  end
432
439
 
433
- context "ip_address_range validations" do
434
- context "validate CIDR" do
435
- it "should validate OK if CIDR is correct" do
436
- data = '192.168.100.100/24'
437
- schema = { type: 'ip_address_range' }
438
- v = ConfigValidator.validate(:base, data, schema)
439
- expect(v.valid?).to be_true
440
- end
441
-
442
- it "should return error if network bit value is greater than 32" do
443
- data = '192.168.100.100/33'
444
- schema = { type: 'ip_address_range' }
445
- v = ConfigValidator.validate(:base, data, schema)
446
- expect(v.valid?).to be_false
447
- expect(v.errors).to eq(["base: 192.168.100.100/33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
448
- end
449
-
450
- it "should return error if network bit value is less than 0" do
451
- data = '192.168.100.100/33'
452
- schema = { type: 'ip_address_range' }
453
- v = ConfigValidator.validate(:base, data, schema)
454
- expect(v.valid?).to be_false
455
- expect(v.errors).to eq(["base: 192.168.100.100/33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
456
- end
457
-
458
- it "should return error if network IP address is incorrect" do
459
- data = '192.168.100./33'
460
- schema = { type: 'ip_address_range' }
461
- v = ConfigValidator.validate(:base, data, schema)
462
- expect(v.valid?).to be_false
463
- expect(v.errors).to eq(["base: 192.168.100./33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
464
- end
465
- end
440
+ it "should return error if network bit value is greater than 32" do
441
+ data = '192.168.100.100/33'
442
+ schema = { type: 'ip_address_range' }
443
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
444
+ expect(v.valid?).to be_false
445
+ expect(v.errors).to eq(["base: 192.168.100.100/33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
446
+ end
466
447
 
467
- context "validate alphabetical values for IP range" do
468
- %w(Any internal external).each do |data|
469
- it "should validate OK if IP range is '#{data}'" do
470
- schema = { type: 'ip_address_range' }
471
- v = ConfigValidator.validate(:base, data, schema)
472
- expect(v.valid?).to be_true
473
- expect(v.errors).to be_empty
474
- end
475
- end
476
-
477
- it "should error if IP range is a string but not a valid alphabetical value" do
478
- data = 'invalid_ip_range_string'
479
- schema = { type: 'ip_address_range' }
480
- v = ConfigValidator.validate(:base, data, schema)
481
- expect(v.valid?).to be_false
482
- expect(v.errors).to eq(["base: invalid_ip_range_string is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
483
- end
484
- end
448
+ it "should return error if network bit value is less than 0" do
449
+ data = '192.168.100.100/33'
450
+ schema = { type: 'ip_address_range' }
451
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
452
+ expect(v.valid?).to be_false
453
+ expect(v.errors).to eq(["base: 192.168.100.100/33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
454
+ end
485
455
 
486
- context "validate ranges specified using start and end addresses" do
487
- it "should validate ok if the combination of start IP and end IP is correct" do
488
- data = '192.168.100.100-192.168.100.110'
489
- schema = { type: 'ip_address_range' }
490
- v = ConfigValidator.validate(:base, data, schema)
491
- expect(v.valid?).to be_true
492
- expect(v.errors).to be_empty
493
- end
494
-
495
- it "should error if start IP address is incorrect" do
496
- data = '192.168.100-192.168.100.110'
497
- schema = { type: 'ip_address_range' }
498
- v = ConfigValidator.validate(:base, data, schema)
499
- expect(v.valid?).to be_false
500
- expect(v.errors).to eq(["base: 192.168.100-192.168.100.110 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
501
- end
502
-
503
- it "should error if end IP address is incorrect" do
504
- data = '192.168.100.110-192.168.100'
505
- schema = { type: 'ip_address_range' }
506
- v = ConfigValidator.validate(:base, data, schema)
507
- expect(v.valid?).to be_false
508
- expect(v.errors).to eq(["base: 192.168.100.110-192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
509
- end
510
-
511
- it "should error if the combination of start IP and end IP is incorrect" do
512
- data = '200.168.100.99-192.168.100'
513
- schema = { type: 'ip_address_range' }
514
- v = ConfigValidator.validate(:base, data, schema)
515
- expect(v.valid?).to be_false
516
- expect(v.errors).to eq(["base: 200.168.100.99-192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
517
- end
518
-
519
- it "should error if the start and end IPS are not separated by -" do
520
- data = '190.168.100.99:192.168.100'
521
- schema = { type: 'ip_address_range' }
522
- v = ConfigValidator.validate(:base, data, schema)
523
- expect(v.valid?).to be_false
524
- expect(v.errors).to eq(["base: 190.168.100.99:192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
525
- end
526
- end
456
+ it "should return error if network IP address is incorrect" do
457
+ data = '192.168.100./33'
458
+ schema = { type: 'ip_address_range' }
459
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
460
+ expect(v.valid?).to be_false
461
+ expect(v.errors).to eq(["base: 192.168.100./33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
462
+ end
463
+ end
527
464
 
528
- it "should accept single ip address as range" do
529
- data = '190.168.100.99'
465
+ context "validate alphabetical values for IP range" do
466
+ %w(Any internal external).each do |data|
467
+ it "should validate OK if IP range is '#{data}'" do
530
468
  schema = { type: 'ip_address_range' }
531
- v = ConfigValidator.validate(:base, data, schema)
469
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
532
470
  expect(v.valid?).to be_true
533
- expect(v.errors).to eq([])
471
+ expect(v.errors).to be_empty
534
472
  end
535
473
  end
536
474
 
537
- context "enum validations" do
538
- it "should error if enum value is not present in list" do
539
- data = 'blah'
540
- schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
541
- v = ConfigValidator.validate(:base, data, schema)
542
- expect(v.errors).to eq(["base: blah is not a valid value. Acceptable values are 'allow', 'decline', 'none'."])
543
- end
475
+ it "should error if IP range is a string but not a valid alphabetical value" do
476
+ data = 'invalid_ip_range_string'
477
+ schema = { type: 'ip_address_range' }
478
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
479
+ expect(v.valid?).to be_false
480
+ expect(v.errors).to eq(["base: invalid_ip_range_string is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
481
+ end
482
+ end
544
483
 
545
- it "should raise error if enum schema does not contain acceptable_values" do
546
- data = 'blah'
547
- schema = { type: 'enum', required: false}
548
- expect{ ConfigValidator.validate(:base, data, schema) }.to raise_error("Must set :acceptable_values for type 'enum'")
549
- end
484
+ context "validate ranges specified using start and end addresses" do
485
+ it "should validate ok if the combination of start IP and end IP is correct" do
486
+ data = '192.168.100.100-192.168.100.110'
487
+ schema = { type: 'ip_address_range' }
488
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
489
+ expect(v.valid?).to be_true
490
+ expect(v.errors).to be_empty
491
+ end
550
492
 
551
- it "should validate ok if enum is acceptable" do
552
- data = 'allow'
553
- schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
554
- v = ConfigValidator.validate(:base, data, schema)
555
- expect(v.valid?).to be_true
556
- end
493
+ it "should error if start IP address is incorrect" do
494
+ data = '192.168.100-192.168.100.110'
495
+ schema = { type: 'ip_address_range' }
496
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
497
+ expect(v.valid?).to be_false
498
+ expect(v.errors).to eq(["base: 192.168.100-192.168.100.110 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
557
499
  end
558
500
 
559
- context "boolean validations" do
560
- it "should error if boolean value is not valid" do
561
- data = 'blah'
562
- schema = { type: 'boolean' }
563
- v = ConfigValidator.validate(:base, data, schema)
564
- expect(v.errors).to eq(["base: blah is not a valid boolean value."])
565
- end
501
+ it "should error if end IP address is incorrect" do
502
+ data = '192.168.100.110-192.168.100'
503
+ schema = { type: 'ip_address_range' }
504
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
505
+ expect(v.valid?).to be_false
506
+ expect(v.errors).to eq(["base: 192.168.100.110-192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
507
+ end
566
508
 
567
- [true, false].each do |boolean_value|
568
- it "should validate ok if value is #{boolean_value}" do
569
- schema = { type: 'boolean' }
570
- v = ConfigValidator.validate(:base, boolean_value, schema)
571
- expect(v.valid?).to be_true
572
- end
573
- end
509
+ it "should error if the combination of start IP and end IP is incorrect" do
510
+ data = '200.168.100.99-192.168.100'
511
+ schema = { type: 'ip_address_range' }
512
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
513
+ expect(v.valid?).to be_false
514
+ expect(v.errors).to eq(["base: 200.168.100.99-192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
574
515
  end
575
516
 
576
- context "deprecated_by" do
577
- # For clarification:
578
- #
579
- # - deprecatee: is the old param with a `deprecated_by` field.
580
- # - deprecator: is the new param listed in the `deprecated_by` field.
581
- #
582
- context "deprecatee is provided and deprecator is not" do
583
- let(:data) {{ name: "santa" }}
584
-
585
- it "should validate and warn when deprecator is required" do
586
- schema = {
587
- type: "Hash",
588
- internals: {
589
- name: { type: 'string', deprecated_by: 'full_name' },
590
- full_name: { type: 'string', required: true },
591
- }
592
- }
593
- v = ConfigValidator.validate(:base, data, schema)
594
- expect(v.valid?).to be_true
595
- expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
596
- end
597
-
598
- it "should validate and warn when deprecator appears before deprecatee in schema" do
599
- schema = {
600
- type: "Hash",
601
- internals: {
602
- full_name: { type: 'string', required: true },
603
- name: { type: 'string', deprecated_by: 'full_name' },
604
- }
605
- }
606
- v = ConfigValidator.validate(:base, data, schema)
607
- expect(v.valid?).to be_true
608
- expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
609
- end
610
-
611
- it "should warn about deprecatee even when both are not required" do
612
- schema = {
613
- type: "Hash",
614
- internals: {
615
- name: { type: 'string', required: false, deprecated_by: 'full_name' },
616
- full_name: { type: 'string', required: false },
617
- }
618
- }
619
- v = ConfigValidator.validate(:base, data, schema)
620
- expect(v.valid?).to be_true
621
- expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
622
- end
623
- end
517
+ it "should error if the start and end IPS are not separated by -" do
518
+ data = '190.168.100.99:192.168.100'
519
+ schema = { type: 'ip_address_range' }
520
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
521
+ expect(v.valid?).to be_false
522
+ expect(v.errors).to eq(["base: 190.168.100.99:192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
523
+ end
524
+ end
624
525
 
625
- context "neither deprecatee or deprecator are provided" do
626
- let(:data) {{ bogus: "blah" }}
627
-
628
- it "should return error for deprecator but not deprecatee if neither are set" do
629
- schema = {
630
- type: "Hash",
631
- internals: {
632
- name: { type: 'string', deprecated_by: 'full_name' },
633
- full_name: { type: 'string', required: true },
634
- bogus: { type: 'string' },
635
- }
636
- }
637
- v = ConfigValidator.validate(:base, data, schema)
638
- expect(v.valid?).to be_false
639
- expect(v.errors).to eq(["base: missing 'full_name' parameter"])
640
- end
641
-
642
- it "should raise exception if deprecator does not exist in schema" do
643
- schema = {
644
- type: "Hash",
645
- internals: {
646
- name: { type: 'string', deprecated_by: 'does_not_exist' },
647
- bogus: { type: 'string' },
648
- }
649
- }
650
- expect {
651
- ConfigValidator.validate(:base, data, schema)
652
- }.to raise_error("name: deprecated_by target 'does_not_exist' not found in schema")
653
- end
654
- end
526
+ it "should accept single ip address as range" do
527
+ data = '190.168.100.99'
528
+ schema = { type: 'ip_address_range' }
529
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
530
+ expect(v.valid?).to be_true
531
+ expect(v.errors).to eq([])
532
+ end
533
+ end
655
534
 
656
- context "deprecatee and deprecator are provided and of the wrong type" do
657
- let(:data) {{ name: 123, full_name: 123 }}
658
-
659
- it "should return an error for each and a warning for deprecatee" do
660
- schema = {
661
- type: "Hash",
662
- internals: {
663
- name: { type: 'string', deprecated_by: 'full_name' },
664
- full_name: { type: 'string', required: true },
665
- }
666
- }
667
- v = ConfigValidator.validate(:base, data, schema)
668
- expect(v.valid?).to be_false
669
- expect(v.errors).to eq([
670
- "name: 123 is not a string",
671
- "full_name: 123 is not a string",
672
- ])
673
- expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
674
- end
675
- end
535
+ context "enum validations" do
536
+ it "should error if enum value is not present in list" do
537
+ data = 'blah'
538
+ schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
539
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
540
+ expect(v.errors).to eq(["base: blah is not a valid value. Acceptable values are 'allow', 'decline', 'none'."])
541
+ end
676
542
 
677
- it "should not honour deprecation across nested structures" do
678
- data = { bogus: "blah" }
679
- schema = {
680
- type: "Hash",
681
- internals: {
682
- name: { type: 'string', deprecated_by: 'full_name' },
683
- nested: { type: 'hash', internals: {
684
- full_name: { type: 'string', required: true },
685
- }},
686
- bogus: { type: 'string' },
687
- }
688
- }
689
- expect {
690
- ConfigValidator.validate(:base, data, schema)
691
- }.to raise_error("name: deprecated_by target 'full_name' not found in schema")
692
- end
543
+ it "should raise error if enum schema does not contain acceptable_values" do
544
+ data = 'blah'
545
+ schema = { type: 'enum', required: false}
546
+ expect{ Vcloud::Core::ConfigValidator.validate(:base, data, schema) }.to raise_error("Must set :acceptable_values for type 'enum'")
547
+ end
548
+
549
+ it "should validate ok if enum is acceptable" do
550
+ data = 'allow'
551
+ schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
552
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
553
+ expect(v.valid?).to be_true
554
+ end
555
+ end
556
+
557
+ context "boolean validations" do
558
+ it "should error if boolean value is not valid" do
559
+ data = 'blah'
560
+ schema = { type: 'boolean' }
561
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
562
+ expect(v.errors).to eq(["base: blah is not a valid boolean value."])
563
+ end
564
+
565
+ [true, false].each do |boolean_value|
566
+ it "should validate ok if value is #{boolean_value}" do
567
+ schema = { type: 'boolean' }
568
+ v = Vcloud::Core::ConfigValidator.validate(:base, boolean_value, schema)
569
+ expect(v.valid?).to be_true
570
+ end
571
+ end
572
+ end
573
+
574
+ context "deprecated_by" do
575
+ # For clarification:
576
+ #
577
+ # - deprecatee: is the old param with a `deprecated_by` field.
578
+ # - deprecator: is the new param listed in the `deprecated_by` field.
579
+ #
580
+ context "deprecatee is provided and deprecator is not" do
581
+ let(:data) {{ name: "santa" }}
582
+
583
+ it "should validate and warn when deprecator is required" do
584
+ schema = {
585
+ type: "Hash",
586
+ internals: {
587
+ name: { type: 'string', deprecated_by: 'full_name' },
588
+ full_name: { type: 'string', required: true },
589
+ }
590
+ }
591
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
592
+ expect(v.valid?).to be_true
593
+ expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
594
+ end
595
+
596
+ it "should validate and warn when deprecator appears before deprecatee in schema" do
597
+ schema = {
598
+ type: "Hash",
599
+ internals: {
600
+ full_name: { type: 'string', required: true },
601
+ name: { type: 'string', deprecated_by: 'full_name' },
602
+ }
603
+ }
604
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
605
+ expect(v.valid?).to be_true
606
+ expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
607
+ end
608
+
609
+ it "should warn about deprecatee even when both are not required" do
610
+ schema = {
611
+ type: "Hash",
612
+ internals: {
613
+ name: { type: 'string', required: false, deprecated_by: 'full_name' },
614
+ full_name: { type: 'string', required: false },
615
+ }
616
+ }
617
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
618
+ expect(v.valid?).to be_true
619
+ expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
693
620
  end
621
+ end
622
+
623
+ context "neither deprecatee or deprecator are provided" do
624
+ let(:data) {{ bogus: "blah" }}
625
+
626
+ it "should return error for deprecator but not deprecatee if neither are set" do
627
+ schema = {
628
+ type: "Hash",
629
+ internals: {
630
+ name: { type: 'string', deprecated_by: 'full_name' },
631
+ full_name: { type: 'string', required: true },
632
+ bogus: { type: 'string' },
633
+ }
634
+ }
635
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
636
+ expect(v.valid?).to be_false
637
+ expect(v.errors).to eq(["base: missing 'full_name' parameter"])
638
+ end
639
+
640
+ it "should raise exception if deprecator does not exist in schema" do
641
+ schema = {
642
+ type: "Hash",
643
+ internals: {
644
+ name: { type: 'string', deprecated_by: 'does_not_exist' },
645
+ bogus: { type: 'string' },
646
+ }
647
+ }
648
+ expect {
649
+ Vcloud::Core::ConfigValidator.validate(:base, data, schema)
650
+ }.to raise_error("name: deprecated_by target 'does_not_exist' not found in schema")
651
+ end
652
+ end
694
653
 
654
+ context "deprecatee and deprecator are provided and of the wrong type" do
655
+ let(:data) {{ name: 123, full_name: 123 }}
656
+
657
+ it "should return an error for each and a warning for deprecatee" do
658
+ schema = {
659
+ type: "Hash",
660
+ internals: {
661
+ name: { type: 'string', deprecated_by: 'full_name' },
662
+ full_name: { type: 'string', required: true },
663
+ }
664
+ }
665
+ v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
666
+ expect(v.valid?).to be_false
667
+ expect(v.errors).to eq([
668
+ "name: 123 is not a string",
669
+ "full_name: 123 is not a string",
670
+ ])
671
+ expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
672
+ end
673
+ end
674
+
675
+ it "should not honour deprecation across nested structures" do
676
+ data = { bogus: "blah" }
677
+ schema = {
678
+ type: "Hash",
679
+ internals: {
680
+ name: { type: 'string', deprecated_by: 'full_name' },
681
+ nested: { type: 'hash', internals: {
682
+ full_name: { type: 'string', required: true },
683
+ }},
684
+ bogus: { type: 'string' },
685
+ }
686
+ }
687
+ expect {
688
+ Vcloud::Core::ConfigValidator.validate(:base, data, schema)
689
+ }.to raise_error("name: deprecated_by target 'full_name' not found in schema")
695
690
  end
696
691
  end
692
+
697
693
  end