ouroboros-consensus-test-0.1.0.0: Tests of the consensus layer
Safe HaskellNone
LanguageHaskell2010

Test.Util.FS.Sim.MockFS

Description

Mock file system implementation

Intended for qualified import

import Test.Util.FS.Sim.MockFS (MockFS)
import qualified Test.Util.FS.Sim.MockFS as Mock
Synopsis

Documentation

handleIsOpenMockFSHandleMockBool Source #

Return True iff the handle is open.

Throws an exception if the handle is unknown.

numOpenHandlesMockFSInt Source #

Number of open handles

prettyMockFSString Source #

Renders the MockFS in a human-readable fashion.

TODO: Right now does this not show the state of the handles.

Debugging

dumpState ∷ CanSimFS m ⇒ m String Source #

Operations on files

hClose ∷ CanSimFS m ⇒ Handle' → m () Source #

Mock implementation of hClose

hGetSize ∷ CanSimFS m ⇒ Handle' → m Word64 Source #

Get file size

NOTE: In the mock implementation this is thread safe, because there can be only one writer, so concurrent threads cannot change the size of the file.

hGetSome ∷ CanSimFS m ⇒ Handle' → Word64 → m ByteString Source #

Get bytes from handle

NOTE: Unlike real I/O, we disallow hGetSome on a handle in append mode.

hGetSomeAt ∷ CanSimFS m ⇒ Handle' → Word64AbsOffset → m ByteString Source #

Thread safe version of hGetSome, which doesn't modify or read the file offset.

hIsOpen ∷ CanSimFS m ⇒ Handle' → m Bool Source #

Mock implementation of hIsOpen

hOpen ∷ CanSimFS m ⇒ FsPathOpenMode → m Handle' Source #

Mock implementation of hOpen.

NOTE: Differences from Posix:

  • We do not support opening directories.
  • We do not support more than one concurrent writer (we do however allow a writer and multiple concurrent readers)
  • We do not support create file on ReadMode.

hPutSome ∷ CanSimFS m ⇒ Handle' → ByteString → m Word64 Source #

hSeek ∷ CanSimFS m ⇒ Handle' → SeekModeInt64 → m () Source #

Mock implementation of hSeek

NOTE: This is more restricted than the IO version, because seek has some odd properties:

  • We do not allow seeking at all on files in append mode
  • We do not allow seeking past the end of the file (this means that when using SeekFromEnd, the only valid offset is 0)
  • We do not return the new file offset

hTruncate ∷ CanSimFS m ⇒ Handle' → Word64 → m () Source #

Truncate a file

NOTE: Differences from Posix:

  • Although this corresponds to Posix ftruncate, this can only be used to make files smaller, not larger.
  • We only support this in append mode. The reason is that Posix ftruncate does not modify the file offset, and adds padding with zeroes on subsequent writes. This is however not behaviour we want to emulate. In append mode however the Posix file offset is not used (and we don't even record it at all), appends always happen at the end of the file.

Operations on directories

createDirectory ∷ CanSimFS m ⇒ FsPath → m () Source #

createDirectoryIfMissing ∷ CanSimFS m ⇒ BoolFsPath → m () Source #

doesDirectoryExist ∷ CanSimFS m ⇒ FsPath → m Bool Source #

Check if directory exists

It seems real I/O maps what would be "inapproriate device" errors to False.

doesFileExist ∷ CanSimFS m ⇒ FsPath → m Bool Source #

Check if file exists

See comments for doesDirectoryExist.

listDirectory ∷ CanSimFS m ⇒ FsPath → m (Set String) Source #

removeFile ∷ CanSimFS m ⇒ FsPath → m () Source #

Remove a file

The behaviour of unlink is to remove the file after all open file handles that refer to it are closed. The open file handles referring to the file can still be used to write/read to/from, while at the same time, the file is invisible for all other operations.

We do not implement this behaviour and consider this a limitation of the mock file system, and throw an error when removing a file that still has open file handles to it.

In the state machine tests, removing the root directory may cause the IO implementation to throw an FsInsufficientPermissions error, depending on the permissions of the temporary directory used to run the tests in. In theory it should throw a FsResourceInappropriateType error. To avoid this mismatch during testing, we also consider removing the root folder a limitation of the mock file system.

renameFile ∷ CanSimFS m ⇒ FsPathFsPath → m () Source #

Exported for the benefit of tests only

type Files = FsTree ByteString Source #

We store the files as an FsTree of the file contents

opaque

data ClosedHandleState Source #

Instances

Instances details
Show ClosedHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Generic ClosedHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Associated Types

type Rep ClosedHandleStateTypeType Source #

NoThunks ClosedHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Methods

noThunks ∷ Context → ClosedHandleStateIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → ClosedHandleStateIO (Maybe ThunkInfo) #

showTypeOfProxy ClosedHandleStateString #

type Rep ClosedHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

type Rep ClosedHandleState = D1 ('MetaData "ClosedHandleState" "Test.Util.FS.Sim.MockFS" "ouroboros-consensus-test-0.1.0.0-inplace" 'False) (C1 ('MetaCons "ClosedHandle" 'PrefixI 'True) (S1 ('MetaSel ('Just "closedFilePath") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FsPath)))

data FilePtr Source #

File pointer

This is purely an internal abstraction.

Instances

Instances details
Show FilePtr Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Generic FilePtr Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Associated Types

type Rep FilePtrTypeType Source #

Methods

fromFilePtrRep FilePtr x Source #

toRep FilePtr x → FilePtr Source #

NoThunks FilePtr Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Methods

noThunks ∷ Context → FilePtrIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → FilePtrIO (Maybe ThunkInfo) #

showTypeOfProxy FilePtrString #

type Rep FilePtr Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

type Rep FilePtr = D1 ('MetaData "FilePtr" "Test.Util.FS.Sim.MockFS" "ouroboros-consensus-test-0.1.0.0-inplace" 'False) (C1 ('MetaCons "RW" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word64))) :+: C1 ('MetaCons "Append" 'PrefixI 'False) (U1TypeType))

data HandleState Source #

Mock handle internal state

Instances

Instances details
Show HandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Generic HandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Associated Types

type Rep HandleStateTypeType Source #

NoThunks HandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Methods

noThunks ∷ Context → HandleStateIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → HandleStateIO (Maybe ThunkInfo) #

showTypeOfProxy HandleStateString #

type Rep HandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

type Rep HandleState = D1 ('MetaData "HandleState" "Test.Util.FS.Sim.MockFS" "ouroboros-consensus-test-0.1.0.0-inplace" 'False) (C1 ('MetaCons "HandleOpen" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OpenHandleState)) :+: C1 ('MetaCons "HandleClosed" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ClosedHandleState)))

data OpenHandleState Source #

Instances

Instances details
Show OpenHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Generic OpenHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Associated Types

type Rep OpenHandleStateTypeType Source #

NoThunks OpenHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Methods

noThunks ∷ Context → OpenHandleStateIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → OpenHandleStateIO (Maybe ThunkInfo) #

showTypeOfProxy OpenHandleStateString #

type Rep OpenHandleState Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

type Rep OpenHandleState = D1 ('MetaData "OpenHandleState" "Test.Util.FS.Sim.MockFS" "ouroboros-consensus-test-0.1.0.0-inplace" 'False) (C1 ('MetaCons "OpenHandle" 'PrefixI 'True) (S1 ('MetaSel ('Just "openFilePath") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FsPath) :*: S1 ('MetaSel ('Just "openPtr") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FilePtr)))

opaque

data HandleMock Source #

A mock handle to a file on disk.

This is only meaningful when interpreted against a MockFS.

Instances

Instances details
Enum HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Eq HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Ord HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Show HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Generic HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Associated Types

type Rep HandleMockTypeType Source #

NoThunks HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Methods

noThunks ∷ Context → HandleMockIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → HandleMockIO (Maybe ThunkInfo) #

showTypeOfProxy HandleMockString #

type Rep HandleMock Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

type Rep HandleMock = D1 ('MetaData "HandleMock" "Test.Util.FS.Sim.MockFS" "ouroboros-consensus-test-0.1.0.0-inplace" 'True) (C1 ('MetaCons "HandleMock" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

data MockFS Source #

Instances

Instances details
Show MockFS Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Generic MockFS Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Associated Types

type Rep MockFSTypeType Source #

Methods

fromMockFSRep MockFS x Source #

toRep MockFS x → MockFS Source #

NoThunks MockFS Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

Methods

noThunks ∷ Context → MockFSIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → MockFSIO (Maybe ThunkInfo) #

showTypeOfProxy MockFSString #

MonadState MockFS PureSimFS Source # 
Instance details

Defined in Test.Util.FS.Sim.Pure

Methods

getPureSimFS MockFS Source #

putMockFSPureSimFS () Source #

state ∷ (MockFS → (a, MockFS)) → PureSimFS a Source #

type Rep MockFS Source # 
Instance details

Defined in Test.Util.FS.Sim.MockFS

type Rep MockFS = D1 ('MetaData "MockFS" "Test.Util.FS.Sim.MockFS" "ouroboros-consensus-test-0.1.0.0-inplace" 'False) (C1 ('MetaCons "MockFS" 'PrefixI 'True) (S1 ('MetaSel ('Just "mockFiles") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Files) :*: (S1 ('MetaSel ('Just "mockHandles") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map HandleMock HandleState)) :*: S1 ('MetaSel ('Just "mockNextHandle") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 HandleMock))))