-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
191 additions
and
259 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
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,57 @@ | ||
module StackDeploy.NamedTemplate | ||
( NamedTemplate(..) | ||
, NamedTemplateMap | ||
, TemplateName | ||
, mkNamedTemplate | ||
, stratosphereTemplateEncodePretty | ||
, testTree | ||
) | ||
where | ||
|
||
import Data.Ord (compare) | ||
import StackDeploy.Prelude | ||
import System.FilePath ((<.>), (</>)) | ||
|
||
import qualified Data.Aeson.Encode.Pretty as JSON | ||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified Data.Map.Strict as Map | ||
import qualified Data.Text.Encoding as Text | ||
import qualified Stratosphere | ||
import qualified Test.Tasty as Tasty | ||
import qualified Test.Tasty.MGolden as Tasty | ||
|
||
type TemplateName = BoundText "StackDeploy.Template.Name" | ||
|
||
data NamedTemplate = NamedTemplate | ||
{ name :: TemplateName | ||
, template :: Stratosphere.Template | ||
} | ||
deriving stock (Eq, Show) | ||
|
||
type NamedTemplateMap = Map TemplateName Stratosphere.Template | ||
|
||
-- | Pretty print a template using aeson-pretty. | ||
stratosphereTemplateEncodePretty :: Stratosphere.Template -> LBS.ByteString | ||
stratosphereTemplateEncodePretty = JSON.encodePretty' config | ||
where | ||
config | ||
= JSON.defConfig | ||
{ JSON.confIndent = JSON.Spaces 2 | ||
, JSON.confCompare = compare | ||
} | ||
|
||
mkNamedTemplate :: TemplateName -> Stratosphere.Template -> NamedTemplate | ||
mkNamedTemplate = NamedTemplate | ||
|
||
testTree :: NamedTemplateMap -> Tasty.TestTree | ||
testTree map | ||
= Tasty.testGroup "template" (templateTest <$> Map.toList map) | ||
|
||
templateTest :: (TemplateName, Stratosphere.Template) -> Tasty.TestTree | ||
templateTest (name, template) = | ||
Tasty.goldenTest | ||
(convertText name) | ||
expectedPath | ||
(pure . Text.decodeUtf8 . LBS.toStrict $ stratosphereTemplateEncodePretty template) | ||
where | ||
expectedPath = "test" </> "template" </> convertText name <.> ".json" |
Oops, something went wrong.