7
7
describe "Memory facts" do
9
# We need these facts loaded, but they belong to a file with a
10
# different name, so load the file explicitly.
11
Facter.collection.loader.load(:memory)
9
# We need these facts loaded, but they belong to a file with a
10
# different name, so load the file explicitly.
11
Facter.collection.loader.load(:memory)
18
it "should return the current swap size" do
20
Facter.fact(:kernel).stubs(:value).returns("Darwin")
21
Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
22
swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
24
if swapusage =~ /total = (\S+).*/
25
Facter.fact(:swapfree).value.should == $1
29
it "should return the current swap free" do
30
Facter.fact(:kernel).stubs(:value).returns("Darwin")
31
Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
32
swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
34
if swapusage =~ /free = (\S+).*/
35
Facter.fact(:swapfree).value.should == $1
39
it "should return whether swap is encrypted" do
40
Facter.fact(:kernel).stubs(:value).returns("Darwin")
41
Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
42
swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
44
swapusage =~ /\(encrypted\)/
45
Facter.fact(:swapencrypted).value.should == true
48
describe "on OpenBSD" do
51
Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
53
swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
54
Facter::Util::Resolution.stubs(:exec).with('swapctl -s').returns(swapusage)
57
procs memory page disks traps cpu
58
r b w avm fre flt re pi po fr sr cd0 sd0 int sys cs us sy id
59
0 0 0 11048 181028 39 0 0 0 0 0 0 1 3 90 17 0 0 100
61
Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
63
Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344')
65
Facter.collection.loader.load(:memory)
72
it "should return the current swap free" do
73
Facter.fact(:swapfree).value.should == "144.87 MB"
18
76
it "should return the current swap size" do
20
Facter.fact(:kernel).stubs(:value).returns("Darwin")
21
Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
22
swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
24
if swapusage =~ /total = (\S+).*/
25
Facter.fact(:swapfree).value.should == $1
29
it "should return the current swap free" do
30
Facter.fact(:kernel).stubs(:value).returns("Darwin")
31
Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
32
swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
34
if swapusage =~ /free = (\S+).*/
35
Facter.fact(:swapfree).value.should == $1
39
it "should return whether swap is encrypted" do
40
Facter.fact(:kernel).stubs(:value).returns("Darwin")
41
Facter::Util::Resolution.stubs(:exec).with('sysctl vm.swapusage').returns("vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)")
42
swapusage = "vm.swapusage: total = 64.00M used = 0.00M free = 64.00M (encrypted)"
44
swapusage =~ /\(encrypted\)/
45
Facter.fact(:swapencrypted).value.should == true
48
describe "on OpenBSD" do
51
Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
53
swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
54
Facter::Util::Resolution.stubs(:exec).with('swapctl -s').returns(swapusage)
57
procs memory page disks traps cpu
58
r b w avm fre flt re pi po fr sr cd0 sd0 int sys cs us sy id
59
0 0 0 11048 181028 39 0 0 0 0 0 0 1 3 90 17 0 0 100
61
Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
63
Facter::Util::Resolution.stubs(:exec).with("sysctl hw.physmem | cut -d'=' -f2").returns('267321344')
65
Facter.collection.loader.load(:memory)
72
it "should return the current swap free" do
73
Facter.fact(:swapfree).value.should == "144.87 MB"
76
it "should return the current swap size" do
77
Facter.fact(:swapsize).value.should == "144.87 MB"
80
it "should return the current memorysize" do
81
Facter.fact(:memorytotal).value.should == "254.94 MB"
85
describe "on DragonFly BSD" do
88
Facter.fact(:kernel).stubs(:value).returns("dragonfly")
90
swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
91
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096")
92
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461")
93
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635")
94
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0")
97
procs memory page disks faults cpu
98
r b w avm fre flt re pi po fr sr da0 sg1 in sy cs us sy id
77
Facter.fact(:swapsize).value.should == "144.87 MB"
80
it "should return the current memorysize" do
81
Facter.fact(:memorytotal).value.should == "254.94 MB"
85
describe "on DragonFly BSD" do
88
Facter.fact(:kernel).stubs(:value).returns("dragonfly")
90
swapusage = "total: 148342k bytes allocated = 0k used, 148342k available"
91
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n hw.pagesize').returns("4096")
92
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_size').returns("128461")
93
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_anon_use').returns("2635")
94
Facter::Util::Resolution.stubs(:exec).with('/sbin/sysctl -n vm.swap_cache_use').returns("0")
97
procs memory page disks faults cpu
98
r b w avm fre flt re pi po fr sr da0 sg1 in sy cs us sy id
99
99
0 0 0 33152 13940 1902120 2198 53119 11642 6544597 5460994 0 0 6148243 7087927 3484264 0 1 9
101
Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
103
Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512')
105
Facter.collection.loader.load(:memory)
112
it "should return the current swap free" do
113
Facter.fact(:swapfree).value.should == "491.51 MB"
116
it "should return the current swap size" do
117
Facter.fact(:swapsize).value.should == "501.80 MB"
120
it "should return the current memorysize" do
121
Facter.fact(:memorytotal).value.should == "237.00 MB"
125
describe "on Windows" do
128
Facter.fact(:kernel).stubs(:value).returns("windows")
129
Facter.collection.loader.load(:memory)
131
require 'facter/util/wmi'
134
it "should return free memory" do
136
os.stubs(:FreePhysicalMemory).returns("3415624")
137
Facter::Util::WMI.stubs(:execquery).returns([os])
139
Facter.fact(:MemoryFree).value.should == '3.26 GB'
142
it "should return total memory" do
143
computer = stubs 'computer'
144
computer.stubs(:TotalPhysicalMemory).returns("4193837056")
145
Facter::Util::WMI.stubs(:execquery).returns([computer])
147
Facter.fact(:MemoryTotal).value.should == '3.91 GB'
101
Facter::Util::Resolution.stubs(:exec).with('vmstat').returns(vmstat)
103
Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.physmem").returns('248512512')
105
Facter.collection.loader.load(:memory)
112
it "should return the current swap free" do
113
Facter.fact(:swapfree).value.should == "491.51 MB"
116
it "should return the current swap size" do
117
Facter.fact(:swapsize).value.should == "501.80 MB"
120
it "should return the current memorysize" do
121
Facter.fact(:memorytotal).value.should == "237.00 MB"
125
describe "on Windows" do
128
Facter.fact(:kernel).stubs(:value).returns("windows")
129
Facter.collection.loader.load(:memory)
131
require 'facter/util/wmi'
134
it "should return free memory" do
136
os.stubs(:FreePhysicalMemory).returns("3415624")
137
Facter::Util::WMI.stubs(:execquery).returns([os])
139
Facter.fact(:MemoryFree).value.should == '3.26 GB'
142
it "should return total memory" do
143
computer = stubs 'computer'
144
computer.stubs(:TotalPhysicalMemory).returns("4193837056")
145
Facter::Util::WMI.stubs(:execquery).returns([computer])
147
Facter.fact(:MemoryTotal).value.should == '3.91 GB'