Skip to content

A peer-to-peer stack for code collaboration

Add tests for 'rad diff propose'

Thomas Scholtes36872d15afee
diff --git a/README.md b/README.md
index 057ecf3..2392a53 100644
--- a/README.md
+++ b/README.md
@@ -52,9 +52,10 @@ into version control.
### End-to-end Tests
The end-to-end test suite is run with `stack test :e2e`. It requires you to
-start up an IPFS test network with
+start up an IPFS test network and the Raicle daemon.
docker-compose -f test/docker-compose.yaml up -d ipfs-test-network
+ RAD_IPFS_API_URL=http://localhost:19301 stack exec -- radicle-daemon --filePrefix test
If you use `docker-compose up` for the first time you will also need to
initialize the IPFS test network with
@@ -62,6 +63,8 @@ initialize the IPFS test network with
echo '{"radicle": true}' | \
docker-compose -f test/docker-compose.yaml exec -T ipfs-test-network ipfs dag put
+You can reset the test daemon’s state by removing the file
+`./local/share/radicle/testdaemon-follows`.
### Troubleshooting
diff --git a/test/e2e/DiffAppTest.hs b/test/e2e/DiffAppTest.hs
new file mode 100644
index 0000000..25581cc
--- /dev/null
+++ b/test/e2e/DiffAppTest.hs
@@ -0,0 +1,28 @@
+-- | Test the Radicle diff app.
+module DiffAppTest
+ ( test_diff_propose
+ ) where
+
+import Protolude
+
+import Test.E2ESupport
+
+test_diff_propose :: TestTree
+test_diff_propose = testCaseSteps "diff propose" $ \step -> do
+ step "Init project"
+ _ <- runTestCommand "rad-create-keys" []
+ _ <- runTestCommand "git" ["config", "--global", "user.name", "Alice"]
+ _ <- runTestCommand "git" ["config", "--global", "user.email", "[email protected]"]
+ _ <- runTestCommand' "rad-project" ["init"] ["project-name", "project desc"]
+ _ <- runTestCommand "git" ["commit", "--allow-empty", "--message", "first commit"]
+ commitSha <- runTestCommand "git" ["rev-parse", "--short", "HEAD"]
+
+ step "rad diff propose"
+ _ <- runTestCommand "rad-diff" ["propose", "HEAD"]
+
+ listOutput <- runTestCommand "rad-diff" ["list"]
+ assertContains listOutput $ "(pending) [Alice] " <> commitSha <> " - first commit | DIFF 0"
+
+ showOutput <- runTestCommand "rad-diff" ["show", "0"]
+ assertContains showOutput $ "(pending) [Alice] " <> commitSha <> " - first commit | DIFF 0"
+ assertContains showOutput $ "Comments\n---"
diff --git a/test/e2e/Test/E2ESupport.hs b/test/e2e/Test/E2ESupport.hs
index 384dd04..96e6d32 100644
--- a/test/e2e/Test/E2ESupport.hs
+++ b/test/e2e/Test/E2ESupport.hs
@@ -9,9 +9,11 @@ module Test.E2ESupport
, testCaseSteps
, runTestCommand
+ , runTestCommand'
, TestTree
, assertEqual
+ , assertContains
) where
import Prelude (String, unwords)
@@ -78,6 +80,17 @@ testCaseSteps name mkTest =
assertEqual :: (HasCallStack, MonadIO m, Eq a, Show a) => Text -> a -> a -> m ()
assertEqual msg a a' = liftIO $ HUnit.assertEqual (toS msg) a a'
+assertFailure :: (HasCallStack, MonadIO m) => Text -> m a
+assertFailure msg = liftIO $ HUnit.assertFailure $ toS msg
+
+-- | @assertContains str substr@ throws as assertion error if @substr@ is not
+-- contained in @str@
+assertContains :: (HasCallStack, MonadIO m) => Text -> Text -> m ()
+assertContains str substr =
+ if substr `T.isInfixOf` str
+ then pure ()
+ else assertFailure $ "\"" <> substr <> "\" is not contained in \"" <> str <> "\""
+
-- * Run commands
-- | Like 'runTestCommand'' but does not provide input to stdin.