File: metadata_spec.rb

package info (click to toggle)
ruby-fission 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 4,664; makefile: 10
file content (123 lines) | stat: -rw-r--r-- 4,383 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require 'spec_helper'

describe Fission::Metadata do
  before do
    @plist_mock = double('plist_mock')
    @plist_file_path = Fission.config['plist_file']
    @metadata = Fission::Metadata.new
  end

  describe 'load' do
    it 'should load the existing data' do
      plist = {'vm_list' => ['1', '2', '3']}
      CFPropertyList::List.should_receive(:new).
                           with(:file => @plist_file_path).
                           and_return(@plist_mock)
      @plist_mock.stub(:value).and_return(plist)
      CFPropertyList.should_receive(:native_types).with(plist).
                                                   and_return([1, 2, 3])
      @metadata.load
      @metadata.content.should == [1, 2, 3]
    end
  end

  describe 'delete_vm_restart_document' do
    before do
      vm_dir = Fission.config['vm_dir']
      @foo_vm_dir = File.join vm_dir, 'foo.vmwarevm'
      @bar_vm_dir = File.join vm_dir, 'bar.vmwarevm'
      @data = { 'PLRestartDocumentPaths' => [@foo_vm_dir, @bar_vm_dir]}
      @metadata.content = @data
    end

    it 'should remove the vm item from the list if the vm path is in the list' do
      @metadata.delete_vm_restart_document(Fission::VM.new('foo').path)
      @metadata.content.should == { 'PLRestartDocumentPaths' => [@bar_vm_dir]}
    end

    it 'should not doing anything if the vm is not in the list' do
      @metadata.delete_vm_restart_document(Fission::VM.new('baz').path)
      @metadata.content.should == @data
    end

    it 'should not do anything if the restart document list does not exist' do
      other_data = { 'OtherConfigItem' => ['foo', 'bar']}
      @metadata.content = other_data
      @metadata.delete_vm_restart_document(Fission::VM.new('foo').path)
      @metadata.content.should == other_data
    end
  end

  describe 'delete_vm_favorite_entry' do
    before do
      foo_vm_dir = File.join Fission.config['vm_dir'], 'foo.vmwarevm'

      @data = { 'VMFavoritesListDefaults2' => [{'path' => foo_vm_dir}] }
      @metadata.content = @data
    end

    it 'should remove the vm item from the list' do
      @metadata.delete_vm_favorite_entry(Fission::VM.new('foo').path)
      @metadata.content.should == { 'VMFavoritesListDefaults2' => [] }
    end

    it 'should not do anything if the vm is not in the list' do
      @metadata.delete_vm_favorite_entry(Fission::VM.new('bar').path)
      @metadata.content.should == @data
    end

    it 'should ignore VMFavoritesListDefaults2 in Fussion 5' do
      data = {}
      @metadata.content = data
      @metadata.delete_vm_favorite_entry(Fission::VM.new('bar').path)
      @metadata.content.should == data
    end

    it 'should remove the vm item from the list in Fussion 5' do
      foo_vm_dir = File.join Fission.config['vm_dir'], 'foo.vmwarevm'
      data = {"fusionInitialSessions" => [{"documentPath" => foo_vm_dir}]}

      @metadata.content = data
      @metadata.delete_vm_favorite_entry(Fission::VM.new('foo').path)
      @metadata.content.should == { 'fusionInitialSessions' => []}
    end
  end

  describe 'self.delete_vm_info' do
    before do
      @md_mock = double('metadata_mock')
      @md_mock.should_receive(:load)
      @md_mock.should_receive(:save)
      Fission::Metadata.stub(:new).and_return(@md_mock)

      @foo_vm_dir = File.join Fission.config['vm_dir'], 'foo.vmwarevm'
    end

    it 'should remove the vm from the restart document list' do
      @md_mock.should_receive(:delete_vm_restart_document).with(@foo_vm_dir)
      @md_mock.stub(:delete_vm_favorite_entry)
      Fission::Metadata.delete_vm_info(Fission::VM.new('foo').path)
    end

    it 'should remove the vm from the favorite list' do
      @md_mock.should_receive(:delete_vm_favorite_entry).with(@foo_vm_dir)
      @md_mock.stub(:delete_vm_restart_document)
      Fission::Metadata.delete_vm_info(Fission::VM.new('foo').path)
    end
  end

  describe 'save' do
    it 'should save the data' do
      CFPropertyList::List.should_receive(:new).and_return(@plist_mock)
      CFPropertyList.should_receive(:guess).with([1, 2, 3]).
                                           and_return(['1', '2', '3'])

      @plist_mock.should_receive(:value=).with(['1', '2', '3'])
      @plist_mock.should_receive(:save).
                  with(@plist_file_path, CFPropertyList::List::FORMAT_BINARY)

      @metadata.content = [1, 2, 3]
      @metadata.save
    end
  end
end