Skip to content

Commit

Permalink
Split out sandwich-contexts.minio, fixes #84
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed May 16, 2024
1 parent a727068 commit be1245e
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 61 deletions.
1 change: 1 addition & 0 deletions demos/demo-minio/demo-minio.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ executable demo-minio
, network
, sandwich
, sandwich-contexts
, sandwich-contexts-minio
, string-interpolate
, text
, unliftio
Expand Down
1 change: 1 addition & 0 deletions demos/demo-minio/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- network
- sandwich
- sandwich-contexts
- sandwich-contexts-minio
- string-interpolate
- text
- unliftio
Expand Down
4 changes: 1 addition & 3 deletions sandwich-contexts-docker/.dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
((haskell-mode
. (
(haskell-process-args-stack-ghci . ("--ghci-options=-ferror-spans" "--no-build" "--no-load"
"--stack-yaml" "/home/tom/codedown/stack.yaml"
"codedown-core:lib"
"codedown-test-contexts:lib"
"sandwich-contexts-docker:lib"
))
)))
3 changes: 0 additions & 3 deletions sandwich-contexts-docker/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ library:
- containers
- docker-engine
- exceptions
- filepath
- hostname
- http-client
- http-types
Expand All @@ -54,11 +53,9 @@ library:
- relude
- retry
- safe
- sandwich-contexts
- string-interpolate
- text
- unliftio-core
- vector

tests:
tests:
Expand Down
3 changes: 0 additions & 3 deletions sandwich-contexts-docker/sandwich-contexts-docker.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ library
, containers
, docker-engine
, exceptions
, filepath
, hostname
, http-client
, http-types
Expand All @@ -56,12 +55,10 @@ library
, retry
, safe
, sandwich
, sandwich-contexts
, string-interpolate
, text
, unliftio
, unliftio-core
, vector
default-language: Haskell2010

test-suite tests
Expand Down
1 change: 0 additions & 1 deletion sandwich-contexts-kubernetes/.dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
((haskell-mode
. (
(haskell-process-args-stack-ghci . ("--ghci-options=-ferror-spans" "--no-build" "--no-load"
"--stack-yaml" "/home/tom/tools/sandwich/stack.yaml"
"sandwich-contexts-kubernetes:lib"
))
)))
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ module Test.Sandwich.Contexts.Kubernetes.MinioS3Server (
, withK8SMinioS3Server
) where

import Test.Sandwich.Contexts.Kubernetes.Cluster
import Test.Sandwich.Contexts.Kubernetes.MinioS3Server.Parsing
import Test.Sandwich.Contexts.Kubernetes.Types
import Test.Sandwich.Contexts.Kubernetes.Util.UUID
import Control.Monad
import Control.Monad.Catch (MonadMask)
import Control.Monad.IO.Unlift
Expand All @@ -24,6 +20,10 @@ import Network.Minio
import Relude
import System.Exit
import Test.Sandwich
import Test.Sandwich.Contexts.Kubernetes.Cluster
import Test.Sandwich.Contexts.Kubernetes.MinioS3Server.Parsing
import Test.Sandwich.Contexts.Kubernetes.Types
import Test.Sandwich.Contexts.Kubernetes.Util.UUID
import Test.Sandwich.Contexts.MinIO
import Test.Sandwich.Contexts.Waits
import UnliftIO.Environment
Expand Down
1 change: 1 addition & 0 deletions sandwich-contexts-kubernetes/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ library:
- base64-bytestring
- bytestring
- sandwich-contexts
- sandwich-contexts-minio
- containers
- exceptions
- filepath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ library
, safe
, sandwich
, sandwich-contexts
, sandwich-contexts-minio
, string-interpolate
, temporary
, text
Expand Down
6 changes: 6 additions & 0 deletions sandwich-contexts-minio/.dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
((haskell-mode
. (
(haskell-process-args-stack-ghci . ("--ghci-options=-ferror-spans" "--no-build" "--no-load"
"sandwich-contexts-minio:lib"
))
)))
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Test.Sandwich
import Test.Sandwich.Contexts.Files
import Test.Sandwich.Contexts.Nix
import Test.Sandwich.Contexts.Types
import Test.Sandwich.Contexts.Types.S3
import Test.Sandwich.Contexts.Util.Aeson
import Test.Sandwich.Contexts.Util.Container
import Test.Sandwich.Contexts.Util.UUID
Expand All @@ -66,41 +67,6 @@ import UnliftIO.Process

-- * Types

testS3Server :: Label "testS3Server" TestS3Server
testS3Server = Label

data TestS3Server = TestS3Server {
testS3ServerAddress :: NetworkAddress
-- | The address of the S3 server within its container, if present.
-- Useful if you're doing container-to-container networking.
, testS3ServerContainerAddress :: Maybe NetworkAddress
, testS3ServerAccessKeyId :: Text
, testS3ServerSecretAccessKey :: Text
, testS3ServerBucket :: Maybe Text
, testS3ServerHttpMode :: HttpMode
} deriving (Show, Eq)

data HttpMode = HttpModeHttp | HttpModeHttps | HttpModeHttpsNoValidate
deriving (Show, Eq)

type HasTestS3Server context = HasLabel context "testS3Server" TestS3Server

testS3ServerEndpoint :: TestS3Server -> Text
testS3ServerEndpoint serv@(TestS3Server {testS3ServerAddress=(NetworkAddressTCP hostname port)}) =
[i|#{s3Protocol serv}://#{hostname}:#{port}|]
testS3ServerEndpoint serv@(TestS3Server {testS3ServerAddress=(NetworkAddressUnix path)}) =
[i|#{s3Protocol serv}://#{path}|]

testS3ServerContainerEndpoint :: TestS3Server -> Maybe Text
testS3ServerContainerEndpoint serv@(TestS3Server {testS3ServerContainerAddress=(Just (NetworkAddressTCP hostname port))}) =
Just [i|#{s3Protocol serv}://#{hostname}:#{port}|]
testS3ServerContainerEndpoint serv@(TestS3Server {testS3ServerContainerAddress=(Just (NetworkAddressUnix path))}) =
Just [i|#{s3Protocol serv}://#{path}|]
testS3ServerContainerEndpoint _ = Nothing

s3Protocol :: TestS3Server -> Text
s3Protocol (TestS3Server {..}) = if testS3ServerHttpMode == HttpModeHttp then "http" else "https"

testS3ServerConnectInfo :: TestS3Server -> ConnectInfo
testS3ServerConnectInfo testServ@(TestS3Server {..}) =
fromString (toString (testS3ServerEndpoint testServ))
Expand Down
69 changes: 69 additions & 0 deletions sandwich-contexts-minio/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: sandwich-contexts-minio
version: 0.1.0.0
synopsis: Sandwich test contexts for MinIO
description: Please see README.md
author: Tom McLaughlin
maintainer: tom@codedown.io
copyright: 2024 Tom McLaughlin
dependencies:
- base
- sandwich
- unliftio

default-extensions:
- OverloadedStrings
- QuasiQuotes
- NamedFieldPuns
- RecordWildCards
- ScopedTypeVariables
- LambdaCase
- MultiWayIf
- ViewPatterns
- TupleSections
- FlexibleContexts
- NoImplicitPrelude
- NumericUnderscores

ghc-options:
- -Wunused-packages # For GHC 8.10.1 and above
- -Wall
# - -Wpartial-fields
# - -Wredundant-constraints # Reports HasCallStack, so keep it off normally

library:
source-dirs: lib
exposed-modules:
- Test.Sandwich.Contexts.MinIO
dependencies:
- aeson
- containers
- exceptions
- filepath
- minio-hs
- monad-logger
- mtl
- network
- network-uri
- relude
- retry
- safe
- sandwich-contexts
- string-interpolate
- temporary
- text
- unliftio-core

tests:
tests:
main: Main.hs
source-dirs: test
ghc-options:
- -Wall
- -rtsopts
- -threaded
dependencies:
- filepath
- postgresql-simple
- relude
- sandwich-contexts
- string-interpolate
92 changes: 92 additions & 0 deletions sandwich-contexts-minio/sandwich-contexts-minio.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

name: sandwich-contexts-minio
version: 0.1.0.0
synopsis: Sandwich test contexts for MinIO
description: Please see README.md
author: Tom McLaughlin
maintainer: tom@codedown.io
copyright: 2024 Tom McLaughlin
build-type: Simple

library
exposed-modules:
Test.Sandwich.Contexts.MinIO
other-modules:
Paths_sandwich_contexts_minio
hs-source-dirs:
lib
default-extensions:
OverloadedStrings
QuasiQuotes
NamedFieldPuns
RecordWildCards
ScopedTypeVariables
LambdaCase
MultiWayIf
ViewPatterns
TupleSections
FlexibleContexts
NoImplicitPrelude
NumericUnderscores
ghc-options: -Wunused-packages -Wall
build-depends:
aeson
, base
, containers
, exceptions
, filepath
, minio-hs
, monad-logger
, mtl
, network
, network-uri
, relude
, retry
, safe
, sandwich
, sandwich-contexts
, string-interpolate
, temporary
, text
, unliftio
, unliftio-core
default-language: Haskell2010

test-suite tests
type: exitcode-stdio-1.0
main-is: Main.hs
other-modules:
Spec
Spec.Basic
Paths_sandwich_contexts_minio
hs-source-dirs:
test
default-extensions:
OverloadedStrings
QuasiQuotes
NamedFieldPuns
RecordWildCards
ScopedTypeVariables
LambdaCase
MultiWayIf
ViewPatterns
TupleSections
FlexibleContexts
NoImplicitPrelude
NumericUnderscores
ghc-options: -Wunused-packages -Wall -Wall -rtsopts -threaded
build-depends:
base
, filepath
, postgresql-simple
, relude
, sandwich
, sandwich-contexts
, string-interpolate
, unliftio
default-language: Haskell2010
11 changes: 11 additions & 0 deletions sandwich-contexts-minio/test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

module Main where

import Relude
import qualified Spec
import Test.Sandwich


main :: IO ()
main = runSandwichWithCommandLineArgs defaultOptions $
Spec.tests
25 changes: 25 additions & 0 deletions sandwich-contexts-minio/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{-# OPTIONS_GHC -F -pgmF sandwich-discover #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

module Spec where

import Test.Sandwich

#insert_test_imports


tests :: TopSpec
tests = $(getSpecFromFolder defaultGetSpecFromFolderOptions)

-- testsPooled :: PooledSpec
-- testsPooled = $(getSpecFromFolder $ defaultGetSpecFromFolderOptions {
-- getSpecCombiner = 'describeParallel
-- , getSpecIndividualSpecHooks = 'poolify
-- , getSpecWarnOnParseError = NoWarnOnParseError
-- })

-- main :: IO ()
-- main = pooledMain (return ()) testsPooled
14 changes: 14 additions & 0 deletions sandwich-contexts-minio/test/Spec/Basic.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Spec.Basic where

import Data.String.Interpolate
import Relude
import System.FilePath
import Test.Sandwich
import Test.Sandwich.Contexts.Nix
import UnliftIO.Directory


tests :: TopSpec
tests = describe "Tests" $ do
it "should work" $ do
2 `shouldBe` 2
4 changes: 1 addition & 3 deletions sandwich-contexts/.dir-locals.el
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
((haskell-mode
. (
(haskell-process-args-stack-ghci . ("--ghci-options=-ferror-spans" "--no-build" "--no-load"
"--stack-yaml" "/home/tom/codedown/stack.yaml"
"codedown-core:lib"
"codedown-test-contexts:lib"
"sandwich-contexts:lib"
))
)))
Loading

0 comments on commit be1245e

Please sign in to comment.