diff options
author | William Carroll <wpcarro@gmail.com> | 2020-03-29T17·49+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-03-29T17·49+0100 |
commit | 75595b0126806e1f1f35802ec534e32492cb2a6c (patch) | |
tree | 845351b7b4f712f507eb99932c64323e9575b33e /tools/website-blocker/Spec.hs | |
parent | 059af12bea03eef4616cbf47fa60890c14e9049a (diff) |
Parse and serialize rules.json
TL;DR: - Write FromJSON instances to decode rules.json file - Prefer Text to String and use the OverloadedStrings language extension - Read /etc/hosts and append the serialized rules.json to the end Notes: - I can remove some of the FromJSON instances and use GHC Generics to define them for me. TODO: - Define the systemd timer unit for this to run - Ensure script can run with root privileges
Diffstat (limited to 'tools/website-blocker/Spec.hs')
-rw-r--r-- | tools/website-blocker/Spec.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/website-blocker/Spec.hs b/tools/website-blocker/Spec.hs new file mode 100644 index 000000000000..b70d8619cb25 --- /dev/null +++ b/tools/website-blocker/Spec.hs @@ -0,0 +1,38 @@ +module Spec (main) where + +-------------------------------------------------------------------------------- +-- Dependencies +-------------------------------------------------------------------------------- + +import qualified Main as Main + +import Test.Hspec + +-------------------------------------------------------------------------------- +-- Tests +-------------------------------------------------------------------------------- + +main :: IO () +main = hspec $ do + describe "getRules" $ do + it "returns the parsed rules from rules.json" $ do + rules <- Main.getRules + rules `shouldBe` [ Main.Rule { Main.urls = [ Main.URL "facebook.com" + , Main.URL "www.facebook.com" + , Main.URL "twitter.com" + , Main.URL "www.twitter.com" + , Main.URL "youtube.com" + , Main.URL "www.youtube.com" + , Main.URL "instagram.com" + , Main.URL "www.instagram.com" + ] + , Main.allowed = [] + } + , Main.Rule { Main.urls = [ Main.URL "chat.googleplex.com" ] + , Main.allowed = [] + } + ] + + describe "Prelude.head" $ do + it "returns the first element of a list" $ do + head [23 ..] `shouldBe` (23 :: Int) |