Skip to content

Commit

Permalink
add a test for scanVendoredDep with fullFileUploads set to True
Browse files Browse the repository at this point in the history
  • Loading branch information
spatten committed Apr 22, 2023
1 parent e8892b8 commit cef6eae
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions integration-test/Analysis/LicenseScannerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import Path (reldir, (</>))
import Path.IO qualified as PIO
import Srclib.Types (
LicenseSourceUnit (licenseSourceUnitLicenseUnits),
LicenseUnit (licenseUnitFiles, licenseUnitName),
emptyLicenseUnit,
LicenseUnit (licenseUnitFiles, licenseUnitName, licenseUnitData),
emptyLicenseUnit, LicenseUnitData (licenseUnitDataContents),
)
import Test.Hspec (Spec, describe, it, shouldBe)
import Types (GlobFilter (GlobFilter), LicenseScanPathFilters (..))
import Data.Text (Text)
import qualified Data.Text as Text

recursiveArchive :: FixtureArtifact
recursiveArchive =
Expand Down Expand Up @@ -60,6 +62,29 @@ vendoredDep =
-- ├── quux
-- │ └── QUUX_LICENSE
-- └── something.rb

mitLicense :: Text
mitLicense = Text.dropEnd 1 $ Text.unlines ([
"Permission is hereby granted, free of charge, to any person obtaining",
"a copy of this software and associated documentation files (the",
"\"Software\"), to deal in the Software without restriction, including",
"without limitation the rights to use, copy, modify, merge, publish,",
"distribute, sublicense, and/or sell copies of the Software, and to",
"permit persons to whom the Software is furnished to do so, subject to",
"the following conditions:",
"",
"The above copyright notice and this permission notice shall be",
"included in all copies or substantial portions of the Software.",
"",
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,",
"EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF",
"MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.",
"IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY",
"CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,",
"TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE",
"SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
])

spec :: Spec
spec = do
describe "scanVendoredDep" $ do
Expand All @@ -75,6 +100,29 @@ spec = do
NE.sort (NE.map licenseUnitName us) `shouldBe` NE.fromList ["No_license_found", "apache-2.0", "mit"]
NE.sort (licenseUnitFiles mitUnit) `shouldBe` NE.fromList ["vendor/foo/bar/MIT_LICENSE", "vendor/foo/bar/baz/SOMETHING_LICENSE", "vendor/foo/bar/baz/quux/QUUX_LICENSE"]
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo/bar/bar_apache.rb", "vendor/foo/bar/baz/something.rb"]
-- no Contents since we're running themis with --srclib-with-matches
licenseUnitDataContents <$> licenseUnitData mitUnit `shouldBe` NE.fromList [Nothing, Nothing, Nothing]
where
mitUnit :: LicenseUnit
mitUnit = fromMaybe emptyLicenseUnit (head' $ NE.filter (\u -> licenseUnitName u == "mit") us)
apacheUnit :: LicenseUnit
apacheUnit = fromMaybe emptyLicenseUnit (head' $ NE.filter (\u -> licenseUnitName u == "apache-2.0") us)

it "should get full file contents from Themis if fullFileUploads is true" $ do
extractedDir <- getArtifact recursiveArchive
let scanDir = extractedDir </> [reldir|cli-license-scan-integration-test-fixtures-main/recursive-archive|]
units <- runStack . runDiagnostics . ignoreStickyLogger . runExecIO . runReadFSIO . fmap licenseSourceUnitLicenseUnits $ scanVendoredDep scanDir Nothing True vendoredDep
PIO.removeDirRecur extractedDir
case units of
Failure ws eg -> fail (show (renderFailure ws eg "An issue occurred"))
Success _ us -> do
length us `shouldBe` 3
NE.sort (NE.map licenseUnitName us) `shouldBe` NE.fromList ["No_license_found", "apache-2.0", "mit"]
NE.sort (licenseUnitFiles mitUnit) `shouldBe` NE.fromList ["vendor/foo/bar/MIT_LICENSE", "vendor/foo/bar/baz/SOMETHING_LICENSE", "vendor/foo/bar/baz/quux/QUUX_LICENSE"]
NE.sort (licenseUnitFiles apacheUnit) `shouldBe` NE.fromList ["vendor/foo/bar/bar_apache.rb", "vendor/foo/bar/baz/something.rb"]
-- We should get Contents since we're running themis with --srclib-with-full-files
licenseUnitDataContents <$> licenseUnitData mitUnit `shouldBe` NE.fromList [Just mitLicense, Just mitLicense, Just mitLicense]

where
mitUnit :: LicenseUnit
mitUnit = fromMaybe emptyLicenseUnit (head' $ NE.filter (\u -> licenseUnitName u == "mit") us)
Expand Down

0 comments on commit cef6eae

Please sign in to comment.