<commit_before>require 'spec_helper'

module Vcloud
  module Core
    describe VappTemplate do

    before(:each) do
      @mock_fog_interface = double(:fog_interface)
      @test_config = {
          :catalog => 'test_catalog',
          :catalog_item => 'test_template'
      }
    end

    it 'should raise a RuntimeError if there is no template' do
      @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(nil)
      Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

      expect { VappTemplate.get('test_catalog', 'test_template') }.to raise_exception(RuntimeError, 'Could not find template vApp')
    end

    context "id" do
      it 'should return the id of the template' do
        test_catalog_item_entity = {
            :href => "/vappTemplate-12345678-90ab-cdef-0123-4567890abcde"
        }
        @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(test_catalog_item_entity)
        Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

        test_template = VappTemplate.get('test_catalog', 'test_template')
        test_template.id.should == 'vappTemplate-12345678-90ab-cdef-0123-4567890abcde'
      end

      it "should raise error if invalid id is found" do
        test_catalog_item_entity = {
            :href => "/#{'vAppTemplate-12345678-90ab-cdef-0123-4567890abcde'}"
        }
        @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(test_catalog_item_entity)
        Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

        test_template = VappTemplate.get('test_catalog', 'test_template')
        expect { test_template.id }.to raise_exception(RuntimeError, 'vappTemplate id : vmTemplate-12345678-90ab-cdef-0123-4567890abcde is not in correct format')
      end
    end

    it 'should fail gracefully if id is not of expected form' do
      test_catalog_item_entity = {
          :href => '/1234'
      }
      @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(test_catalog_item_entity)
      Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

      test_template = VappTemplate.get('test_catalog', 'test_template')
      expect { test_template.id }.to raise_exception(RuntimeError, 'vappTemplate id : 1234 is not in correct format')
    end

  end
  end
end<commit_msg>indentation fix<commit_after>require 'spec_helper'

module Vcloud
  module Core
    describe VappTemplate do

      before(:each) do
        @mock_fog_interface = double(:fog_interface)
        @test_config = {
            :catalog => 'test_catalog',
            :catalog_item => 'test_template'
        }
      end

      it 'should raise a RuntimeError if there is no template' do
        @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(nil)
        Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

        expect { VappTemplate.get('test_catalog', 'test_template') }.to raise_exception(RuntimeError, 'Could not find template vApp')
      end

      context "id" do
        it 'should return the id of the template' do
          test_catalog_item_entity = {
              :href => "/vappTemplate-12345678-90ab-cdef-0123-4567890abcde"
          }
          @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(test_catalog_item_entity)
          Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

          test_template = VappTemplate.get('test_catalog', 'test_template')
          test_template.id.should == 'vappTemplate-12345678-90ab-cdef-0123-4567890abcde'
        end

        it "should raise error if invalid id is found" do
          test_catalog_item_entity = {
              :href => "/#{'vAppTemplate-12345678-90ab-cdef-0123-4567890abcde'}"
          }
          @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(test_catalog_item_entity)
          Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

          test_template = VappTemplate.get('test_catalog', 'test_template')
          expect { test_template.id }.to raise_exception(RuntimeError, 'vappTemplate id : vmTemplate-12345678-90ab-cdef-0123-4567890abcde is not in correct format')
        end
      end

      it 'should fail gracefully if id is not of expected form' do
        test_catalog_item_entity = {
            :href => '/1234'
        }
        @mock_fog_interface.should_receive(:template).with('test_catalog', 'test_template').and_return(test_catalog_item_entity)
        Vcloud::Fog::ServiceInterface.should_receive(:new).and_return(@mock_fog_interface)

        test_template = VappTemplate.get('test_catalog', 'test_template')
        expect { test_template.id }.to raise_exception(RuntimeError, 'vappTemplate id : 1234 is not in correct format')
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.10606653620352251, 'fraction_numerical': 0.03600782778864971, 'mean_word_length': 3.563392857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5816523', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1530, 'n_words': 276}