packages feed

language-docker-16.0.0: test/Language/Docker/ParseAddSpec.hs

module Language.Docker.ParseAddSpec (spec) where

import Data.Default
import qualified Data.Text as Text
import Language.Docker.Syntax
import TestHelper
import Test.Hspec


spec :: Spec
spec = do
  describe "ADD" $ do
    it "simple ADD" $
      let file = Text.unlines ["ADD . /app", "ADD http://foo.bar/baz ."]
       in assertAst
            file
            [ Add ( AddArgs [SourcePath "."] (TargetPath "/app") ) def,
              Add
                ( AddArgs [SourcePath "http://foo.bar/baz"] (TargetPath ".") )
                def
            ]
    it "multifiles ADD" $
      let file = Text.unlines ["ADD foo bar baz /app"]
       in assertAst
            file
            [ Add
                ( AddArgs
                    (fmap SourcePath ["foo", "bar", "baz"])
                    (TargetPath "/app")
                )
                def
            ]
    it "list of quoted files" $
      let file = Text.unlines ["ADD [\"foo\", \"bar\", \"baz\", \"/app\"]"]
       in assertAst
            file
            [ Add
                ( AddArgs
                    (fmap SourcePath ["foo", "bar", "baz"])
                    (TargetPath "/app")
                )
                def
            ]
    it "with checksum flag" $
       let file = Text.unlines ["ADD --checksum=sha256:24454f830cdd http://www.example.com/foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["http://www.example.com/foo"]) (TargetPath "bar") )
                ( AddFlags (Checksum "sha256:24454f830cdd") NoChown NoChmod NoLink NoKeepGitDir NoUnpack [] )
            ]
    it "with chown flag" $
      let file = Text.unlines ["ADD --chown=root:root foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum (Chown "root:root") NoChmod NoLink NoKeepGitDir NoUnpack [] )
            ]
    it "with chmod flag" $
      let file = Text.unlines ["ADD --chmod=640 foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown (Chmod "640") NoLink NoKeepGitDir NoUnpack [] )
            ]

    it "with link flag" $
      let file = Text.unlines ["ADD --link foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod ( Link True ) NoKeepGitDir NoUnpack [] )
            ]

    it "with link flag explicit true" $
      let file = Text.unlines ["ADD --link=true foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod ( Link True ) NoKeepGitDir NoUnpack [] )
            ]

    it "with link flag explicit false" $
      let file = Text.unlines ["ADD --link=false foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod ( Link False ) NoKeepGitDir NoUnpack [] )
            ]

    it "with keep-git-dir flag" $
      let file = Text.unlines ["ADD --keep-git-dir foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink ( KeepGitDir True ) NoUnpack [] )
            ]

    it "with keep-git-dir flag explicit true" $
      let file = Text.unlines ["ADD --keep-git-dir=true foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink ( KeepGitDir True ) NoUnpack [] )
            ]

    it "with keep-git-dir flag explicit false" $
      let file = Text.unlines ["ADD --keep-git-dir=false foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink ( KeepGitDir False ) NoUnpack [] )
            ]

    it "with chown and chmod flag" $
      let file = Text.unlines ["ADD --chown=root:root --chmod=640 foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum (Chown "root:root") (Chmod "640") NoLink NoKeepGitDir NoUnpack [] )
            ]
    it "with chown and chmod flag other order" $
      let file = Text.unlines ["ADD --chmod=640 --chown=root:root foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum (Chown "root:root") (Chmod "640") NoLink NoKeepGitDir NoUnpack [] )
            ]
    it "with all flags" $
      let file =
            Text.unlines ["ADD --chmod=640 --chown=root:root --checksum=sha256:24454f830cdd --link --keep-git-dir --unpack foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags
                    ( Checksum "sha256:24454f830cdd" )
                    ( Chown "root:root" )
                    ( Chmod "640" )
                    ( Link True )
                    ( KeepGitDir True )
                    ( Unpack True )
                    []
                )
            ]
    it "list of quoted files and chown" $
      let file =
            Text.unlines
              [ "ADD --chown=user:group [\"foo\", \"bar\", \"baz\", \"/app\"]" ]
       in assertAst
            file
            [ Add
                ( AddArgs
                    (fmap SourcePath ["foo", "bar", "baz"])
                    (TargetPath "/app")
                )
                ( AddFlags NoChecksum (Chown "user:group") NoChmod NoLink NoKeepGitDir NoUnpack [] )
            ]
    it "with unpack flag" $
      let file = Text.unlines ["ADD --unpack http://www.example.com/archive.tar.gz /download"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["http://www.example.com/archive.tar.gz"]) (TargetPath "/download") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink NoKeepGitDir (Unpack True) [] )
            ]
    it "with unpack flag explicit true" $
      let file = Text.unlines ["ADD --unpack=true http://www.example.com/archive.tar.gz /download"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["http://www.example.com/archive.tar.gz"]) (TargetPath "/download") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink NoKeepGitDir (Unpack True) [] )
            ]
    it "with unpack flag explicit false" $
      let file = Text.unlines ["ADD --unpack=false my-archive.tar.gz ."]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["my-archive.tar.gz"]) (TargetPath ".") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink NoKeepGitDir (Unpack False) [] )
            ]
    it "with exclude flag" $
      let file = Text.unlines ["ADD --exclude=*.tmp foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink NoKeepGitDir NoUnpack [Exclude "*.tmp"] )
            ]
    it "with multiple exclude flags" $
      let file = Text.unlines ["ADD --exclude=*.tmp --exclude=*.log foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum NoChown NoChmod NoLink NoKeepGitDir NoUnpack [Exclude "*.tmp", Exclude "*.log"] )
            ]
    it "with exclude and other flags" $
      let file = Text.unlines ["ADD --chown=root:root --exclude=*.tmp foo bar"]
       in assertAst
            file
            [ Add
                ( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
                ( AddFlags NoChecksum (Chown "root:root") NoChmod NoLink NoKeepGitDir NoUnpack [Exclude "*.tmp"] )
            ]