From 15981d57cda18a19fcb3012172a9f0994abfd97a Mon Sep 17 00:00:00 2001 From: AndrewRademacher Date: Wed, 24 Feb 2016 17:24:19 -0600 Subject: Added testing for UDP method. --- graylog.cabal | 26 ++++++++++++++++++++++++++ src/Graylog/Gelf.hs | 31 ++++++++----------------------- src/Graylog/UDP.hs | 19 +++++++++++++++++++ test/Main.hs | 12 ++++++++++++ test/Test/Graylog/UDP.hs | 13 +++++++++++++ 5 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 src/Graylog/UDP.hs create mode 100644 test/Main.hs create mode 100644 test/Test/Graylog/UDP.hs diff --git a/graylog.cabal b/graylog.cabal index d7d1163..b3c1a53 100644 --- a/graylog.cabal +++ b/graylog.cabal @@ -24,7 +24,33 @@ library , aeson , aeson-casing + , network , scientific , text , time , vector + +test-suite test-state + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: test + default-language: Haskell2010 + + ghc-options: -Wall -threaded -with-rtsopts=-N -rtsopts + + other-modules: Test.Graylog.UDP + + build-depends: base ==4.* + + , graylog + + , aeson + , aeson-casing + , network + , scientific + , tasty + , tasty-hunit + , text + , time + , vector + diff --git a/src/Graylog/Gelf.hs b/src/Graylog/Gelf.hs index 67e0de7..32b9321 100644 --- a/src/Graylog/Gelf.hs +++ b/src/Graylog/Gelf.hs @@ -7,24 +7,21 @@ module Graylog.Gelf where import Data.Aeson (ToJSON (..), Value (..), genericToJSON, toJSON) import Data.Aeson.Casing -import Data.Scientific import Data.Text (Text) import Data.Time import Data.Typeable -import Data.Vector import GHC.Generics data GELF = GELF - { _gelfVersion :: Version - , _gelfHost :: Text - , _gelfShortMessage :: Text - , _gelfFullMessage :: Maybe Text - , _gelfTimestamp :: Maybe UTCTime - , _gelfLevel :: Maybe SyslogLevel - , _gelfLine :: Maybe Word - , _gelfFile :: Maybe Text - , _gelfAdditionalFields :: Vector Field + { _gelfVersion :: Version + , _gelfHost :: Text + , _gelfShortMessage :: Text + , _gelfFullMessage :: Maybe Text + , _gelfTimestamp :: Maybe UTCTime + , _gelfLevel :: Maybe SyslogLevel + , _gelfLine :: Maybe Word + , _gelfFile :: Maybe Text } deriving (Show, Typeable, Generic) @@ -62,15 +59,3 @@ instance ToJSON SyslogLevel where toJSON Notice = Number 5 toJSON Informational = Number 6 toJSON Debug = Number 7 - --- - -data Field - = FieldString Text - | FieldNumber Scientific - deriving (Eq, Show, Typeable, Generic) - -instance ToJSON Field where - toJSON (FieldString s) = String s - toJSON (FieldNumber n) = Number n - diff --git a/src/Graylog/UDP.hs b/src/Graylog/UDP.hs new file mode 100644 index 0000000..6aec108 --- /dev/null +++ b/src/Graylog/UDP.hs @@ -0,0 +1,19 @@ +module Graylog.UDP + ( Graylog (..) + , sendLog + + , module Graylog.Gelf + ) where + +import Network.Socket + +import Graylog.Gelf + +data Graylog + = Graylog + { _graylogHost :: String + , _graylogPort :: String + } + +sendLog :: Graylog -> GELF -> IO () +sendLog glog msg = undefined diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..604b65a --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,12 @@ +import qualified Test.Graylog.UDP (tests) + +import Test.Tasty + +main :: IO () +main = defaultMain tests + +tests :: TestTree +tests = testGroup "Graylog Library" + [ Test.Graylog.UDP.tests + ] + diff --git a/test/Test/Graylog/UDP.hs b/test/Test/Graylog/UDP.hs new file mode 100644 index 0000000..67da6fe --- /dev/null +++ b/test/Test/Graylog/UDP.hs @@ -0,0 +1,13 @@ +module Test.Graylog.UDP where + +import Test.Tasty +import Test.Tasty.HUnit + +tests :: TestTree +tests = testGroup "Test.Graylog.UDP" + [ testCase "Validation: Something" case_validateSomething + ] + +case_validateSomething :: IO () +case_validateSomething = return () + -- cgit v1.2.3