module BucketLoaderTests
    ( bucketLoadingTests
    ) where

import Test.HUnit
import BucketLoader (loadBucketFrom)
import Utils (withTemporaryDirectory)
import BucketLoader (createBucket)
import System.Directory

givenABucketAt = createBucket
givenFilesInBucketAt path = do
    createDirectory $ path ++ "/oneFile"
    createDirectory $ path ++ "/anotherFile"

whenLoadingBucketFrom = loadBucketFrom
thenOneFileShouldBeReturned filesInBucket = assertEqual "" ["oneFile", "anotherFile"] filesInBucket

bucketLoadingTests = test [

    "return empty file list when no bucket exist" ~: do
        filesInBucket <- loadBucketFrom "/a/path"
        assertEqual "Should be empty" [] filesInBucket

    , "return files in bucket" ~: withTemporaryDirectory $ \path -> do
        givenABucketAt $ path ++ "/bucket"
        givenFilesInBucketAt $ path ++ "/bucket"
        filesInBucket <- whenLoadingBucketFrom $ path ++ "/bucket"
        thenOneFileShouldBeReturned filesInBucket
    ]

module BucketLoaderTests
    ( bucketLoadingTests
    ) where

import Test.HUnit
import BucketLoader (loadBucketFrom)
import Utils (withTemporaryDirectory)
import BucketLoader (createBucket)
import System.Directory
import qualified Data.Set as Set

givenABucketAt = createBucket
givenFilesInBucketAt path = do
    createDirectory $ path ++ "/oneFile"
    createDirectory $ path ++ "/anotherFile"

whenLoadingBucketFrom = loadBucketFrom
thenOneFileShouldBeReturned filesInBucket = assertEqual "" (Set.fromList ["oneFile", "anotherFile"]) (Set.fromList filesInBucket)

bucketLoadingTests = test [

    "return empty file list when no bucket exist" ~: do
        filesInBucket <- loadBucketFrom "/a/path"
        assertEqual "Should be empty" [] filesInBucket

    , "return files in bucket" ~: withTemporaryDirectory $ \path -> do
        givenABucketAt $ path ++ "/bucket"
        givenFilesInBucketAt $ path ++ "/bucket"
        filesInBucket <- whenLoadingBucketFrom $ path ++ "/bucket"
        thenOneFileShouldBeReturned filesInBucket
    ]

Make file list comparison with sets so that order doesn't matter.
Make file list comparison with sets so that order doesn't matter.
