Add local state persistence tests.

This commit is contained in:
Chris Penner 2021-12-21 11:41:38 -06:00
parent e8917e101d
commit f9bfaa6943
2 changed files with 43 additions and 1 deletions

View File

@ -9,6 +9,9 @@ module Unison.Codebase.Editor.Git
withIOError,
withStatus,
withIsolatedRepo,
-- * Exported for testing
gitCacheDir,
)
where
@ -145,7 +148,10 @@ pullRepo repo@(ReadGitRepo uri) = do
remoteRef :: Text
remoteRef = fromMaybe "HEAD" maybeRemoteRef
goFromScratch :: (MonadIO m, MonadError GitProtocolError m) => m ()
goFromScratch = do wipeDir localPath; checkOutNew localPath Nothing
goFromScratch = do
liftIO . putStrLn $ "FROM SCRATCH"
wipeDir localPath
checkOutNew localPath Nothing
isEmptyGitRepo :: MonadIO m => FilePath -> m Bool
isEmptyGitRepo localPath = liftIO $

View File

@ -22,6 +22,8 @@ import Unison.Symbol (Symbol)
import Unison.Test.Ucm (CodebaseFormat, Transcript)
import qualified Unison.Test.Ucm as Ucm
import Unison.WatchKind (pattern TestWatch)
import qualified Data.Text.IO as Text
import Unison.Codebase.Editor.Git (gitCacheDir)
transcriptOutputFile :: String -> FilePath
transcriptOutputFile name =
@ -37,6 +39,7 @@ test :: Test ()
test = scope "gitsync22" . tests $
fastForwardPush :
nonFastForwardPush :
localStatePersistence :
destroyedRemote :
flip map [(Ucm.CodebaseFormat2, "sc")]
\(fmt, name) -> scope name $ tests [
@ -635,6 +638,39 @@ fastForwardPush = scope "fastforward-push" do
|]
ok
localStatePersistence :: Test ()
localStatePersistence = scope "local-state-persistence" do
repo <- io initGitRepo
cachedRepoDir <- io $ gitCacheDir (Text.pack repo)
-- Create some local state in the cached git repo.
let someFilePath = cachedRepoDir </> "myfile.txt"
let someText = "SOME TEXT"
io $ do
codebase <- Ucm.initCodebase Ucm.CodebaseFormat2
-- Push some state the remote codebase
-- Then pull to ensure we have a non-empty local git repo.
void $ Ucm.runTranscript codebase [i|
```ucm
.lib> alias.type ##Nat Nat
.lib> push.create ${repo}
.lib> pull ${repo}
```
|]
-- Write a file to our local git cache to represent some changes we may have made to our
-- codebase, e.g. a migration.
Text.writeFile someFilePath someText
void $ Ucm.runTranscript codebase [i|
```ucm
.lib> pull ${repo}
.lib> push ${repo}
```
|]
-- We expect the state in the cached git repo to remain untouched iff the remote
-- hasn't changed. This is helpful for when we need to migrate a remote codebase,
-- we don't want to re-migrate if nothing has changed.
txt <- io $ Text.readFile someFilePath
expectEqual someText txt
nonFastForwardPush :: Test ()
nonFastForwardPush = scope "non-fastforward-push" do
io do