-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from zakiva/add_template_tests
Add Container Template Spec
- Loading branch information
Showing
3 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryGirl.define do | ||
factory :openshift_template, | ||
:aliases => ['manageiq/providers/openshift/container_manager/container_template'], | ||
:class => 'ManageIQ::Providers::Openshift::ContainerManager::ContainerTemplate', | ||
:parent => :container_template do | ||
end | ||
end |
61 changes: 61 additions & 0 deletions
61
spec/models/manageiq/providers/openshift/container_manager/container_template_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
describe ContainerTemplate do | ||
let(:ems) do | ||
hostname = 'host.example.com' | ||
token = 'theToken' | ||
FactoryGirl.create( | ||
:ems_openshift, | ||
:name => 'OpenShiftProvider', | ||
:connection_configurations => [{:endpoint => {:role => :default, | ||
:hostname => hostname, | ||
:port => "8443"}, | ||
:authentication => {:role => :bearer, | ||
:auth_key => token, | ||
:userid => "_"}}, | ||
{:endpoint => {:role => :hawkular, | ||
:hostname => hostname, | ||
:port => "443"}, | ||
:authentication => {:role => :hawkular, | ||
:auth_key => token, | ||
:userid => "_"}}] | ||
) | ||
end | ||
|
||
before(:each) do | ||
allow(MiqServer).to receive(:my_zone).and_return("default") | ||
end | ||
|
||
it "instantiate a template with parameters and object labels" do | ||
param = FactoryGirl.create(:container_template_parameter, | ||
:name => 'VAR', | ||
:value => 'example', | ||
:required => true) | ||
|
||
object = {:apiVersion => "v1", | ||
:kind => "PersistentVolumeClaim", | ||
:metadata => {:name => "pvc-${VAR}"}, | ||
:spec => {:accessModes => ["ReadWriteOnce"], | ||
:resources => {:requests => {:storage => "8Gi"}}}} | ||
|
||
object_labels = {:created_from_template => "true"} | ||
|
||
template = FactoryGirl.create(:openshift_template, | ||
:ems_id => ems.id, | ||
:objects => [object], | ||
:object_labels => object_labels).tap do |temp| | ||
temp.container_template_parameters = [param] | ||
end | ||
|
||
VCR.use_cassette(described_class.name.underscore, | ||
:match_requests_on => [:path, :body], | ||
:allow_unused_http_interactions => false) do # , :record => :new_episodes) do | ||
ems.create_project(:metadata => {:name => "test-project"}) | ||
objects = template.instantiate(template.container_template_parameters, "test-project", template.object_labels) | ||
|
||
pvc = objects.first | ||
expect(pvc[:kind]).to eq("PersistentVolumeClaim") | ||
expect(pvc[:miq_class]).to eq(PersistentVolumeClaim) | ||
expect(pvc[:metadata][:name]).to eq("pvc-example") | ||
expect(pvc[:metadata][:labels]).to eq(:created_from_template => "true") | ||
end | ||
end | ||
end |
Oops, something went wrong.