|
| 1 | +Class UnitTest.SourceControl.Git.Sync Extends UnitTest.SourceControl.Git.AbstractTest |
| 2 | +{ |
| 3 | + |
| 4 | +Method TestSync() |
| 5 | +{ |
| 6 | + do $$$LogMessage("set up remote repo on filesystem") |
| 7 | + set remoteDir = ##class(%Library.File).TempFilename()_"d" |
| 8 | + if '##class(%File).CreateDirectoryChain(remoteDir,.ret) { |
| 9 | + $$$ThrowStatus($$$ERROR($$$GeneralError,"failed to create directory: "_ret)) |
| 10 | + } |
| 11 | + do $zf(-100,"/SHELL","git","init",remoteDir) |
| 12 | + do $zf(- 100, "/SHELL", "git", "-C", remoteDir, "config", "user.email", "[email protected]") |
| 13 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "config", "user.name", "Unit Test") |
| 14 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "checkout", "-b", "live") |
| 15 | + do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass1.cls","Class TestGit.SampleClass1 {}") |
| 16 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") |
| 17 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "initial commit in remote for unit test") |
| 18 | + do $$$LogMessage("initialize local repo cloning remote") |
| 19 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).Clone(remoteDir_"/.git")) |
| 20 | + do $$$LogMessage("set default merge branch to live and enable basic mode") |
| 21 | + set settings = ##class(SourceControl.Git.Settings).%New() |
| 22 | + set settings.defaultMergeBranch = "live" |
| 23 | + set settings.basicMode = "system" |
| 24 | + set settings.systemBasicMode = 1 |
| 25 | + $$$ThrowOnError(settings.%Save()) |
| 26 | + do $$$LogMessage("check out live branch on local") |
| 27 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).SwitchBranch("live")) |
| 28 | + do $$$LogMessage("create a class through IRIS, add it to source control, and sync") |
| 29 | + do $System.OBJ.Delete("TestGit.SampleClass2") |
| 30 | + set classDef = ##class(%Dictionary.ClassDefinition).%New("TestGit.SampleClass2") |
| 31 | + $$$ThrowOnError(classDef.%Save()) |
| 32 | + $$$ThrowOnError($System.OBJ.Compile("TestGit.SampleClass2")) |
| 33 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).AddToSourceControl("TestGit.SampleClass2.cls")) |
| 34 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).Sync("should not commit")) |
| 35 | + do $$$LogMessage("sync should NOT have committed the new file since we are on the live branch.") |
| 36 | + do $$$AssertTrue(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName("TestGit.SampleClass2.cls"))) |
| 37 | + do $$$LogMessage("now, check out an interface branch") |
| 38 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).NewBranch("interface")) |
| 39 | + do $$$LogMessage("simulate another developer's change going live") |
| 40 | + do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass1.cls","Class TestGit.SampleClass1 { Parameter foo = ""bar""; }") |
| 41 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") |
| 42 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "initial commit in remote for unit test") |
| 43 | + do $$$LogMessage("check out an interface branch and sync") |
| 44 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).Sync("should commit")) |
| 45 | + do $$$LogMessage("sync should have rebased the other developer's change, and committed the new file.") |
| 46 | + do $$$AssertEquals(##class(TestGit.SampleClass1).#foo, "bar") |
| 47 | + do $$$AssertNotTrue(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName("TestGit.SampleClass2.cls"))) |
| 48 | + do $$$LogMessage("simulate a merge request on the remote from the interface branch to live.") |
| 49 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "merge", "interface") |
| 50 | + do $$$AssertTrue(##class(%File).Exists(remoteDir_"/cls/TestGit/SampleClass2.cls")) |
| 51 | +} |
| 52 | + |
| 53 | +} |
0 commit comments