mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-13 09:55:35 +03:00
Add local state persistence tests.
This commit is contained in:
parent
e8917e101d
commit
f9bfaa6943
@ -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 $
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user