|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test_plugin_helper' |
| 4 | + |
| 5 | +module ForemanBootdisk |
| 6 | + class LibvirtTest < ActiveSupport::TestCase |
| 7 | + class DummyLibvirtComputeResource |
| 8 | + prepend ForemanBootdisk::ComputeResources::Libvirt |
| 9 | + |
| 10 | + attr_reader :client |
| 11 | + |
| 12 | + def initialize(client, volumes = []) |
| 13 | + @client = client |
| 14 | + @volumes = volumes |
| 15 | + end |
| 16 | + |
| 17 | + def capabilities |
| 18 | + [:image] |
| 19 | + end |
| 20 | + |
| 21 | + def volumes |
| 22 | + @volumes |
| 23 | + end |
| 24 | + |
| 25 | + def set_boot_order(_attr = {}) |
| 26 | + %w[hd] |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + setup do |
| 31 | + @client = mock('client') |
| 32 | + @cr = DummyLibvirtComputeResource.new(@client, [OpenStruct.new(pool_name: 'bootdisk')]) |
| 33 | + end |
| 34 | + |
| 35 | + describe '#capabilities' do |
| 36 | + test 'should include bootdisk' do |
| 37 | + assert_includes @cr.capabilities, :bootdisk |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe '#iso_upload' do |
| 42 | + test 'calls fog-libvirt upload_iso' do |
| 43 | + @client.expects(:upload_iso).with('bootdisk', 'test.iso', '/tmp/test.iso') |
| 44 | + @cr.iso_upload('/tmp/test.iso', '1234') |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + describe '#iso_attach' do |
| 49 | + test 'calls fog-libvirt attach_iso' do |
| 50 | + @client.expects(:attach_iso).with('1234', 'test.iso') |
| 51 | + @cr.iso_attach('test.iso', '1234') |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe '#iso_detach' do |
| 56 | + test 'calls fog-libvirt detach_iso' do |
| 57 | + @client.expects(:detach_iso).with('1234', nil) |
| 58 | + @cr.iso_detach('1234') |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + describe '#iso_delete' do |
| 63 | + test 'calls fog-libvirt destroy_iso' do |
| 64 | + @client.expects(:destroy_iso).with('bootdisk', 'test.iso') |
| 65 | + @cr.iso_delete('test.iso') |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe '#set_boot_order' do |
| 70 | + test 'prepends cdrom when provision_method is bootdisk' do |
| 71 | + order = @cr.set_boot_order(provision_method: 'bootdisk') |
| 72 | + assert_equal %w[cdrom network hd], order |
| 73 | + end |
| 74 | + |
| 75 | + test 'returns base order when provision_method is not bootdisk' do |
| 76 | + order = @cr.set_boot_order(provision_method: 'image') |
| 77 | + assert_equal %w[hd], order |
| 78 | + end |
| 79 | + end |
| 80 | + end |
| 81 | +end |
0 commit comments