[functional-tests] era_check tests

This commit is contained in:
Joe Thornber 2017-08-30 14:29:36 +01:00
parent 516afc8ed6
commit 6616a21891
4 changed files with 121 additions and 83 deletions

View File

@ -1,83 +0,0 @@
Feature: era_check
Scenario: print version (-V flag)
When I run `era_check -V`
Then it should pass with version
Scenario: print version (--version flag)
When I run `era_check --version`
Then it should pass with version
Scenario: print help
When I run `era_check --help`
Then it should pass
And era_usage to stdout
Scenario: print help
When I run `era_check -h`
Then it should pass
And era_usage to stdout
Scenario: Metadata file must be specified
When I run `era_check`
Then it should fail
And era_usage to stderr
And the stderr should contain:
"""
No input file provided.
"""
Scenario: Metadata file doesn't exist
When I run `era_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 `era_check foo`
Then it should fail
And the stderr should contain:
"""
foo: Not a block device or regular file
"""
# This test will fail if you're running as root
Scenario: Metadata file exists, but can't be opened
Given input without read permissions
When I run `era_check input`
Then it should fail
And the stderr should contain:
"""
Permission denied
"""
Scenario: Metadata file full of zeroes
Given input file
And block 1 is zeroed
When I run `era_check input`
Then it should fail
Scenario: --quiet is observed
Given input file
And block 1 is zeroed
When I run `era_check --quiet input`
Then it should fail
And it should give no output
Scenario: -q is observed
Given input file
And block 1 is zeroed
When I run `era_check -q input`
Then it should fail
And it should give no output

View File

@ -0,0 +1,109 @@
(library
(era-functional-tests)
(export register-era-tests)
(import (chezscheme)
(disk-units)
(functional-tests)
(era-xml)
(fmt fmt)
(process)
(scenario-string-constants)
(temp-file)
(srfi s8 receive))
(define-tool era-check)
(define-tool era-restore)
(define-tool era-dump)
(define-syntax with-era-xml
(syntax-rules ()
((_ (v) b1 b2 ...)
(with-temp-file-containing ((v "era.xml" (fmt #f (generate-xml 128 256 32 4))))
b1 b2 ...))))
(define-syntax with-valid-metadata
(syntax-rules ()
((_ (md) b1 b2 ...)
(with-temp-file-sized ((md "era.bin" (meg 4)))
(with-cache-xml (xml)
(era-restore "-i" xml "-o" md)
b1 b2 ...)))))
(define-syntax with-corrupt-metadata
(syntax-rules ()
((_ (md) b1 b2 ...)
(with-temp-file-sized ((md "era.bin" (meg 4)))
b1 b2 ...))))
(define-syntax with-empty-metadata
(syntax-rules ()
((_ (md) b1 b2 ...)
(with-temp-file-sized ((md "era.bin" (meg 4)))
b1 b2 ...))))
(define (register-era-tests) #t)
;;;-----------------------------------------------------------
;;; era_check scenarios
;;;-----------------------------------------------------------
(define-scenario (era-check v)
"era_check -V"
(receive (stdout _) (era-check "-V")
(assert-equal tools-version stdout)))
(define-scenario (era-check version)
"era_check --version"
(receive (stdout _) (era-check "--version")
(assert-equal tools-version stdout)))
(define-scenario (era-check h)
"era_check -h"
(receive (stdout _) (era-check "-h")
(assert-equal era-check-help stdout)))
(define-scenario (era-check help)
"era_check --help"
(receive (stdout _) (era-check "--help")
(assert-equal era-check-help stdout)))
(define-scenario (era-check no-device-specified)
"Fail if no device specified"
(receive (_ stderr) (run-fail "era_check")
(assert-starts-with "No input file provided." stderr)))
(define-scenario (era-check dev-not-exist)
"Fail if specified device doesn't exist"
(receive (_ stderr) (run-fail "era_check /dev/unlikely")
(assert-starts-with "/dev/unlikely: No such file or directory" stderr)))
(define-scenario (era-check dev-is-a-directory)
"Fail if given a directory instead of a file or device"
(receive (_ stderr) (run-fail "era_check /tmp")
(assert-starts-with "/tmp: Not a block device or regular file" stderr)))
(define-scenario (era-check bad-permissions)
"Fail if given a device with inadequate access permissions"
(with-temp-file-sized ((md "era.bin" (meg 4)))
(run-ok "chmod -r" md)
(receive (_ stderr) (run-fail "era_check" md)
(assert-starts-with "syscall 'open' failed: Permission denied" stderr))))
(define-scenario (era-check empty-dev)
"Fail if given a file of zeroes"
(with-empty-metadata (md)
(run-fail "era_check" md)))
(define-scenario (era-check quiet)
"Fail should give no output if --quiet"
(with-empty-metadata (md)
(receive (stdout stderr) (run-fail "era_check --quiet" md)
(assert-eof stdout)
(assert-eof stderr))))
(define-scenario (era-check q)
"Fail should give no output if -q"
(with-empty-metadata (md)
(receive (stdout stderr) (run-fail "era_check -q" md)
(assert-eof stdout)
(assert-eof stderr))))
)

View File

@ -5,6 +5,7 @@
(list-utils) (list-utils)
(functional-tests) (functional-tests)
(cache-functional-tests) (cache-functional-tests)
(era-functional-tests)
(parser-combinators) (parser-combinators)
(only (srfi s1 lists) break) (only (srfi s1 lists) break)
(regex) (regex)
@ -155,6 +156,8 @@
(register-thin-tests) (register-thin-tests)
(register-cache-tests) (register-cache-tests)
(register-era-tests)
(with-dir "test-output" (with-dir "test-output"
((parse-command-line))) ((parse-command-line)))

View File

@ -12,6 +12,8 @@
cache-restore-outfile-too-small-text cache-restore-outfile-too-small-text
cache-dump-help cache-dump-help
cache-metadata-size-help cache-metadata-size-help
era-check-help
) )
(import (rnrs)) (import (rnrs))
@ -117,4 +119,11 @@ Options:
These all relate to the size of the fast device (eg, SSD), rather These all relate to the size of the fast device (eg, SSD), rather
than the whole cached device.") than the whole cached device.")
(define era-check-help
"Usage: era_check [options] {device|file}
Options:
{-q|--quiet}
{-h|--help}
{-V|--version}
{--super-block-only}")
) )