Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3649 from input-output-hk/yamlValidation
Browse files Browse the repository at this point in the history
[DEVOPS-1057] automated testing of yaml files
  • Loading branch information
cleverca22 authored Sep 27, 2018
2 parents e73ed4d + 8a3a5c0 commit 4d849bf
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ let
stylishHaskell = pkgs.callPackage ./scripts/test/stylish.nix { inherit (cardanoPkgs) stylish-haskell; inherit src localLib; };
walletIntegration = pkgs.callPackage ./scripts/test/wallet/integration/build-test.nix { inherit walletIntegrationTests; };
swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; };
yamlValidation = pkgs.callPackage ./scripts/test/yamlValidation.nix { inherit cardanoPkgs; inherit (localLib) runHaskell; };
};
cardano-sl-explorer-frontend = (import ./explorer/frontend {
inherit system config gitrev pkgs;
Expand Down
10 changes: 10 additions & 0 deletions lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ in lib // (rec {
forEnvironments = f: lib.mapAttrs'
(name: env: lib.nameValuePair env.attr (f (env // { environment = name; })))
(lib.filterAttrs (name: env: !env.private) environments);

runHaskell = name: hspkgs: deps: env: code: let
ghc = hspkgs.ghcWithPackages deps;
builtBinary = pkgs.runCommand "${name}-binary" { buildInputs = [ ghc ]; } ''
mkdir -p $out/bin/
ghc ${pkgs.writeText "${name}.hs" code} -o $out/bin/${name}
'';
in pkgs.runCommand name env ''
${builtBinary}/bin/$name
'';
})
4 changes: 2 additions & 2 deletions log-configs/template-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ rotation:
keepFiles: 20
loggerTree:
severity: Debug+
file: {{file}}
file: tmpFileName
handlers:
- { name: "json"
, filepath: "{{file}}.json"
, filepath: "tmpFileName.json"
, logsafety: PublicLogLevel
, severity: Debug
, backend: FileJsonBE }
4 changes: 2 additions & 2 deletions scripts/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function logs {

local conf_file="$conf_dir/$log_file.yaml"
# log files are named under the $logs_dir directory
# sed "s|{{file}}|$logs_dir/$log_file|g" "$template" > "$conf_file"
sed "s|{{file}}|$log_file|g" "$template" > "$conf_file"
# sed "s|tmpFileName|$logs_dir/$log_file|g" "$template" > "$conf_file"
sed "s|tmpFileName|$log_file|g" "$template" > "$conf_file"
echo -n " --json-log=$logs_dir/logs/node$i.json "
echo -n " --logs-prefix $logs_dir/logs --log-config $conf_file "
}
Expand Down
56 changes: 56 additions & 0 deletions scripts/test/yamlValidation.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ runHaskell, cardanoPkgs }:

runHaskell "yamlValidation" cardanoPkgs (ps: with ps; [
cardano-sl-util
cardano-sl-infra
split
]) {
logConfigs = [
../../log-configs/daedalus.yaml
#../../log-configs/greppable.yaml
../../log-configs/connect-to-cluster.yaml
../../log-configs/cluster.yaml
../../log-configs/template-demo.yaml
];
topologyConfigs = [
../../docs/network/example-topologies/mainnet-staging.yaml
../../docs/network/example-topologies/behind-nat-no-dns.yaml
../../docs/network/example-topologies/behind-nat-with-dns.yaml
../../docs/network/example-topologies/p2p.yaml
../../docs/network/example-topologies/static-no-dns.yaml
../../docs/network/example-topologies/static-with-dns.yaml
../../docs/network/example-topologies/traditional.yaml
];
} ''
import Pos.Util.Log.LoggerConfig (LoggerConfig)
import Pos.Infra.Network.Yaml (Topology)
import Data.List.Split
import System.Environment
import Data.Yaml
import Control.Monad.Catch
import Data.Monoid
main :: IO ()
main = do
runTest "logConfigs" checkLogConfig
runTest "topologyConfigs" checkTopology
outpath <- getEnv "out"
writeFile outpath "done"
runTest :: FromJSON a => String -> (String -> IO a) -> IO ()
runTest var func = do
paths <- getEnv var
let
pathList = splitOn " " paths
doTest path = do
putStrLn $ "testing: " <> path
func path
mapM_ doTest pathList
checkLogConfig :: String -> IO LoggerConfig
checkLogConfig path = do
either throwM return =<< decodeFileEither path
checkTopology :: String -> IO Topology
checkTopology path = either throwM return =<< decodeFileEither path
''

0 comments on commit 4d849bf

Please sign in to comment.