|
| 1 | +Class UnitTest.SourceControl.Git.Pull Extends %UnitTest.TestCase |
| 2 | +{ |
| 3 | + |
| 4 | +Property InitialExtension As %String [ InitialExpression = {##class(%Studio.SourceControl.Interface).SourceControlClassGet()} ]; |
| 5 | + |
| 6 | +Property SourceControlGlobal [ MultiDimensional ]; |
| 7 | + |
| 8 | +Method %OnNew(initvalue) As %Status |
| 9 | +{ |
| 10 | + Merge ..SourceControlGlobal = ^SYS("SourceControl") |
| 11 | + Kill ^SYS("SourceControl") |
| 12 | + Set settings = ##class(SourceControl.Git.Settings).%New() |
| 13 | + Set settings.namespaceTemp = ##class(%Library.File).TempFilename()_"dir" |
| 14 | + Set settings.Mappings("CLS","*")="cls/" |
| 15 | + Do settings.%Save() |
| 16 | + Do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("SourceControl.Git.Extension") |
| 17 | + Quit ##super(initvalue) |
| 18 | +} |
| 19 | + |
| 20 | +Method %OnClose() As %Status [ Private, ServerOnly = 1 ] |
| 21 | +{ |
| 22 | + Do ##class(%Studio.SourceControl.Interface).SourceControlClassSet(..InitialExtension) |
| 23 | + Kill ^SYS("SourceControl") |
| 24 | + Merge ^SYS("SourceControl") = ..SourceControlGlobal |
| 25 | + Quit $$$OK |
| 26 | +} |
| 27 | + |
| 28 | +ClassMethod WriteFile(filePath, contents) |
| 29 | +{ |
| 30 | + set dirPath = ##class(%File).GetDirectory(filePath) |
| 31 | + if '##class(%File).CreateDirectoryChain(dirPath,.ret) { |
| 32 | + $$$ThrowStatus($$$ERROR($$$GeneralError,"failed to create directory: "_ret)) |
| 33 | + } |
| 34 | + set fileStream = ##class(%Stream.FileCharacter).%OpenId(filePath,,.sc) |
| 35 | + $$$ThrowOnError(sc) |
| 36 | + do fileStream.Write(contents) |
| 37 | + $$$ThrowOnError(fileStream.%Save()) |
| 38 | +} |
| 39 | + |
| 40 | +Method TestPull() |
| 41 | +{ |
| 42 | + // initialize remote repository on filesystem |
| 43 | + set remoteDir = ##class(%Library.File).TempFilename()_"d" |
| 44 | + if '##class(%File).CreateDirectoryChain(remoteDir_"/cls",.ret) { |
| 45 | + $$$ThrowStatus($$$ERROR($$$GeneralError,"failed to create directory: "_ret)) |
| 46 | + } |
| 47 | + do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass1.cls","Class TestGit.SampleClass1 {}") |
| 48 | + do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass2.cls","Class TestGit.SampleClass2 {}") |
| 49 | + do $zf(-100,"/SHELL","git","init",remoteDir) |
| 50 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") |
| 51 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "initial commit in remote for unit test") |
| 52 | + // initialize local repo, cloning remote. |
| 53 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).Clone(remoteDir_"/.git")) |
| 54 | + // import all and confirm classes exist |
| 55 | + do $System.OBJ.Delete("TestGit.SampleClass1,TestGit.SampleClass2") |
| 56 | + $$$ThrowOnError(##class(SourceControl.Git.Utils).ImportAll(1)) |
| 57 | + do $$$AssertTrue($$$comClassDefined("TestGit.SampleClass1")) |
| 58 | + do $$$AssertTrue($$$comClassDefined("TestGit.SampleClass2")) |
| 59 | + // delete, add, and modify classes on remote. add and commit them all on remote. |
| 60 | + if '##class(%File).Delete(remoteDir_"/cls/TestGit/SampleClass1.cls",.ret) { |
| 61 | + $$$ThrowStatus($$$ERROR($$$GeneralError,"failed to delete class file")) |
| 62 | + } |
| 63 | + do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass2.cls","Class TestGit.SampleClass2 { Parameter foo = ""bar""; }") |
| 64 | + do ..WriteFile(remoteDir_"/cls/TestGit/SampleClass3.cls","Class TestGit.SampleClass3 {}") |
| 65 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "add", ".") |
| 66 | + do $zf(-100,"/SHELL","git", "-C", remoteDir, "commit", "-m", "delete, modify, and add classes on remote") |
| 67 | + // pull on local and confirm changes were loaded. |
| 68 | + $$$ThrowOnError(##class(SourceControl.Git.API).Pull()) |
| 69 | + do $$$AssertNotTrue($$$comClassDefined("TestGit.SampleClass1")) |
| 70 | + do $$$AssertEquals(##class(TestGit.SampleClass2).#foo, "bar") |
| 71 | + do $$$AssertTrue($$$comClassDefined("TestGit.SampleClass3")) |
| 72 | +} |
| 73 | + |
| 74 | +} |
0 commit comments