|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | + |
| 3 | +module Stack.Types.BuildPlanSpec where |
| 4 | + |
| 5 | +import Data.Aeson.Extended (WithJSONWarnings(..)) |
| 6 | +import Data.ByteString (ByteString) |
| 7 | +import qualified Data.ByteString.Char8 as S8 |
| 8 | +import Data.Yaml (decode) |
| 9 | +import Stack.Types.BuildPlan |
| 10 | +import Test.Hspec |
| 11 | + |
| 12 | +spec :: Spec |
| 13 | +spec = |
| 14 | + describe "PackageLocation" $ do |
| 15 | + describe "Archive" $ do |
| 16 | + describe "github" $ do |
| 17 | + let decode' :: ByteString -> Maybe (WithJSONWarnings (PackageLocation Subdirs)) |
| 18 | + decode' = decode |
| 19 | + |
| 20 | + it "'github' and 'commit' keys" $ do |
| 21 | + let contents :: ByteString |
| 22 | + contents = |
| 23 | + S8.pack |
| 24 | + (unlines |
| 25 | + [ "github: oink/town" |
| 26 | + , "commit: abc123" |
| 27 | + ]) |
| 28 | + let expected :: PackageLocation Subdirs |
| 29 | + expected = |
| 30 | + PLArchive Archive |
| 31 | + { archiveUrl = "https://github.com/oink/town/archive/abc123.tar.gz" |
| 32 | + , archiveSubdirs = DefaultSubdirs |
| 33 | + , archiveHash = Nothing |
| 34 | + } |
| 35 | + decode' contents `shouldBe` Just (WithJSONWarnings expected []) |
| 36 | + |
| 37 | + it "'github', 'commit', and 'subdirs' keys" $ do |
| 38 | + let contents :: ByteString |
| 39 | + contents = |
| 40 | + S8.pack |
| 41 | + (unlines |
| 42 | + [ "github: oink/town" |
| 43 | + , "commit: abc123" |
| 44 | + , "subdirs:" |
| 45 | + , " - foo" |
| 46 | + ]) |
| 47 | + let expected :: PackageLocation Subdirs |
| 48 | + expected = |
| 49 | + PLArchive Archive |
| 50 | + { archiveUrl = "https://github.com/oink/town/archive/abc123.tar.gz" |
| 51 | + , archiveSubdirs = ExplicitSubdirs ["foo"] |
| 52 | + , archiveHash = Nothing |
| 53 | + } |
| 54 | + decode' contents `shouldBe` Just (WithJSONWarnings expected []) |
| 55 | + |
| 56 | + it "does not parse GitHub repo with no slash" $ do |
| 57 | + let contents :: ByteString |
| 58 | + contents = |
| 59 | + S8.pack |
| 60 | + (unlines |
| 61 | + [ "github: oink" |
| 62 | + , "commit: abc123" |
| 63 | + ]) |
| 64 | + decode' contents `shouldBe` Nothing |
| 65 | + |
| 66 | + it "does not parse GitHub repo with leading slash" $ do |
| 67 | + let contents :: ByteString |
| 68 | + contents = |
| 69 | + S8.pack |
| 70 | + (unlines |
| 71 | + [ "github: /oink" |
| 72 | + , "commit: abc123" |
| 73 | + ]) |
| 74 | + decode' contents `shouldBe` Nothing |
| 75 | + |
| 76 | + it "does not parse GitHub repo with trailing slash" $ do |
| 77 | + let contents :: ByteString |
| 78 | + contents = |
| 79 | + S8.pack |
| 80 | + (unlines |
| 81 | + [ "github: oink/" |
| 82 | + , "commit: abc123" |
| 83 | + ]) |
| 84 | + decode' contents `shouldBe` Nothing |
| 85 | + |
| 86 | + it "does not parse GitHub repo with more than one slash" $ do |
| 87 | + let contents :: ByteString |
| 88 | + contents = |
| 89 | + S8.pack |
| 90 | + (unlines |
| 91 | + [ "github: oink/town/here" |
| 92 | + , "commit: abc123" |
| 93 | + ]) |
| 94 | + decode' contents `shouldBe` Nothing |
0 commit comments