62 lines
2.5 KiB
Ruby
62 lines
2.5 KiB
Ruby
require 'db/mongo/models/image'
|
|
|
|
RSpec.describe Devops::Model::Image, type: :model do
|
|
let(:image) { build(:image) }
|
|
let(:string_with_dash) { 'asd-asd' }
|
|
let(:string_with_slash) { 'asd/asd' }
|
|
let(:string_with_parenthesis) { 'centos 6.5 x86_64 (development instance)' }
|
|
|
|
before do
|
|
allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(openstack ec2 static'))
|
|
allow_any_instance_of(Validators::Image::ImageInFilter).to receive(:available_images).and_return([{'id' => 'test_image'}, {'id' => string_with_dash}, {'id' => string_with_slash}])
|
|
end
|
|
|
|
it 'is valid with correct attrs' do
|
|
expect(image).to be_valid
|
|
end
|
|
|
|
describe 'validation' do
|
|
include_examples 'field type validation', :id, :not_nil, :non_empty_string, :field_validator
|
|
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string, :field_validator
|
|
include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator
|
|
include_examples 'field type validation', :bootstrap_template, :maybe_nil, :non_empty_string, :only_word_symbols, :field_validator
|
|
|
|
it 'id should contain only letters, digits and dashes' do
|
|
expect(build(:image, id: string_with_dash)).to be_valid
|
|
expect(build(:image, id: string_with_slash)).not_to be_valid
|
|
expect(build(:image, id: string_with_parenthesis)).not_to be_valid
|
|
end
|
|
|
|
it "id should be included in image filters" do
|
|
expect(build(:image, id: 'wrong')).not_to be_valid
|
|
end
|
|
|
|
it 'name may contain everything' do
|
|
expect(build(:image, name: string_with_dash)).to be_valid
|
|
expect(build(:image, name: string_with_slash)).to be_valid
|
|
expect(build(:image, name: string_with_parenthesis)).to be_valid
|
|
end
|
|
|
|
it 'name length should be less or equal than 100' do
|
|
expect(build(:image, name: 'a'*100)).to be_valid
|
|
expect(build(:image, name: 'a'*101)).not_to be_valid
|
|
end
|
|
|
|
it 'bootstrap_template should be included in available bootstrap templates' do
|
|
expect(build(:image, bootstrap_template: 'wrong')).not_to be_valid
|
|
end
|
|
|
|
it 'remote_user should contain only a-zA-Z0-9_-.' do
|
|
expect(build(:image, remote_user: 'aA0-.')).to be_valid
|
|
expect(build(:image, remote_user: 'name/')).not_to be_valid
|
|
expect(build(:image, remote_user: 'name!')).not_to be_valid
|
|
end
|
|
end
|
|
|
|
it '#to_hash_without_id returns provider, name, remote_user and bootstrap_template' do
|
|
expect(image.to_hash_without_id.keys).to match_array(%w(provider name remote_user bootstrap_template))
|
|
end
|
|
|
|
|
|
|
|
end |