Skip to content

Commit

Permalink
[FLORA-255] Fix the dependents view to include other namespaces (#256)
Browse files Browse the repository at this point in the history
* [FLORA-255] Fix the `dependents` view to include other namespaces

fix #255

* Fix tests
  • Loading branch information
tchoutri authored Oct 27, 2022
1 parent 0cab27a commit c209aa2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.0.6 -- XXXX-XX-XX

* Fix the `dependents` materialized view (#256)

## v1.0.5 -- 2022-10-22

* Reorder the package page columns in mobile view (#233)
Expand Down
2 changes: 1 addition & 1 deletion environment.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. environment.sh
. ./environment.sh

export FLORA_HTTP_PORT=8085
export FLORA_ENVIRONMENT="test"
Expand Down
1 change: 0 additions & 1 deletion ghc-tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ exclude_paths:
- dist
- dist-newstyle
- assets
language: GHC2021
extensions:
- BangPatterns
- BlockArguments
Expand Down
2 changes: 1 addition & 1 deletion migrations/20211113195849_create_dependents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ create materialized view dependents (
inner join "package_components" as pc2 on pc2."release_id" = r1."release_id"
inner join "requirements" as r3 on r3."package_component_id" = pc2."package_component_id"
inner join "packages" as p4 on p4."package_id" = r3."package_id"
where (p4.name != p0.name) and (p4.namespace != p0.namespace);
where (p4.name, p4.namespace) != (p0.name, p0.namespace);

create index on dependents (name, dependent_id);
create unique index on dependents (name, namespace, dependent_id);
51 changes: 41 additions & 10 deletions test/Flora/PackageSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec :: Fixtures -> TestEff TestTree
spec _fixtures =
testThese
"package tests"
[ testThis "Insert base and its dependencies, and fetch it" testInsertBase
[ testThis "Check Cabal dependencies" testCabalDeps
, testThis "Insert containers and its dependencies" testInsertContainers
, testThis "@haskell/base belongs to the \"Prelude\" category" testThatBaseisInPreludeCategory
, testThis "@hackage/semigroups belongs to appropriate categories" testThatSemigroupsIsInMathematicsAndDataStructures
Expand All @@ -40,10 +40,39 @@ spec _fixtures =
, testThis "@hackage/time components have the correct conditions in their metadata" testTimeConditions
]

testInsertBase :: TestEff ()
testInsertBase = do
result <- Query.getPackageByNamespaceAndName (Namespace "haskell") (PackageName "base")
assertEqual (Just (PackageName "base")) (preview (_Just % #name) result)
testCabalDeps :: TestEff ()
testCabalDeps = do
dependencies <- do
Just cabalPackage <- Query.getPackageByNamespaceAndName (Namespace "haskell") (PackageName "Cabal")
releases <- Query.getReleases (cabalPackage ^. #packageId)
let latestRelease = maximumBy (compare `on` version) releases
Query.getAllRequirements (latestRelease ^. #releaseId)
assertEqual
( Set.fromList
[ PackageName "Win32"
, PackageName "array"
, PackageName "base"
, PackageName "binary"
, PackageName "bytestring"
, PackageName "containers"
, PackageName "deepseq"
, PackageName "directory"
, PackageName "fail"
, PackageName "filepath"
, PackageName "mtl"
, PackageName "parsec"
, PackageName "pretty"
, PackageName "process"
, PackageName "semigroups"
, PackageName "tagged"
, PackageName "text"
, PackageName "time"
, PackageName "transformers"
, PackageName "unix"
, PackageName "void"
]
)
(Set.fromList $ view _2 <$> Vector.toList dependencies)

testInsertContainers :: TestEff ()
testInsertContainers = do
Expand Down Expand Up @@ -94,26 +123,28 @@ testCorrectNumberInHaskellNamespace = do

testBytestringDependents :: TestEff ()
testBytestringDependents = do
results <- Query.getPackageDependentsWithLatestVersion (Namespace "haskell") (PackageName "bytestring")
results <- Query.getAllPackageDependentsWithLatestVersion (Namespace "haskell") (PackageName "bytestring")
assertEqual
6
17
(Vector.length results)

testNoSelfDependent :: TestEff ()
testNoSelfDependent = do
results <- Query.getPackageDependents (Namespace "haskell") (PackageName "text")
results <- Query.getAllPackageDependents (Namespace "haskell") (PackageName "text")
let resultSet = Set.fromList . fmap (view #name) $ Vector.toList results
assertEqual
resultSet
( Set.fromList
[ PackageName "flora"
[ PackageName "Cabal"
, PackageName "flora"
, PackageName "hashable"
, PackageName "jose"
, PackageName "parsec"
, PackageName "relude"
, PackageName "semigroups"
, PackageName "xml"
]
)
resultSet

testBytestringDependencies :: TestEff ()
testBytestringDependencies = do
Expand Down
15 changes: 11 additions & 4 deletions test/Flora/TestUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import Test.Tasty (TestTree)
import Test.Tasty qualified as Test
import Test.Tasty.HUnit qualified as Test

import Effectful.Fail (Fail, runFailIO)
import Effectful.Log (Log, Logger)
import Flora.Environment
import Flora.Environment.Config (LoggingDestination (..))
Expand All @@ -104,16 +105,16 @@ import FloraWeb.Client
import FloraWeb.Server.Logging qualified as Logging
import Log.Backend.StandardOutput qualified as Log

type TestEff = Eff '[DB, Log, Time, IOE]
type TestEff = Eff '[Fail, DB, Log, Time, IOE]

data Fixtures = Fixtures
{ hackageUser :: User
}
deriving stock (Generic, Show, Eq)

getFixtures :: ([DB, IOE] :>> es) => Eff es Fixtures
getFixtures :: ([Fail, DB, IOE] :>> es) => Eff es Fixtures
getFixtures = do
hackageUser <- fromJust <$> Query.getUserByUsername "hackage-user"
Just hackageUser <- Query.getUserByUsername "hackage-user"
pure Fixtures{..}

importAllPackages :: Fixtures -> TestEff ()
Expand All @@ -130,6 +131,7 @@ runTestEff comp pool = runEff $
runCurrentTimeIO
. Log.runLog "flora-test" stdOutLogger LogAttention
. runDB pool
. runFailIO
$ comp

testThis :: String -> TestEff () -> TestEff TestTree
Expand All @@ -147,7 +149,12 @@ testThese groupName tests = fmap (Test.testGroup groupName) newTests
assertBool :: Bool -> TestEff ()
assertBool boolean = liftIO $ Test.assertBool "" boolean

-- | 'assertEqual' @expected@ @actual@
{-| Make sure an expected value is the same as the actual one.
Usage:
>>> assertEqual expected actual
-}
assertEqual :: (Eq a, Show a) => a -> a -> TestEff ()
assertEqual expected actual = liftIO $ Test.assertEqual "" expected actual

Expand Down
2 changes: 2 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Optics.Core
import System.IO
import Test.Tasty (defaultMain, testGroup)

import Effectful.Fail (runFailIO)
import Effectful.Log qualified as Log
import Flora.CabalSpec qualified as CabalSpec
import Flora.CategorySpec qualified as CategorySpec
Expand All @@ -27,6 +28,7 @@ main = do
runCurrentTimeIO
. Log.runLog "flora-test" stdOutLogger LogAttention
. runDB (env ^. #pool)
. runFailIO
$ do
testMigrations
f' <- getFixtures
Expand Down

0 comments on commit c209aa2

Please sign in to comment.