-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse fractional arguments to flags
Parse fractional numbers as arguments to flags for the `HEALTHCHECK` instruction. The `HEALTHCHECK` instruction can take an `--interval`, `--timeout` or `--start-period` flag specifying details to the healthcheck repetition behaviour. This can also be specified with fractions (of secods, minutes or hours), e.g.: ```Dockerfile HEALTHCHECK \ --interval=0.5s \ CMD curl -f http://localhost ``` With the caveat that somewhere from parsing to conversion to a DiffTime some precision is lost (DiffTime has a precision of 10^-12s), this change adds support for the arguments to these interval flags to be specified as fractional numbers. fixes: hadolint/hadolint#893 Signed-off-by: Moritz Röhrich <[email protected]>
- Loading branch information
1 parent
34e9ddf
commit d675b4e
Showing
6 changed files
with
95 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module Language.Docker.ParseHealthcheckSpec where | ||
|
||
import Data.Default.Class (def) | ||
import Language.Docker.Syntax | ||
import Test.Hspec | ||
import TestHelper | ||
import qualified Data.Set as Set | ||
import qualified Data.Text as Text | ||
|
||
|
||
spec :: Spec | ||
spec = do | ||
describe "parse HEALTHCHECK" $ do | ||
it "parse healthcheck with interval" $ | ||
assertAst | ||
"HEALTHCHECK --interval=5m \\\nCMD curl -f http://localhost/" | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs "curl -f http://localhost/" (Just 300) Nothing Nothing Nothing | ||
] | ||
it "parse healthcheck with retries" $ | ||
assertAst | ||
"HEALTHCHECK --retries=10 CMD curl -f http://localhost/" | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs "curl -f http://localhost/" Nothing Nothing Nothing (Just $ Retries 10) | ||
] | ||
it "parse healthcheck with timeout" $ | ||
assertAst | ||
"HEALTHCHECK --timeout=10s CMD curl -f http://localhost/" | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs "curl -f http://localhost/" Nothing (Just 10) Nothing Nothing | ||
] | ||
it "parse healthcheck with start-period" $ | ||
assertAst | ||
"HEALTHCHECK --start-period=2m CMD curl -f http://localhost/" | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs "curl -f http://localhost/" Nothing Nothing (Just 120) Nothing | ||
] | ||
it "parse healthcheck with all flags" $ | ||
assertAst | ||
"HEALTHCHECK --start-period=2s --timeout=1m --retries=3 --interval=5s CMD curl -f http://localhost/" | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs | ||
"curl -f http://localhost/" | ||
(Just 5) | ||
(Just 60) | ||
(Just 2) | ||
(Just $ Retries 3) | ||
] | ||
it "parse healthcheck with no flags" $ | ||
assertAst | ||
"HEALTHCHECK CMD curl -f http://localhost/" | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs "curl -f http://localhost/" Nothing Nothing Nothing Nothing | ||
] | ||
|
||
it "fractional arguments to flags" $ | ||
let file = | ||
Text.unlines | ||
[ "HEALTHCHECK \\", | ||
" --interval=0.5s \\", | ||
" --timeout=0.1s \\", | ||
" --start-period=0.2s \\", | ||
" CMD curl -f http://localhost" | ||
] | ||
in assertAst | ||
file | ||
[ Healthcheck $ | ||
Check $ | ||
CheckArgs | ||
"curl -f http://localhost" | ||
( Just 0.5 ) | ||
( Just 0.10000000149 ) | ||
( Just 0.20000000298 ) | ||
Nothing | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters