aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/Test/Graylog/UDP.hs
blob: 6534c6955694efc62044a337acd3cd698df460ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}

module Test.Graylog.UDP where

import qualified Data.ByteString    as BS
import           Data.FileEmbed
import qualified Data.Text.Encoding as T
import           Test.Tasty
import           Test.Tasty.HUnit

import           Graylog.UDP

largeSample :: BS.ByteString
largeSample = $(embedFile "./test/Test/Graylog/UDP/large-sample.json")

tests :: TestTree
tests = testGroup "Test.Graylog.UDP"
   [ testCase "Send sample message." case_sendSample
   , testCase "Send large sample message." case_sendLargeSample
   ]

case_sendSample :: IO ()
case_sendSample = do
   eglog <- openGraylog "192.168.99.100" "12201" defaultChunkSize
   case eglog of
      Left  e -> assertFailure e
      Right g -> sendLog g sample >> closeGraylog g
   where
      sample = simpleGelf "localhost" "hello world!"

case_sendLargeSample :: IO ()
case_sendLargeSample = do
   eglog <- openGraylog "192.168.99.100" "12201" defaultChunkSize
   case eglog of
      Left  e -> assertFailure e
      Right g -> sendLog g sample >> closeGraylog g
   where
      sample = (simpleGelf "localhost" "hello world!")
                  { _gelfFullMessage = Just $ T.decodeUtf8 largeSample }