Skip to content

Commit

Permalink
Allow 'networks' attribute to be a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi authored and Sharpie committed Jul 31, 2016
1 parent c17d097 commit e023259
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions source/lib/vagrant-openstack-provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def merge(other)
# Let user inputs a string or an array for floating ip pool attribute
obj.floating_ip_pool = [obj.floating_ip_pool].flatten if key.eql?(:@floating_ip_pool) && !obj.floating_ip_pool.nil?

# Let user inputs a string or an array for networks attribute
obj.networks = [obj.networks].flatten if key.eql?(:@networks) && !obj.networks.nil?

# Don't set the value if it is the unset value, either.
value = obj.instance_variable_get(key)

Expand Down
32 changes: 29 additions & 3 deletions source/spec/vagrant-openstack-provider/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

subject { foo_class.new }

context 'with original network not empty' do
context 'with original network not empty array' do
it 'should overidde the config' do
one = foo_class.new
one.networks = ['foo']
Expand All @@ -88,7 +88,7 @@
end
end

context 'with original network empty' do
context 'with original network empty array' do
it 'should add the network to the existing list' do
one = foo_class.new
one.networks = []
Expand All @@ -101,7 +101,7 @@
end
end

context 'with original network not empty and new empty' do
context 'with original network not empty array and new empty array' do
it 'should keep the original network' do
one = foo_class.new
one.networks = ['foo']
Expand All @@ -114,6 +114,32 @@
end
end

context 'with original network is a string and new empty array' do
it 'should keep the original network and wrap it into an array' do
one = foo_class.new
one.networks = 'foo'

two = foo_class.new
two.networks = []

result = one.merge(two)
result.networks.should =~ ['foo']
end
end

context 'with original network is a string and new is a string' do
it 'should overidde the config and wrap it into an array' do
one = foo_class.new
one.networks = 'foo'

two = foo_class.new
two.networks = 'bar'

result = one.merge(two)
result.networks.should =~ ['bar']
end
end

context 'with original floating_ip_pool as string' do
context 'and new as empty array' do
it 'should put original string in a single entry array' do
Expand Down

0 comments on commit e023259

Please sign in to comment.