Skip to content

Commit 09bd30e

Browse files
committed
[cli] refactor: move some E2E to integration stanza
1 parent fd48873 commit 09bd30e

File tree

7 files changed

+98
-94
lines changed

7 files changed

+98
-94
lines changed

cli/anti.cabal

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -295,55 +295,33 @@ executable anti-agent
295295

296296
test-suite anti-E2E-test
297297
-- Import common warning flags.
298-
import: warnings
298+
import: warnings
299299

300300
-- Base language which the package is written in.
301-
default-language: Haskell2010
301+
default-language: Haskell2010
302302

303303
-- Modules included in this executable, other than Main.
304-
other-modules:
305-
E2ESpec
306-
Lib.Github.OracleValidationSpec
307-
MPFS.APISpec
304+
other-modules: E2ESpec
308305

309306
-- LANGUAGE extensions used by modules in this package.
310307
-- other-extensions:
311308

312309
-- The interface type and version of the test suite.
313-
type: exitcode-stdio-1.0
310+
type: exitcode-stdio-1.0
314311

315312
-- Directories containing source files.
316-
hs-source-dirs: test-E2E
313+
hs-source-dirs: test-E2E
317314

318315
-- The entrypoint to the test suite.
319-
main-is: Main.hs
316+
main-is: Main.hs
320317

321318
-- Test dependencies.
322319
build-depends:
323-
, aeson
324-
, anti
325320
, base
326-
, base16-bytestring
327321
, bytestring
328-
, canonical-json
329-
, cardano-ledger-alonzo
330-
, cardano-ledger-api
331-
, cardano-ledger-babbage
332-
, cardano-ledger-binary
333-
, cardano-ledger-core
334-
, cardano-strict-containers
335-
, exceptions
336322
, github
337323
, hspec
338-
, http-client
339-
, http-client-tls
340-
, lens
341-
, plutus-tx
342324
, process
343-
, servant-client
344-
, text
345-
346-
build-tool-depends: hspec-discover:hspec-discover
347325

348326
test-suite anti-unit-test
349327
-- Import common warning flags.
@@ -452,36 +430,52 @@ library test-lib
452430

453431
test-suite anti-integration-test
454432
-- Import common warning flags.
455-
import: warnings
433+
import: warnings
456434

457435
-- Base language which the package is written in.
458-
default-language: Haskell2010
436+
default-language: Haskell2010
459437

460438
-- Modules included in this executable, other than Main.
461439
other-modules:
440+
Lib.Github.OracleValidationSpec
462441
Lib.GitHubSpec
442+
MPFS.APISpec
463443

464444
-- LANGUAGE extensions used by modules in this package.
465445
-- other-extensions:
466446

467447
-- The interface type and version of the test suite.
468-
type: exitcode-stdio-1.0
448+
type: exitcode-stdio-1.0
469449

470450
-- Directories containing source files.
471-
hs-source-dirs: test-integration
451+
hs-source-dirs: test-integration
472452

473453
-- The entrypoint to the test suite.
474-
main-is: Main.hs
454+
main-is: Main.hs
475455

476456
-- Test dependencies.
477457
build-depends:
458+
, aeson
478459
, anti
479460
, base
461+
, base16-bytestring
480462
, bytestring
463+
, canonical-json
464+
, cardano-ledger-alonzo
465+
, cardano-ledger-api
466+
, cardano-ledger-babbage
467+
, cardano-ledger-binary
468+
, cardano-ledger-core
469+
, cardano-strict-containers
481470
, directory
482-
, hspec
471+
, exceptions
483472
, github
473+
, hspec
474+
, http-client
475+
, http-client-tls
476+
, lens
484477
, path
478+
, plutus-tx
479+
, servant-client
485480
, temporary
486-
487-
build-tool-depends: hspec-discover:hspec-discover
481+
, text

cli/src/Lib/GitHub.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ import Path
5252
, File
5353
, Path
5454
, Rel
55-
55+
, parent
56+
, parseRelDir
5657
, parseRelFile
5758
, toFilePath
58-
, (</>), parseRelDir, parent
59+
, (</>)
5960
)
6061
import Streaming
6162
import Streaming.Prelude (yield)
6263
import Streaming.Prelude qualified as S
63-
import Text.JSON.Canonical
6464
import System.Directory (createDirectoryIfMissing)
65+
import Text.JSON.Canonical
6566

6667
data GithubResponseError
6768
= GithubResponseErrorRepositoryNotFound

cli/test-E2E/Main.hs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
import Data.ByteString.Char8 qualified as BC
22
import E2ESpec (e2eSpec)
33
import GitHub (Auth (..))
4-
import Lib.Github.OracleValidationSpec
5-
( existenceSpec
6-
, roleSpecs
7-
, userSpec
8-
)
9-
import MPFS.APISpec (mpfsAPISpec)
104
import System.Environment (lookupEnv)
115
import Test.Hspec (beforeAll, hspec)
126

137
main :: IO ()
148
main = hspec $ do
15-
beforeAll getPAT $ do
16-
existenceSpec
17-
roleSpecs
189
beforeAll getPAT $ do
1910
e2eSpec
20-
mpfsAPISpec
21-
userSpec
2211

2312
tryGetPAT :: IO (Maybe Auth)
2413
tryGetPAT = fmap (OAuth . BC.pack) <$> lookupEnv "ANTI_GITHUB_PAT"
Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
{-# LANGUAGE TemplateHaskell #-}
22

3-
module Lib.GitHubSpec (spec) where
3+
module Lib.GitHubSpec (githubSpec) where
44

5-
import Control.Monad (void)
65
import Core.Types.Basic (Commit (..), Repository (..))
7-
import Data.ByteString.Char8 qualified as BC
8-
import GitHub (Auth (OAuth))
6+
import GitHub (Auth)
97
import Lib.GitHub (copyGithubDirectory)
108
import Path
11-
( Dir,
12-
Path,
13-
parseAbsDir,
14-
toFilePath,
15-
(</>),
16-
mkRelDir,
17-
mkRelFile,
18-
parseRelFile,
19-
File,
20-
Rel )
9+
( Dir
10+
, File
11+
, Path
12+
, Rel
13+
, mkRelDir
14+
, mkRelFile
15+
, parseAbsDir
16+
, toFilePath
17+
, (</>)
18+
)
2119
import System.Directory (doesFileExist)
22-
import System.Environment (getEnv)
2320
import System.IO.Temp (withSystemTempDirectory)
2421
import Test.Hspec
25-
( Spec
26-
, beforeAll
22+
( SpecWith
2723
, describe
2824
, it
2925
, shouldReturn
3026
)
3127

32-
boot :: IO Auth
33-
boot = OAuth . BC.pack <$> getEnv "ANTI_GITHUB_PAT"
34-
3528
repo :: Repository
3629
repo =
3730
Repository
@@ -54,26 +47,20 @@ dockerComposePath = $(mkRelFile "docker-compose.yaml")
5447
testnetPath :: Path Rel File
5548
testnetPath = $(mkRelFile "testnet.yaml")
5649

57-
spec :: Spec
58-
spec = do
59-
describe "Path lib" $ do
60-
it "parses relative directory" $ do
61-
void $ parseRelFile @IO "antithesis-test/somefile.txt"
62-
beforeAll boot $ do
63-
describe "Lib.GitHub" $ do
64-
it "downloads a directory" $ \pat ->
65-
withSystemTempDirectory "github-test" $ \targetPath -> do
66-
targetDir <- parseAbsDir targetPath
67-
copyGithubDirectory pat repo commit srcPath targetDir
68-
`shouldReturn` Right ()
69-
let readmeAbsPath = targetDir </> srcPath </> readmePath
70-
print $ "Checking for file: " ++ toFilePath readmeAbsPath
71-
doesFileExist (toFilePath readmeAbsPath) `shouldReturn` True
72-
let dockerComposeAbsPath =
73-
targetDir
74-
</> srcPath
75-
</> dockerComposePath
76-
doesFileExist (toFilePath dockerComposeAbsPath)
77-
`shouldReturn` True
78-
let testnetAbsPath = targetDir </> srcPath </> testnetPath
79-
doesFileExist (toFilePath testnetAbsPath) `shouldReturn` True
50+
githubSpec :: SpecWith Auth
51+
githubSpec = describe "Lib.GitHub" $ do
52+
it "downloads a directory" $ \pat ->
53+
withSystemTempDirectory "github-test" $ \targetPath -> do
54+
targetDir <- parseAbsDir targetPath
55+
copyGithubDirectory pat repo commit srcPath targetDir
56+
`shouldReturn` Right ()
57+
let readmeAbsPath = targetDir </> srcPath </> readmePath
58+
doesFileExist (toFilePath readmeAbsPath) `shouldReturn` True
59+
let dockerComposeAbsPath =
60+
targetDir
61+
</> srcPath
62+
</> dockerComposePath
63+
doesFileExist (toFilePath dockerComposeAbsPath)
64+
`shouldReturn` True
65+
let testnetAbsPath = targetDir </> srcPath </> testnetPath
66+
doesFileExist (toFilePath testnetAbsPath) `shouldReturn` True
File renamed without changes.
File renamed without changes.

cli/test-integration/Main.hs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
1+
import Data.ByteString.Char8 qualified as BC
2+
import GitHub (Auth (..))
3+
import Lib.GitHubSpec (githubSpec)
4+
import Lib.Github.OracleValidationSpec
5+
( existenceSpec
6+
, roleSpecs
7+
, userSpec
8+
)
9+
import MPFS.APISpec (mpfsAPISpec)
10+
import System.Environment (lookupEnv)
11+
import Test.Hspec (beforeAll, hspec)
12+
13+
main :: IO ()
14+
main = hspec $ do
15+
beforeAll getPAT $ do
16+
githubSpec
17+
existenceSpec
18+
roleSpecs
19+
mpfsAPISpec
20+
userSpec
21+
22+
tryGetPAT :: IO (Maybe Auth)
23+
tryGetPAT = fmap (OAuth . BC.pack) <$> lookupEnv "ANTI_GITHUB_PAT"
24+
25+
getPAT :: IO Auth
26+
getPAT = do
27+
mpat <- tryGetPAT
28+
case mpat of
29+
Just pat -> return pat
30+
Nothing ->
31+
error
32+
"Environment variable ANTI_GITHUB_PAT is not set. \
33+
\ Please set it to some valid GitHub Personal Access Token with \
34+
\ read access to public repositories."

0 commit comments

Comments
 (0)