Skip to content

Commit 96317e2

Browse files
committed
Move FicusSpec to unit tests and use Test.Effect
1 parent 9543639 commit 96317e2

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

spectrometer.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ test-suite unit-tests
657657
Erlang.Rebar3TreeSpec
658658
Extra.ListSpec
659659
Extra.TextSpec
660+
Ficus.FicusSpec
660661
Fortran.FpmTomlSpec
661662
Fossa.API.TypesSpec
662663
Go.GlideLockSpec
@@ -758,7 +759,6 @@ test-suite integration-tests
758759
Analysis.CocoapodsSpec
759760
Analysis.ElixirSpec
760761
Analysis.ErlangSpec
761-
Analysis.FicusSpec
762762
Analysis.FixtureExpectationUtils
763763
Analysis.FixtureUtils
764764
Analysis.GoSpec
Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE QuasiQuotes #-}
33

4-
module Analysis.FicusSpec (spec) where
4+
module Ficus.FicusSpec (spec) where
55

66
import App.Fossa.Ficus.Analyze (analyzeWithFicus)
77
import App.Fossa.Ficus.Types (FicusAnalysisResults (..), FicusSnippetScanResults (..), FicusStrategy (FicusStrategySnippetScan, FicusStrategyVendetta), FicusVendoredDependencyScanResults (FicusVendoredDependencyScanResults))
88
import App.Types (ProjectRevision (..))
99
import Control.Carrier.Diagnostics (runDiagnostics)
1010
import Control.Carrier.Stack (runStack)
1111
import Control.Carrier.StickyLogger (ignoreStickyLogger)
12+
import Control.Effect.Lift (sendIO)
1213
import Control.Timeout (Duration (Seconds))
1314
import Data.List (isInfixOf)
1415
import Data.String.Conversion (toText)
@@ -21,67 +22,70 @@ import Path (Dir, Path, Rel, reldir, (</>))
2122
import Path.IO qualified as PIO
2223
import Srclib.Types (SourceUnit (sourceUnitName))
2324
import System.Environment (lookupEnv)
25+
import Test.Effect (expectationFailure', it', shouldBe', shouldSatisfy')
2426
import Test.Hspec
2527
import Text.URI (mkURI)
2628

2729
fixtureDir :: Path Rel Dir
28-
fixtureDir = [reldir|integration-test/Analysis/testdata/ficus|]
30+
fixtureDir = [reldir|test/Ficus/testdata|]
2931

3032
spec :: Spec
3133
spec = do
3234
describe "Ficus snippet scanning integration" $ do
33-
it "should run ficus binary successfully" $ do
35+
it' "should run ficus binary successfully" $ do
3436
-- Check for API configuration from environment
35-
maybeApiKey <- lookupEnv "FOSSA_API_KEY"
36-
maybeEndpoint <- lookupEnv "FOSSA_ENDPOINT"
37+
maybeApiKey <- sendIO $ lookupEnv "FOSSA_API_KEY"
38+
maybeEndpoint <- sendIO $ lookupEnv "FOSSA_ENDPOINT"
3739

3840
apiOpts <- case (maybeApiKey, maybeEndpoint) of
39-
(Just keyStr, Just endpointStr) -> do
40-
uri <- case mkURI (toText endpointStr) of
41-
Just validUri -> pure validUri
42-
Nothing -> fail $ "Invalid API endpoint URL: " ++ endpointStr
43-
let opts = ApiOpts (Just uri) (ApiKey (toText keyStr)) (Seconds 60)
44-
pure (Just opts)
41+
(Just keyStr, Just endpointStr) ->
42+
case mkURI (toText endpointStr) of
43+
Just uri -> do
44+
let opts = ApiOpts (Just uri) (ApiKey (toText keyStr)) (Seconds 60)
45+
pure (Just opts)
46+
Nothing -> do
47+
expectationFailure' $ "Invalid API endpoint URL: " ++ endpointStr
48+
pure Nothing
4549
_ -> pure Nothing
4650

47-
currentDir <- PIO.getCurrentDir
51+
currentDir <- sendIO PIO.getCurrentDir
4852
let testDataDir = currentDir </> fixtureDir
4953
revision = ProjectRevision "ficus-integration-test" "testdata-123456" (Just "integration-test")
5054

5155
-- Check if test data exists
52-
testDataExists <- PIO.doesDirExist testDataDir
53-
testDataExists `shouldBe` True
56+
testDataExists <- sendIO $ PIO.doesDirExist testDataDir
57+
testDataExists `shouldBe'` True
5458

5559
let strategies = [FicusStrategySnippetScan, FicusStrategyVendetta]
5660

57-
result <- runStack . runDiagnostics . ignoreStickyLogger . ignoreLogger . runExecIO . runReadFSIO $ analyzeWithFicus testDataDir apiOpts revision strategies Nothing (Just 10) Nothing
61+
result <- sendIO $ runStack . runDiagnostics . ignoreStickyLogger . ignoreLogger . runExecIO . runReadFSIO $ analyzeWithFicus testDataDir apiOpts revision strategies Nothing (Just 10) Nothing
5862

5963
case result of
6064
Success _warnings analysisResult -> do
6165
case analysisResult of
6266
Just results -> do
6367
case snippetScanResults results of
6468
Just snippetResults -> do
65-
ficusSnippetScanResultsAnalysisId snippetResults `shouldSatisfy` (> 0)
69+
ficusSnippetScanResultsAnalysisId snippetResults `shouldSatisfy'` (> 0)
6670
_ -> do
6771
-- No snippet scan results returned - this is acceptable for integration testing
68-
True `shouldBe` True
72+
True `shouldBe'` True
6973

7074
case vendoredDependencyScanResults results of
7175
Just (FicusVendoredDependencyScanResults (Just srcUnit)) -> do
72-
sourceUnitName srcUnit `shouldBe` "ficus-vendored-dependencies"
76+
sourceUnitName srcUnit `shouldBe'` "ficus-vendored-dependencies"
7377
_ -> do
7478
-- No vendetta results returned - this is acceptable for integration testing
75-
True `shouldBe` True
76-
_ -> fail "Ficus analysis returned no results unexpectedly."
79+
True `shouldBe'` True
80+
_ -> expectationFailure' "Ficus analysis returned no results unexpectedly."
7781
Failure _warnings errors -> do
7882
let failureMsg = show errors
7983
case apiOpts of
8084
Just _ -> do
8185
-- With API credentials, accept 404/temp-storage errors as valid connectivity tests
8286
if "404" `isInfixOf` failureMsg || "temp-storage" `isInfixOf` failureMsg || "Status(" `isInfixOf` failureMsg
83-
then True `shouldBe` True -- Expected API connectivity issue
84-
else fail ("Ficus integration test failed unexpectedly: " ++ failureMsg)
87+
then True `shouldBe'` True -- Expected API connectivity issue
88+
else expectationFailure' ("Ficus integration test failed unexpectedly: " ++ failureMsg)
8589
Nothing -> do
8690
-- Without API credentials, analysis failure is expected
87-
True `shouldBe` True
91+
True `shouldBe'` True
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)