@@ -0,0 +1,93 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE TemplateHaskell #-}
8+-------------------------------------------------------------------------------
10+import Control.Monad.IO.Class
11+import qualified Data.Map as M
13+import Database.Bloodhound
14+import Network.HTTP.Client (defaultManagerSettings)
16+import Test.Tasty.HUnit
17+-------------------------------------------------------------------------------
19+import Katip.Scribes.ElasticSearch
20+-------------------------------------------------------------------------------
24+main = defaultMain $ testGroup "katip-elasticsearch"
26+ withResource setupSearch teardownSearch esTests
30+-------------------------------------------------------------------------------
31+setupSearch :: IO (Scribe, IO ())
34+ mkEsScribe defaultEsScribeCfg svr ixn mn DebugS V3
37+-------------------------------------------------------------------------------
38+teardownSearch :: (Scribe, IO ()) -> IO ()
39+teardownSearch (_, finalizer) = do
44+-------------------------------------------------------------------------------
45+esTests :: IO (Scribe, IO ()) -> TestTree
46+esTests setup = testGroup "elasticsearch scribe"
48+ testCase "it works" $ withTestLogging setup $ \done -> do
49+ $(logT) () mempty InfoS "A test message"
57+-------------------------------------------------------------------------------
58+getLogs = bh $ searchByIndex ixn $ mkSearch Nothing Nothing
61+-------------------------------------------------------------------------------
62+bh = withBH defaultManagerSettings svr
65+-------------------------------------------------------------------------------
66+withTestLogging setup f = do
67+ (scribe, done) <- setup
68+ le <- initLogEnv ns env
69+ runKatipT le { _logEnvScribes = M.singleton "es" scribe} (f done)
71+ ns = Namespace ["katip-test"]
72+ env = Environment "test"
74+-------------------------------------------------------------------------------
75+svr = Server "http://localhost:9200"
76+ixn = IndexName "katip-elasticsearch-tests"
77+ixs = defaultIndexSettings
78+mn = MappingName "logs"
82+-------------------------------------------------------------------------------
83+recreateESSchema = dropESSchema >> createESSchema
86+-------------------------------------------------------------------------------
87+dropESSchema = void $ deleteIndex ixn
90+-------------------------------------------------------------------------------
93+ putMapping ixn mn mapping