diff options
author | AndrewRademacher <andrew.rademacher@smrxt.com> | 2016-02-24 17:24:19 -0600 |
---|---|---|
committer | AndrewRademacher <andrew.rademacher@smrxt.com> | 2016-02-24 17:24:19 -0600 |
commit | 15981d57cda18a19fcb3012172a9f0994abfd97a (patch) | |
tree | b309de32b39b432ea63a275cb3db7bc4d4dd5415 | |
parent | 526966434f2248c1200427677dc3882668714693 (diff) | |
download | haskell-graylog-15981d57cda18a19fcb3012172a9f0994abfd97a.tar.gz haskell-graylog-15981d57cda18a19fcb3012172a9f0994abfd97a.tar.zst haskell-graylog-15981d57cda18a19fcb3012172a9f0994abfd97a.zip |
Added testing for UDP method.
-rw-r--r-- | graylog.cabal | 26 | ||||
-rw-r--r-- | src/Graylog/Gelf.hs | 31 | ||||
-rw-r--r-- | src/Graylog/UDP.hs | 19 | ||||
-rw-r--r-- | test/Main.hs | 12 | ||||
-rw-r--r-- | test/Test/Graylog/UDP.hs | 13 |
5 files changed, 78 insertions, 23 deletions
diff --git a/graylog.cabal b/graylog.cabal index d7d1163..b3c1a53 100644 --- a/graylog.cabal +++ b/graylog.cabal | |||
@@ -24,7 +24,33 @@ library | |||
24 | 24 | ||
25 | , aeson | 25 | , aeson |
26 | , aeson-casing | 26 | , aeson-casing |
27 | , network | ||
27 | , scientific | 28 | , scientific |
28 | , text | 29 | , text |
29 | , time | 30 | , time |
30 | , vector | 31 | , vector |
32 | |||
33 | test-suite test-state | ||
34 | type: exitcode-stdio-1.0 | ||
35 | main-is: Main.hs | ||
36 | hs-source-dirs: test | ||
37 | default-language: Haskell2010 | ||
38 | |||
39 | ghc-options: -Wall -threaded -with-rtsopts=-N -rtsopts | ||
40 | |||
41 | other-modules: Test.Graylog.UDP | ||
42 | |||
43 | build-depends: base ==4.* | ||
44 | |||
45 | , graylog | ||
46 | |||
47 | , aeson | ||
48 | , aeson-casing | ||
49 | , network | ||
50 | , scientific | ||
51 | , tasty | ||
52 | , tasty-hunit | ||
53 | , text | ||
54 | , time | ||
55 | , vector | ||
56 | |||
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 | |||
7 | import Data.Aeson (ToJSON (..), Value (..), genericToJSON, | 7 | import Data.Aeson (ToJSON (..), Value (..), genericToJSON, |
8 | toJSON) | 8 | toJSON) |
9 | import Data.Aeson.Casing | 9 | import Data.Aeson.Casing |
10 | import Data.Scientific | ||
11 | import Data.Text (Text) | 10 | import Data.Text (Text) |
12 | import Data.Time | 11 | import Data.Time |
13 | import Data.Typeable | 12 | import Data.Typeable |
14 | import Data.Vector | ||
15 | import GHC.Generics | 13 | import GHC.Generics |
16 | 14 | ||
17 | data GELF | 15 | data GELF |
18 | = GELF | 16 | = GELF |
19 | { _gelfVersion :: Version | 17 | { _gelfVersion :: Version |
20 | , _gelfHost :: Text | 18 | , _gelfHost :: Text |
21 | , _gelfShortMessage :: Text | 19 | , _gelfShortMessage :: Text |
22 | , _gelfFullMessage :: Maybe Text | 20 | , _gelfFullMessage :: Maybe Text |
23 | , _gelfTimestamp :: Maybe UTCTime | 21 | , _gelfTimestamp :: Maybe UTCTime |
24 | , _gelfLevel :: Maybe SyslogLevel | 22 | , _gelfLevel :: Maybe SyslogLevel |
25 | , _gelfLine :: Maybe Word | 23 | , _gelfLine :: Maybe Word |
26 | , _gelfFile :: Maybe Text | 24 | , _gelfFile :: Maybe Text |
27 | , _gelfAdditionalFields :: Vector Field | ||
28 | } | 25 | } |
29 | deriving (Show, Typeable, Generic) | 26 | deriving (Show, Typeable, Generic) |
30 | 27 | ||
@@ -62,15 +59,3 @@ instance ToJSON SyslogLevel where | |||
62 | toJSON Notice = Number 5 | 59 | toJSON Notice = Number 5 |
63 | toJSON Informational = Number 6 | 60 | toJSON Informational = Number 6 |
64 | toJSON Debug = Number 7 | 61 | toJSON Debug = Number 7 |
65 | |||
66 | -- | ||
67 | |||
68 | data Field | ||
69 | = FieldString Text | ||
70 | | FieldNumber Scientific | ||
71 | deriving (Eq, Show, Typeable, Generic) | ||
72 | |||
73 | instance ToJSON Field where | ||
74 | toJSON (FieldString s) = String s | ||
75 | toJSON (FieldNumber n) = Number n | ||
76 | |||
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 @@ | |||
1 | module Graylog.UDP | ||
2 | ( Graylog (..) | ||
3 | , sendLog | ||
4 | |||
5 | , module Graylog.Gelf | ||
6 | ) where | ||
7 | |||
8 | import Network.Socket | ||
9 | |||
10 | import Graylog.Gelf | ||
11 | |||
12 | data Graylog | ||
13 | = Graylog | ||
14 | { _graylogHost :: String | ||
15 | , _graylogPort :: String | ||
16 | } | ||
17 | |||
18 | sendLog :: Graylog -> GELF -> IO () | ||
19 | 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 @@ | |||
1 | import qualified Test.Graylog.UDP (tests) | ||
2 | |||
3 | import Test.Tasty | ||
4 | |||
5 | main :: IO () | ||
6 | main = defaultMain tests | ||
7 | |||
8 | tests :: TestTree | ||
9 | tests = testGroup "Graylog Library" | ||
10 | [ Test.Graylog.UDP.tests | ||
11 | ] | ||
12 | |||
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 @@ | |||
1 | module Test.Graylog.UDP where | ||
2 | |||
3 | import Test.Tasty | ||
4 | import Test.Tasty.HUnit | ||
5 | |||
6 | tests :: TestTree | ||
7 | tests = testGroup "Test.Graylog.UDP" | ||
8 | [ testCase "Validation: Something" case_validateSomething | ||
9 | ] | ||
10 | |||
11 | case_validateSomething :: IO () | ||
12 | case_validateSomething = return () | ||
13 | |||