-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Baby steps towards making CmdUpdate unit testable
As part of the work on #120, an error when using the update command, I wanted to add tests to demonstrate the bug and then show that the bug was fixed by my changes. This is problematic because there are no real unit tests for any commands. This commit is the first step in providing better unit testability of various parts of corral in general and commands specifically. The only test added by this commit is that when using a corral.json with empty deps, that no VCS operations will be executed by _Updater. There are a number of changes that are brought in my this initial refactor. As we move forward with making corral more testable, some of these changes will probably fall away. I did what I considered the minimal thing to get a harness for testing _Updater working. This harness should be enough to test using the various test-data bundles that we have as well as testing issue #120. The approach I have taken does leave a lot of things in an inconsistent state. For example, this commit introduces a new way of organizing unit tests that keeps said tests near the code they are testing and allows for testing private implementations like the _Update that is part of the update cmd. These inconsistencies are temporary and as we move forward with adding more tests, will start to fall away.
- Loading branch information
1 parent
818cddb
commit 7f00b2b
Showing
17 changed files
with
237 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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,11 @@ | ||
use "ponytest" | ||
|
||
actor Main is TestList | ||
new create(env: Env) => | ||
PonyTest(env, this) | ||
|
||
new make() => | ||
None | ||
|
||
fun tag tests(test: PonyTest) => | ||
_TestCmdUpdate.make().tests(test) |
This file contains 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,146 @@ | ||
use "files" | ||
use "ponytest" | ||
use "../bundle" | ||
use "../util" | ||
use "../vcs" | ||
|
||
actor _TestCmdUpdate is TestList | ||
new make() => | ||
None | ||
|
||
fun tag tests(test: PonyTest) => | ||
test(_TestEmptyDeps) | ||
|
||
class iso _TestEmptyDeps is UnitTest | ||
fun name(): String => | ||
"cmd/update/" + __loc.type_name() | ||
|
||
fun apply(h: TestHelper) ? => | ||
""" | ||
Verify that when using an corral.json for with empty deps, that there | ||
are never any sync, tag query, or checkout operations executed. | ||
""" | ||
let auth = h.env.root as AmbientAuth | ||
let log = Log(LvlNone, h.env.err, SimpleLogFormatter) | ||
let fp: FilePath = _TestData.file_path_from(h, "empty-deps")? | ||
let repo_cache = _TestRepoCache(auth)? | ||
let ctx = Context(h.env, log, log, false, repo_cache) | ||
let project = Project(auth, log, fp) | ||
let bundle = Bundle.load(fp, log)? | ||
let recorder = _OpsRecorder(h, 0, 0, 0) | ||
let vcs_builder: VCSBuilder = _TestCmdUpdateVCSBuilder(recorder) | ||
|
||
let updater = _Updater(ctx, project, consume bundle, vcs_builder, recorder) | ||
|
||
// when updater is finished, it will send a `cmd_completed` message to | ||
// _OpsRecorder which will trigger pass/fail | ||
h.long_test(2_000_000_000) | ||
|
||
|
||
actor _OpsRecorder is CmdResultReceiver | ||
let _h: TestHelper | ||
|
||
let _expected_sync: U64 | ||
let _expected_tag_query: U64 | ||
let _expected_checkout: U64 | ||
|
||
var _sync: U64 = 0 | ||
var _tag_query: U64 = 0 | ||
var _checkout: U64 = 0 | ||
|
||
new create(h: TestHelper, s: U64, tq: U64, c: U64) => | ||
_h = h | ||
_expected_sync = s | ||
_expected_tag_query = tq | ||
_expected_checkout = c | ||
|
||
be sync() => | ||
_sync = _sync + 1 | ||
|
||
be tag_query() => | ||
_tag_query = _tag_query + 1 | ||
|
||
be checkout() => | ||
_checkout = _checkout + 1 | ||
|
||
be cmd_completed() => | ||
_h.assert_eq[U64](_expected_sync, _sync) | ||
_h.assert_eq[U64](_expected_tag_query, _tag_query) | ||
_h.assert_eq[U64](_expected_checkout, _checkout) | ||
|
||
_h.complete(true) | ||
|
||
|
||
class val _TestCmdUpdateVCSBuilder is VCSBuilder | ||
let _recorder: _OpsRecorder | ||
|
||
new val create(recorder: _OpsRecorder) => | ||
_recorder = recorder | ||
|
||
fun val apply(kind: String): VCS => | ||
_RecordedVCS(_recorder) | ||
|
||
|
||
class val _RecordedVCS is VCS | ||
let _recorder: _OpsRecorder | ||
|
||
new val create(recorder: _OpsRecorder) => | ||
_recorder = recorder | ||
|
||
fun val sync_op(next: RepoOperation): RepoOperation => | ||
_RecordedSync(_recorder, next) | ||
|
||
fun val tag_query_op(receiver: TagListReceiver): RepoOperation => | ||
_RecordedTagQuery(_recorder, receiver) | ||
|
||
fun val checkout_op(rev: String, next: RepoOperation): RepoOperation => | ||
_RecordedCheckout(_recorder, next) | ||
|
||
|
||
class val _RecordedSync is RepoOperation | ||
let _recorder: _OpsRecorder | ||
let _next: RepoOperation | ||
|
||
new val create(recorder: _OpsRecorder, next: RepoOperation) => | ||
_recorder = recorder | ||
_next = next | ||
|
||
fun val apply(repo: Repo) => | ||
_recorder.sync() | ||
_next(repo) | ||
|
||
|
||
class val _RecordedTagQuery is RepoOperation | ||
let _recorder: _OpsRecorder | ||
let _next: TagListReceiver | ||
|
||
new val create(recorder: _OpsRecorder, next: TagListReceiver) => | ||
_recorder = recorder | ||
_next = next | ||
|
||
fun val apply(repo: Repo) => | ||
let tags: Array[String] iso = recover Array[String] end | ||
_recorder.tag_query() | ||
_next(repo, consume tags) | ||
|
||
|
||
class val _RecordedCheckout is RepoOperation | ||
let _recorder: _OpsRecorder | ||
let _next: RepoOperation | ||
|
||
new val create(recorder: _OpsRecorder, next: RepoOperation) => | ||
_recorder = recorder | ||
_next = next | ||
|
||
fun val apply(repo: Repo) => | ||
_recorder.checkout() | ||
_next(repo) | ||
|
||
primitive _TestData | ||
fun file_path_from(h: TestHelper, subdir: String = ""): FilePath ? => | ||
let auth = h.env.root as AmbientAuth | ||
FilePath(auth, "corral/test/testdata")?.join(subdir)? | ||
|
||
primitive _TestRepoCache | ||
fun apply(auth: AmbientAuth): FilePath ? => | ||
FilePath(auth,"_test_cmd_update_repo_cache")? |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,6 @@ | ||
interface tag CmdResultReceiver | ||
be cmd_completed() | ||
|
||
primitive NoOpResultReceiver | ||
fun tag cmd_completed() => | ||
None |
This file contains 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
This file contains 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