Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Reis
argotest
Commits
22d79ef9
Commit
22d79ef9
authored
Dec 12, 2018
by
Valentin Reis
Browse files
[feature] Log parsing and minor Argotest.hs refactoring tasks.
parent
7991c67f
Pipeline
#4623
passed with stage
in 26 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
argotest/src/Argotest.hs
View file @
22d79ef9
...
...
@@ -21,7 +21,7 @@ import System.Posix.Signals
data
StackArgs
=
StackArgs
{
dargs
::
Text
--"Daemon arguments. Properly quote this."
,
app
::
FilePath
--"Input file, target application script
"
,
app
::
Text
--"Target application call, sh+path valid
"
,
manifest
::
FilePath
--"Input file, manifest."
,
cmd_out
::
FilePath
--"Output file, application stdout"
,
cmd_err
::
FilePath
--"Output file, application stderr"
...
...
@@ -33,7 +33,7 @@ data StackArgs = StackArgs
instance
Default
StackArgs
where
def
=
StackArgs
{
dargs
=
""
,
app
=
"echo
\"
Dummy app:
Hello
w
orld
!
\"
"
,
app
=
"echo
\"
Hello
W
orld
\"
"
,
manifest
=
"manifests/basic.json"
,
cmd_out
=
"cmd_out.log"
,
cmd_err
=
"cmd_err.log"
...
...
@@ -50,7 +50,6 @@ colorShell color s = setC color *> s *> setC White
printInfo
::
Text
->
Shell
()
printError
::
Text
->
Shell
()
printWarning
::
Text
->
Shell
()
printInfo
=
printf
(
"Info:"
%
s
)
printWarning
=
colorShell
Yellow
.
printf
(
"Warning:"
%
s
)
printError
=
colorShell
Red
.
printf
(
"Error:"
%
s
)
...
...
@@ -106,6 +105,6 @@ prepareDaemonShell dargs daemon_out daemon_err nrm_log = do
ExitFailure
n
->
do
printInfo
"Contents of argo_nodeos_config_exit_message:
\n
"
view
$
cat
[
"./argo_nodeos_config_exit_message"
]
die
(
"Clean config failed with exit code "
<>
repr
n
)
printInfo
$
format
(
"Running the daemon
: see
main log at "
%
fp
%
"
\n
"
)
nrm_log
printInfo
$
format
(
"Running the daemon
,
main log at "
%
fp
%
"
, stdout at "
%
fp
%
", stderr at "
%
fp
%
"
\n
"
)
nrm_log
daemon_out
daemon_err
export
"ARGO_NODEOS_CONFIG"
(
format
fp
confPath'
)
return
$
sh
$
inshell
(
format
(
fp
%
" "
%
s
%
" --nrm_log="
%
fp
%
" >"
%
fp
%
" 2>"
%
fp
)
daemonPath
dargs
nrm_log
daemon_out
daemon_err
)
empty
argotk.hs
View file @
22d79ef9
#!
/
usr
/
bin
/
env
nix
-
shell
#!
nix
-
shell
-
i
runhaskell
-
A
test
#!
/
usr
/
bin
/
env
runhaskell
{-# LANGUAGE
OverloadedStrings
...
...
@@ -20,11 +19,20 @@ opts :: Parser (IO ())
opts
=
subparser
(
command
"clean"
(
info
(
pure
$
runClean
def
)
idm
)
<>
help
"Target for the greeting"
<>
command
"daemon"
(
info
(
pure
$
runDaemon
def
)
idm
)
<>
command
"helloworld"
(
info
(
pure
$
run
SimpleStack
def
)
idm
)
)
<>
command
"helloworld"
(
info
(
pure
$
run
HelloWorld
def
)
idm
)
)
main
::
IO
()
main
=
join
$
execParser
(
info
(
opts
<**>
helper
)
idm
)
runHelloWorld
::
StackArgs
->
IO
()
runHelloWorld
a
@
StackArgs
{
..
}
=
do
let
passStr
=
"HelloWorldFromApp"
runSimpleStack
$
a
{
app
=
format
(
"echo "
%
s
)
passStr
}
readTextFile
cmd_err
>>=
\
x
->
case
match
(
has
"HelloWorldFromApp"
)
x
of
[]
->
die
(
"Hello world app failed to run."
)
_
->
sh
$
printInfo
"The hello world app executed properly in a
\
\
container and its message was received by `cmd`.
\n
"
runSimpleStack
::
StackArgs
->
IO
()
runSimpleStack
a
@
StackArgs
{
..
}
=
sh
$
do
cleanLeftovers
daemon_out
daemon_err
cmd_out
cmd_err
time_file
nrm_log
...
...
@@ -39,7 +47,7 @@ runSimpleStack a@StackArgs{..} = sh $ do
printInfo
"Launching the application through cmd.
\n
"
(
_
,
t
)
<-
time
$
shell
(
format
(
"cmd run -u toto "
%
fp
%
" "
%
fp
%
" > "
%
fp
%
" 2>"
%
fp
)
manifest
app
cmd_out
cmd_err
)
empty
>>=
\
case
shell
(
format
(
"cmd run -u toto "
%
fp
%
" "
%
s
%
" > "
%
fp
%
" 2>"
%
fp
)
manifest
app
cmd_out
cmd_err
)
empty
>>=
\
case
ExitSuccess
->
printInfo
"cmd has exited successfuly.
\n
"
ExitFailure
n
->
die
(
"cmd failed with exit code "
<>
repr
n
<>
" . The application logs are at "
<>
repr
cmd_out
<>
" "
<>
repr
cmd_err
)
...
...
@@ -54,6 +62,5 @@ runClean StackArgs{..} = sh $
cleanLeftovers
daemon_out
daemon_err
cmd_out
cmd_err
time_file
nrm_log
runDaemon
::
StackArgs
->
IO
()
runDaemon
StackArgs
{
..
}
=
sh
$
do
daemonShell
<-
prepareDaemonShell
dargs
daemon_out
daemon_err
nrm_log
daemonShell
runDaemon
StackArgs
{
..
}
=
sh
$
prepareDaemonShell
dargs
daemon_out
daemon_err
nrm_log
>>=
id
default.nix
View file @
22d79ef9
...
...
@@ -19,13 +19,36 @@ let
in
rec
{
dev-
before
lib
=
hpkgs
.
shellFor
{
dev-lib
=
hpkgs
.
shellFor
{
packages
=
p
:
with
p
;
[
argotest
];
withHoogle
=
true
;
buildInputs
=
with
hpkgs
;
with
pkgs
;
[
cabal-install
ghcid
hlint
sysstat
hdevtools
];
};
dev-test
=
pkgs
.
stdenv
.
mkDerivation
rec
{
name
=
"env"
;
env
=
pkgs
.
buildEnv
{
name
=
name
;
paths
=
buildInputs
;
};
buildInputs
=
[
(
hpkgs
.
ghcWithPackages
(
p
:
[
p
.
argotest
p
.
turtle
p
.
data-default
p
.
managed
p
.
ansi-terminal
p
.
unix
p
.
system-filepath
p
.
async
]))
containers
hpkgs
.
hdevtools
hpkgs
.
hlint
hpkgs
.
ghcid
amg
nrm
];
};
test
=
pkgs
.
stdenv
.
mkDerivation
rec
{
name
=
"env"
;
env
=
pkgs
.
buildEnv
{
name
=
name
;
paths
=
buildInputs
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment