mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
Rename free to free_kb
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
5bbd4c16d6
commit
02cb799ee6
3 changed files with 15 additions and 13 deletions
|
@ -19,6 +19,8 @@ This resource is distributed along with InSpec itself. You can use it automatica
|
|||
|
||||
This resource first became available in v1.51.0 of InSpec.
|
||||
|
||||
The `free_kb`, `size_kb`, and `type` properties became available in v3.6 of InSpec.
|
||||
|
||||
### Note
|
||||
|
||||
Versions of this resource in InSpec prior to 3.5.x offered a property `size`, which returned a value in GB when on Windows and a value in KB on Linux, though it was documented to always return KB. All new code should use `size_kb` which is unit-stable.
|
||||
|
@ -28,8 +30,8 @@ Versions of this resource in InSpec prior to 3.5.x offered a property `size`, wh
|
|||
A `filesystem` resource block declares tests for disk space in a partition:
|
||||
|
||||
describe filesystem('/') do
|
||||
its('size_kb') { should be >= 32000 }
|
||||
its('free') { should be >= 5000000 }
|
||||
its('size_kb') { should be >= 32 * 1024 * 1024}
|
||||
its('free_kb') { should be >= 50 * 1024 }
|
||||
its('percent_free') { should be >= 20 }
|
||||
its('type') { should cmp 'ext4' }
|
||||
end
|
||||
|
@ -38,7 +40,7 @@ where
|
|||
|
||||
* `filesystem('/')` states that the resource will look at the root (/) partition.
|
||||
* `size_kb` is the total partition size and is measured in kilobytes (KB).
|
||||
* `free` is the available space on the partition and is measured in kilobytes (KB).
|
||||
* `free_kb` is the available space on the partition and is measured in kilobytes (KB).
|
||||
* `percent_free` is the percentage of available free space, and ranges from 0 to 100.
|
||||
|
||||
<br>
|
||||
|
@ -58,7 +60,7 @@ The following examples show how to use this InSpec audit resource.
|
|||
### Test that the root partition has more than 5GB free
|
||||
|
||||
describe filesystem('/') do
|
||||
its('free') { should be >= 5000000 }
|
||||
its('free_kb') { should be >= 5000000 }
|
||||
end
|
||||
|
||||
<br>
|
||||
|
|
|
@ -6,14 +6,14 @@ module Inspec::Resources
|
|||
desc 'Use the filesystem InSpec resource to test file system'
|
||||
example "
|
||||
describe filesystem('/') do
|
||||
its('size') { should be >= 32000 }
|
||||
its('free') { should be >= 3200 }
|
||||
its('size_kb') { should be >= 32000 }
|
||||
its('free_kb') { should be >= 3200 }
|
||||
its('type') { should cmp 'ext4' }
|
||||
its('percent_free') { should be >= 20 }
|
||||
end
|
||||
describe filesystem('c:') do
|
||||
its('size') { should be >= 90 }
|
||||
its('free') { should be >= 3200 }
|
||||
its('size_kb') { should be >= 9000 }
|
||||
its('free_kb') { should be >= 3200 }
|
||||
its('type') { should cmp 'NTFS' }
|
||||
its('percent_free') { should be >= 20 }
|
||||
end
|
||||
|
@ -63,13 +63,13 @@ module Inspec::Resources
|
|||
end
|
||||
end
|
||||
|
||||
def free
|
||||
def free_kb
|
||||
info = @fsman.info(@partition)
|
||||
info[:free_kb]
|
||||
end
|
||||
|
||||
def percent_free
|
||||
100 * free / size_kb
|
||||
100 * free_kb / size_kb
|
||||
end
|
||||
|
||||
def type
|
||||
|
|
|
@ -9,18 +9,18 @@ describe 'Inspec::Resources::FileSystemResource' do
|
|||
_(resource.size).must_equal 30428648
|
||||
_(resource.name).must_equal '/'
|
||||
_(resource.type).must_equal 'ext4'
|
||||
_(resource.free).must_equal 20760728
|
||||
_(resource.free_kb).must_equal 20760728
|
||||
_(resource.percent_free).must_equal 68
|
||||
end
|
||||
|
||||
# arch windows
|
||||
# windows
|
||||
it 'verify filesystem on windows' do
|
||||
resource = MockLoader.new(:windows).load_resource('filesystem','c:')
|
||||
_(resource.size).must_equal 38 # Windows size() had a bug that turned it into GB, not KB
|
||||
_(resource.size_kb).must_equal 40000000 # approx 38 GB
|
||||
_(resource.name).must_equal 'c:'
|
||||
_(resource.type).must_equal 'NTFS'
|
||||
_(resource.free).must_equal 30000000
|
||||
_(resource.free_kb).must_equal 30000000
|
||||
_(resource.percent_free).must_equal 75
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue