Skip to content

Commit

Permalink
Add fetch tests
Browse files Browse the repository at this point in the history
  - adds `fetch` tests for the following scenarios:
    * empty deps
    * empty dir
    * mutually recursive
    * self referential
  • Loading branch information
JONBRWN committed Jun 9, 2020
1 parent f178e2b commit 29a5652
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
1 change: 1 addition & 0 deletions corral/cmd/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ actor Main is TestList

fun tag tests(test: PonyTest) =>
_TestCmdUpdate.make().tests(test)
_TestCmdFetch.make().tests(test)
102 changes: 102 additions & 0 deletions corral/cmd/_test_cmd_fetch.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use "files"
use "ponytest"
use "../bundle"
use "../util"
use "../vcs"

actor _TestCmdFetch is TestList
new make() =>
None

fun tag tests(test: PonyTest) =>
test(_TestFetchEmptyDeps)
test(_TestFetchEmptyFile)
test(_TestFetchMutuallyRecursive)
test(_TestFetchSelfReferential)

class iso _TestFetchEmptyDeps is UnitTest
"""
Verify that when using corral.json with empty deps, that there
are never any sync, tag query, or checkout operations executed.
"""

fun name(): String =>
"cmd/fetch/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderFetchTestRunner(
h,
"empty-deps",
_OpsRecorder(h, 0, 0, 0))?

class iso _TestFetchEmptyFile is UnitTest
"""
Verify that when using corral.json with an empty deps file, that there
are never any sync, tag query, or checkout operations executed.
"""

fun name(): String =>
"cmd/fetch/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderFetchTestRunner(
h,
"empty-file",
_OpsRecorder(h, 0, 0, 0))?

class iso _TestFetchSelfReferential is UnitTest
"""
Verify that a self reference in a corral.json results in only 1 operation
"""
fun name(): String =>
"cmd/fetch/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderFetchTestRunner(
h,
"self-referential",
_OpsRecorder(h, 1, 0, 1))?

class iso _TestFetchMutuallyRecursive is UnitTest
"""
Verify that when using mutually recursive corral.json files that we
execute the correct number of operations
"""

fun name(): String =>
"cmd/fetch/" + __loc.type_name()

fun apply(h: TestHelper) ? =>
_OpsRecorderFetchTestRunner(
h,
"mutually-recursive/foo",
_OpsRecorder(h, 2, 0, 2))?

primitive _OpsRecorderFetchTestRunner
fun apply(h: TestHelper, dep_path: String val, recorder: _OpsRecorder) ? =>
"""
Runs an _OpsRecorder test.
"""
let auth = h.env.root as AmbientAuth
let log = Log(LvlNone, h.env.err, SimpleLogFormatter)
let fp: FilePath = _TestData.file_path_from(h, dep_path)?
let repo_cache = _TestRepoCache(auth, "_test_cmd_fetch_repo_cache")?
let ctx = Context(h.env, log, log, false, repo_cache)
let project = Project(auth, log, fp)
let bundle = Bundle.load(fp, log)?
let vcs_builder: VCSBuilder = _TestCmdFetchVCSBuilder(recorder)

let fetcher = _Fetcher(ctx, project, consume bundle, vcs_builder,
recorder)

// when fetcher is finished, it will send a `cmd_completed` message to
// _OpsRecorder which will trigger pass/fail

class val _TestCmdFetchVCSBuilder is VCSBuilder
let _recorder: _OpsRecorder

new val create(recorder: _OpsRecorder) =>
_recorder = recorder

fun val apply(kind: String): VCS =>
_RecordedVCS(_recorder)
8 changes: 6 additions & 2 deletions corral/cmd/cmd_fetch.pony
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CmdFetch is CmdType

match project.load_bundle()
| let base_bundle: Bundle iso =>
_Fetcher(ctx, project, consume base_bundle, vcs_builder)
_Fetcher(ctx, project, consume base_bundle, vcs_builder, result_receiver)
| let err: Error =>
ctx.uout.err(err.message)
ctx.env.exitcode(1)
Expand All @@ -31,16 +31,19 @@ actor _Fetcher
let fetched: Set[Locator] = fetched.create()

let _vcs_builder: VCSBuilder
let _results_receiver: CmdResultReceiver

new create(ctx': Context,
project': Project,
base_bundle': Bundle iso,
vcs_builder: VCSBuilder)
vcs_builder: VCSBuilder,
results_receiver: CmdResultReceiver)
=>
ctx = ctx'
project = project'
base_bundle = consume base_bundle'
_vcs_builder = vcs_builder
_results_receiver = results_receiver
ctx.log.info("Fetching direct deps of project bundle: " + base_bundle.name())
fetch_bundle_deps(base_bundle)

Expand All @@ -58,6 +61,7 @@ actor _Fetcher
ctx.uout.info("fetch: would have fetched dep: " + dep.name() + " @ " + dep.version())
end
end
_results_receiver.cmd_completed()

fun fetch_dep(dep: Dep val) =>
try
Expand Down

0 comments on commit 29a5652

Please sign in to comment.