-
Notifications
You must be signed in to change notification settings - Fork 11
Integration tests for pull and sync #827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Class UnitTest.SourceControl.Git.AbstractTest Extends %UnitTest.TestCase | ||
{ | ||
|
||
Property InitialExtension As %String [ InitialExpression = {##class(%Studio.SourceControl.Interface).SourceControlClassGet()} ]; | ||
|
||
Property SourceControlGlobal [ MultiDimensional ]; | ||
|
||
Method %OnNew(initvalue) As %Status | ||
{ | ||
Merge ..SourceControlGlobal = ^SYS("SourceControl") | ||
Kill ^SYS("SourceControl") | ||
Set settings = ##class(SourceControl.Git.Settings).%New() | ||
Set settings.namespaceTemp = ##class(%Library.File).TempFilename()_"dir" | ||
Set settings.Mappings("CLS","*")="cls/" | ||
Do settings.%Save() | ||
Do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("SourceControl.Git.Extension") | ||
Quit ##super(initvalue) | ||
} | ||
|
||
Method %OnClose() As %Status [ Private, ServerOnly = 1 ] | ||
{ | ||
Do ##class(%Studio.SourceControl.Interface).SourceControlClassSet(..InitialExtension) | ||
Kill ^SYS("SourceControl") | ||
Merge ^SYS("SourceControl") = ..SourceControlGlobal | ||
Quit $$$OK | ||
} | ||
|
||
ClassMethod WriteFile(filePath, contents) | ||
{ | ||
set dirPath = ##class(%File).GetDirectory(filePath) | ||
if '##class(%File).CreateDirectoryChain(dirPath,.ret) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"failed to create directory: "_ret)) | ||
} | ||
set fileStream = ##class(%Stream.FileCharacter).%OpenId(filePath,,.sc) | ||
$$$ThrowOnError(sc) | ||
do fileStream.Write(contents) | ||
$$$ThrowOnError(fileStream.%Save()) | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Class UnitTest.SourceControl.Git.Pull Extends UnitTest.SourceControl.Git.AbstractTest | ||
{ | ||
|
||
Method TestPull() | ||
{ | ||
// initialize remote repository on filesystem | ||
set remoteDir = ##class(%Library.File).TempFilename()_"d" | ||
if '##class(%File).CreateDirectoryChain(remoteDir_"/cls",.ret) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"failed to create directory: "_ret)) | ||
} | ||
do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass1.cls","Class TestGit.SampleClass1 {}") | ||
do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass2.cls","Class TestGit.SampleClass2 {}") | ||
do $zf(-100,"/SHELL","git","init",remoteDir) | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "config", "user.email", "[email protected]") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "config", "user.name", "Unit Test") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "initial commit in remote for unit test") | ||
// initialize local repo, cloning remote. | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).Clone(remoteDir_"/.git")) | ||
// import all and confirm classes exist | ||
do $System.OBJ.Delete("TestGit.SampleClass1,TestGit.SampleClass2") | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).ImportAll(1)) | ||
do $$$AssertTrue($$$comClassDefined("TestGit.SampleClass1")) | ||
do $$$AssertTrue($$$comClassDefined("TestGit.SampleClass2")) | ||
// delete, add, and modify classes on remote. add and commit them all on remote. | ||
if '##class(%File).Delete(remoteDir_"/cls/TestGit/SampleClass1.cls",.ret) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"failed to delete class file")) | ||
} | ||
do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass2.cls","Class TestGit.SampleClass2 { Parameter foo = ""bar""; }") | ||
do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass3.cls","Class TestGit.SampleClass3 {}") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "delete, modify, and add classes on remote") | ||
// pull on local and confirm changes were loaded. | ||
$$$ThrowOnError(##class(SourceControl.Git.API).Pull()) | ||
do $$$AssertNotTrue($$$comClassDefined("TestGit.SampleClass1")) | ||
do $$$AssertEquals(##class(TestGit.SampleClass2).#foo, "bar") | ||
do $$$AssertTrue($$$comClassDefined("TestGit.SampleClass3")) | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Class UnitTest.SourceControl.Git.Sync Extends UnitTest.SourceControl.Git.AbstractTest | ||
{ | ||
|
||
Method TestSync() | ||
{ | ||
do $$$LogMessage("set up remote repo on filesystem") | ||
set remoteDir = ##class(%Library.File).TempFilename()_"d" | ||
if '##class(%File).CreateDirectoryChain(remoteDir,.ret) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError,"failed to create directory: "_ret)) | ||
} | ||
do $zf(-100,"/SHELL","git","init",remoteDir) | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "config", "user.email", "[email protected]") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "config", "user.name", "Unit Test") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "checkout", "-b", "live") | ||
do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass1.cls","Class TestGit.SampleClass1 {}") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "initial commit in remote for unit test") | ||
do $$$LogMessage("initialize local repo cloning remote") | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).Clone(remoteDir_"/.git")) | ||
do $$$LogMessage("set default merge branch to live and enable basic mode") | ||
set settings = ##class(SourceControl.Git.Settings).%New() | ||
set settings.defaultMergeBranch = "live" | ||
set settings.basicMode = "system" | ||
set settings.systemBasicMode = 1 | ||
$$$ThrowOnError(settings.%Save()) | ||
do $$$LogMessage("check out live branch on local") | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).SwitchBranch("live")) | ||
do $$$LogMessage("create a class through IRIS, add it to source control, and sync") | ||
do $System.OBJ.Delete("TestGit.SampleClass2") | ||
set classDef = ##class(%Dictionary.ClassDefinition).%New("TestGit.SampleClass2") | ||
$$$ThrowOnError(classDef.%Save()) | ||
$$$ThrowOnError($System.OBJ.Compile("TestGit.SampleClass2")) | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).AddToSourceControl("TestGit.SampleClass2.cls")) | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).Sync("should not commit")) | ||
do $$$LogMessage("sync should NOT have committed the new file since we are on the live branch.") | ||
do $$$AssertTrue(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName("TestGit.SampleClass2.cls"))) | ||
do $$$LogMessage("now, check out an interface branch") | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).NewBranch("interface")) | ||
do $$$LogMessage("simulate another developer's change going live") | ||
do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass1.cls","Class TestGit.SampleClass1 { Parameter foo = ""bar""; }") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "initial commit in remote for unit test") | ||
do $$$LogMessage("check out an interface branch and sync") | ||
$$$ThrowOnError(##class(SourceControl.Git.Utils).Sync("should commit")) | ||
do $$$LogMessage("sync should have rebased the other developer's change, and committed the new file.") | ||
do $$$AssertEquals(##class(TestGit.SampleClass1).#foo, "bar") | ||
do $$$AssertNotTrue(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName("TestGit.SampleClass2.cls"))) | ||
do $$$LogMessage("simulate a merge request on the remote from the interface branch to live.") | ||
do $zf(-100,"/SHELL","git", "-C", remoteDir, "merge", "interface") | ||
do $$$AssertTrue(##class(%File).Exists(remoteDir_"/cls/TestGit/SampleClass2.cls")) | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.