Skip to content
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

Some more fixups for snapshot-dir.py (#160) #450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 99 additions & 6 deletions test/python_utils/SnapshotDir_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# ************************************************************************
# @HEADER


########################################
# Unit testing code for SnapshotDir.py #
########################################
Expand Down Expand Up @@ -74,6 +75,9 @@ def getDummyDefaultOptions():
return dummyDefaultOptions


# Run a snapshot-dir.py test case using mock commands all in memory without
# actually doing anyting on the disk or the filesystem.
#
def runSnapshotDirTestCase(testObject, cmndLineArgsList, cmndInterceptList,
passRegexExpressionsList, defaultOptions=None \
):
Expand All @@ -90,6 +94,7 @@ def runSnapshotDirTestCase(testObject, cmndLineArgsList, cmndInterceptList,
sout = WriteToString()

rtn = snapshotDirMainDriver(cmndLineArgsList, defaultOptions, sout)
g_sysCmndInterceptor.assertAllCommandsRun()
ostr = sout.getStr()
#print("ostr =", ostr)
for passRegexExpr in passRegexExpressionsList:
Expand All @@ -111,8 +116,12 @@ def runSnapshotDirTestCase(testObject, cmndLineArgsList, cmndInterceptList,

g_gitRevParse = "IT: git rev-parse --abbrev-ref --symbolic-full-name ..u.; 0; 'remotename/remotebranch'\n"

g_gitRevParseDetailedHead = "IT: git rev-parse --abbrev-ref --symbolic-full-name ..u.; 1; ''\n"

g_gitRemote = "IT: git remote -v; 0; 'remotename\tsome-url-location (fetch)'\n"

g_gitDescribe = "IT: git describe; 0; 'v1.2.3-225-g9877045'\n"

g_gitLog = "IT: git log --pretty=.*; 0; 'one commit msg'\n"

g_gitClean = "IT: git clean -xdf; 0; 'clean passed'\n"
Expand Down Expand Up @@ -184,6 +193,7 @@ def test_snapshot_default(self):
g_gitDiffHead,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
Expand All @@ -197,6 +207,7 @@ def test_snapshot_default(self):
"origin remote name = 'remotename'",
"origin remote branch = 'remotebranch'",
"origin remote URL = 'some-url-location'",
"Git describe = 'v1.2.3-225-g9877045'",
"Automatic snapshot commit from orig-dir at abc123",
"Origin repo remote tracking branch: 'remotename/remotebranch'",
"Origin repo remote repo URL: 'remotename = some-url-location'",
Expand All @@ -205,6 +216,69 @@ def test_snapshot_default(self):
)


def test_snapshot_default_no_op(self):
runSnapshotDirTestCase(
self,
["--orig-dir=dummy/orig-dir/", "--dest-dir=dummy/dest-dir/", "--no-op"],
[
g_gitDiffHead,
g_gitDiffHead,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_gitLogSha1,
],
[
"Script: snapshot-dir\.py",
"--orig-dir='dummy/orig-dir/'",
"--dest-dir='dummy/dest-dir/'",
"origin remote name = 'remotename'",
"origin remote branch = 'remotebranch'",
"origin remote URL = 'some-url-location'",
"Git describe = 'v1.2.3-225-g9877045'",
"Would be running: rsync -cav --delete --exclude=\\\[.]git dummy/orig-dir/ dummy/dest-dir/",
"Automatic snapshot commit from orig-dir at abc123",
"Origin repo remote tracking branch: 'remotename/remotebranch'",
"Origin repo remote repo URL: 'remotename = some-url-location'",
"one commit msg",
"Would be running: git add .",
"Would be running: git commit -m \"<commit-msg>\"",
]
)


def test_snapshot_detached_head(self):
runSnapshotDirTestCase(
self,
["--orig-dir=dummy/orig-dir/", "--dest-dir=dummy/dest-dir/"],
[
g_gitDiffHead,
g_gitDiffHead,
g_gitRevParseDetailedHead,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
g_gitAdd,
g_gitCommit,
],
[
"Script: snapshot-dir\.py",
"--orig-dir='dummy/orig-dir/'",
"--dest-dir='dummy/dest-dir/'",
"origin remote name = 'remotename'",
"origin remote branch = ''",
"origin remote URL = 'some-url-location'",
"Git describe = 'v1.2.3-225-g9877045'",
"Automatic snapshot commit from orig-dir at abc123",
"Origin repo remote repo URL: 'remotename = some-url-location'",
"one commit msg"
]
)


def test_snapshot_default_missing_trailing_slash(self):
runSnapshotDirTestCase(
self,
Expand All @@ -214,6 +288,7 @@ def test_snapshot_default_missing_trailing_slash(self):
g_gitDiffHead,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
Expand All @@ -238,6 +313,7 @@ def test_snapshot_default_with_exclude(self):
g_gitDiffHead,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
Expand Down Expand Up @@ -271,6 +347,7 @@ def test_snapshot_clean_ignored(self):
g_gitClean,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
Expand All @@ -293,6 +370,7 @@ def test_snapshot_no_verify_commit(self):
g_gitDiffHead,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
Expand All @@ -305,6 +383,27 @@ def test_snapshot_no_verify_commit(self):
)


def test_snapshot_skip_commit(self):
runSnapshotDirTestCase(
self,
["--orig-dir=dummy/orig-dir/", "--dest-dir=dummy/dest-dir/",
"--skip-commit"],
[
g_gitDiffHead,
g_gitDiffHead,
g_gitRevParse,
g_gitRemote,
g_gitDescribe,
g_gitLog,
g_rsync,
g_gitLogSha1,
],
[
"Skipping commit on request"
]
)


# ToDo: Test assert failure of clean origDir ...

# ToDo: Test skipping test of clean origDir ...
Expand All @@ -317,14 +416,8 @@ def test_snapshot_no_verify_commit(self):

# ToDo: Test failure to acquire origin commit ...

# ToDo: Test skipping getting origin info ...

# ToDo: Test failing rsync ...

# ToDo: Test failing to create commit in dest repo ...

# ToDo: Test skipping creation of commit in dest repo ...


if __name__ == '__main__':
unittest.main()
Loading