cache_check work

This commit is contained in:
Joe Thornber
2013-03-21 15:44:28 +00:00
committed by Joe Thornber
parent 81d4e5523f
commit 52f1aa8a8a
6 changed files with 221 additions and 19 deletions

View File

@@ -0,0 +1,76 @@
Feature: cache_check
Scenario: print version (-V flag)
When I run `cache_check -V`
Then it should pass
And version to stdout
Scenario: print version (--version flag)
When I run `cache_check --version`
Then it should pass
And version to stdout
Scenario: print help
When I run `cache_check --help`
Then it should pass
And usage to stdout
Scenario: print help
When I run `cache_check -h`
Then it should pass
And usage to stdout
Scenario: Metadata file must be specified
When I run `cache_check`
Then it should fail
And usage to stderr
And the stderr should contain:
"""
No input file provided.
"""
Scenario: Metadata file doesn't exist
When I run `cache_check /arbitrary/filename`
Then it should fail
And the stderr should contain:
"""
/arbitrary/filename: No such file or directory
"""
Scenario: Metadata file cannot be a directory
Given a directory called foo
When I run `cache_check foo`
Then it should fail
And the stderr should contain:
"""
foo: Not a block device or regular file
"""
Scenario: Metadata file exists, but can't be opened
Given input without read permissions
When I run `cache_check input`
Then it should fail
And the stderr should contain:
"""
input: Permission denied
"""
Scenario: Metadata file full of zeroes
Given input file
And block 1 is zeroed
When I run `cache_check input`
And the stderr should contain:
"""
input: No superblock found
"""

View File

@@ -0,0 +1,57 @@
DEFAULT_INPUT = 'input'
BLOCK_SIZE = 4096
Given /^a directory called (.*)\s*$/ do |dir|
create_dir(dir)
end
Given /^input without read permissions$/ do
write_file(DEFAULT_INPUT, "\0" * 4096)
in_current_dir do
f = File.new(DEFAULT_INPUT)
f.chmod(0000)
end
end
Given(/^input file$/) do
write_file(DEFAULT_INPUT, "\0" * BLOCK_SIZE * 1024)
end
Given(/^block (\d+) is zeroed$/) do |b|
in_current_dir do
File.open(DEFAULT_INPUT, 'w') do |f|
f.seek(BLOCK_SIZE * b.to_i, IO::SEEK_SET)
f.write("\0" * BLOCK_SIZE)
end
end
end
Then /^it should pass$/ do
assert_success(true)
end
Then /^it should fail$/ do
assert_success(false)
end
VERSION="0.1.6\n"
Then /^version to stdout$/ do
assert_exact_output(VERSION, all_stdout)
end
USAGE =<<EOF
Usage: cache_check [options] {device|file}
Options:
{-q|--quiet}
{-h|--help}
{-V|--version}
EOF
Then /^usage to stdout$/ do
assert_partial_output(USAGE, all_stdout)
end
Then /^usage to stderr$/ do
assert_partial_output(USAGE, all_stderr)
end

View File

@@ -1,4 +1,3 @@
require 'aruba/cucumber'
STDERR.puts "pwd = #{Dir::pwd}"
ENV['PATH'] = "#{Dir::pwd}:#{ENV['PATH']}"