]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_endpoint / openstack_spec.rb
diff --git a/3rdparty/modules/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb b/3rdparty/modules/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb
new file mode 100644 (file)
index 0000000..a0ac752
--- /dev/null
@@ -0,0 +1,113 @@
+require 'puppet'
+require 'spec_helper'
+require 'puppet/provider/keystone_endpoint/openstack'
+
+provider_class = Puppet::Type.type(:keystone_endpoint).provider(:openstack)
+
+describe provider_class do
+
+  describe 'when updating an endpoint' do
+
+    let(:endpoint_attrs) do
+      {
+        :name         => 'foo/bar',
+        :ensure       => 'present',
+        :public_url   => 'http://127.0.0.1:5000/v2.0',
+        :internal_url => 'http://127.0.0.1:5001/v2.0',
+        :admin_url    => 'http://127.0.0.1:5002/v2.0',
+        :auth         => {
+          'username'    => 'test',
+          'password'    => 'abc123',
+          'tenant_name' => 'foo',
+          'auth_url'    => 'http://127.0.0.1:5000/v2.0',
+        }
+      }
+    end
+
+    let(:resource) do
+      Puppet::Type::Keystone_endpoint.new(endpoint_attrs)
+    end
+
+    let(:provider) do
+      provider_class.new(resource)
+    end
+
+    describe '#create' do
+      it 'creates an endpoint' do
+        provider.class.stubs(:openstack)
+                      .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+                      .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
+"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
+')
+        provider.class.stubs(:openstack)
+                      .with('endpoint', 'create', '--format', 'shell', [['bar', '--region', 'foo', '--publicurl', 'http://127.0.0.1:5000/v2.0', '--internalurl', 'http://127.0.0.1:5001/v2.0', '--adminurl', 'http://127.0.0.1:5002/v2.0', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+                      .returns('adminurl="http://127.0.0.1:5002/v2.0"
+id="3a5c4378981e4112a0d44902a43e16ef"
+internalurl="http://127.0.0.1:5001/v2.0"
+publicurl="http://127.0.0.1:5000/v2.0"
+region="foo"
+service_id="8137d72980fd462192f276585a002426"
+service_name="bar"
+service_type="test"
+')
+        provider.create
+        expect(provider.exists?).to be_truthy
+      end
+    end
+
+    describe '#destroy' do
+      it 'destroys an endpoint' do
+        provider.class.stubs(:openstack)
+                      .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+                      .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
+"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
+')
+        provider.class.stubs(:openstack)
+                      .with('endpoint', 'delete', [['1cb05cfed7c24279be884ba4f6520262', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+        expect(provider.destroy).to be_nil # We don't really care that it's nil, only that it runs successfully
+      end
+
+    end
+
+    describe '#exists' do
+      context 'when endpoint exists' do
+
+        subject(:response) do
+          provider.class.stubs(:openstack)
+                        .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+                        .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
+"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
+')
+          response = provider.exists?
+        end
+
+        it { is_expected.to be_truthy }
+      end
+
+      context 'when tenant does not exist' do
+
+        subject(:response) do
+          provider.class.stubs(:openstack)
+                        .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+                        .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"')
+          response = provider.exists?
+        end
+
+        it { is_expected.to be_falsey }
+      end
+    end
+
+    describe '#instances' do
+      it 'finds every tenant' do
+        provider.class.stubs(:openstack)
+                      .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
+                      .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
+"1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
+')
+        instances = provider.instances
+        expect(instances.count).to eq(1)
+      end
+    end
+
+  end
+end