diff --git a/src/Password.hs b/src/Password.hs index 3582cda..9ce30ea 100644 --- a/src/Password.hs +++ b/src/Password.hs @@ -225,7 +225,7 @@ pwSetService -- ^ the database to add to -> PWDatabase -- ^ the resulting database -pwSetService = undefined +pwSetService = M.insert -- | attempts to get a service from the database pwGetService diff --git a/test/Spec.hs b/test/Spec.hs index 3c5af05..e9103de 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -32,6 +32,7 @@ import qualified Spec.NewPWPolicy as NewPWPolicy import qualified Spec.NewPWSalt as NewPWSalt import qualified Spec.PWGenerate as PWGenerate import qualified Spec.PWHasService as PWHasService +import qualified Spec.PWSetService as PWSetService import qualified Spec.ValidatePWData as ValidatePWData import qualified Spec.ValidatePWDatabase as ValidatePWDatabase import qualified Spec.ValidatePWPolicy as ValidatePWPolicy @@ -51,6 +52,7 @@ tests = TestList , ValidatePWPolicy.tests , PWGenerate.tests , PWHasService.tests + , PWSetService.tests ] --jl diff --git a/test/Spec/PWSetService.hs b/test/Spec/PWSetService.hs new file mode 100644 index 0000000..f9da993 --- /dev/null +++ b/test/Spec/PWSetService.hs @@ -0,0 +1,73 @@ +{- + +passman +Copyright (C) 2018 Jonathan Lamothe + + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this program. If not, see +. + +-} + +module Spec.PWSetService (tests) where + +import qualified Data.Map as M +import System.Random (mkStdGen) +import Test.HUnit (Test (..), (~?=)) + +import Password + +tests = TestLabel "pwSetService" $ TestList + [ addToEmpty, addToNonEmpty, addToExisting ] + +addToEmpty = tests' "empty database" newPWDatabase 1 + +addToNonEmpty = tests' "non-empty database" nonEmpty 3 + +addToExisting = tests' "exiating database" existing 3 + +tests' label db size = TestLabel label $ TestList + [ dbSize result size + , find result + ] where + result = pwSetService "foo" foo db + +dbSize db expect = TestLabel "database size" $ + length db ~?= expect + +find db = TestLabel "record" $ + M.lookup "foo" db ~?= Just foo + +nonEmpty = M.fromList + [ ( "bar", bar ) + , ( "baz", baz ) + ] + +existing = M.fromList + [ ( "foo", foo' ) + , ( "bar", bar ) + , ( "baz", baz ) + ] + +(foo, g1) = newPWData g + +(foo', g2) = newPWData g1 + +(bar, g3) = newPWData g2 + +(baz, _) = newPWData g3 + +g = mkStdGen 1 + +--jl