Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Jan 27, 2025
1 parent cce614c commit 9242626
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/portable/instance/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ pub fn bootstrap(
.arg(&ensure_runstate_dir(&info.name)?);
self_signed_arg(&mut cmd, info.get_version()?);
cmd.arg("--bootstrap-command").arg(script);
if info.get_version()?.specific().major >= 5 {
cmd.arg("--default-branch").arg(database);
} else {
cmd.arg("--default-database").arg(database);
}
cmd.run()?;

let cert_path = tmp_data.join("edbtlscert.pem");
Expand Down
115 changes: 115 additions & 0 deletions tests/portable_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,118 @@ fn project_link_and_init() {
.context("destroy-2", "should unlink and destroy project")
.success();
}

#[test]
fn hooks() {
Command::new("edgedb")
.arg("--version")
.assert()
.context("version", "command-line version option")
.success()
.stdout(predicates::str::contains(EXPECTED_VERSION));

Command::new("edgedb")
.arg("instance")
.arg("create")
.arg("inst2")
.arg("master")
.arg("--non-interactive")
.assert()
.context("instance-create", "")
.success();

Command::new("edgedb")
.current_dir("tests/proj/project3")
.arg("project")
.arg("init")
.arg("--link")
.arg("--server-instance=inst2")
.arg("--non-interactive")
.assert()
.context("project-init", "")
.success()
.stderr(ContainsHooks {
expected: &[
"project.init.after",
"migration.apply.before",
"migration.apply.after",
],
});

Command::new("edgedb")
.current_dir("tests/proj/project3")
.arg("branch")
.arg("switch")
.arg("--create")
.arg("--empty")
.arg("another")
.assert()
.context("branch-switch", "")
.success()
.stderr(ContainsHooks {
expected: &["branch.switch.before", "branch.switch.after"],
});

Command::new("edgedb")
.current_dir("tests/proj/project3")
.arg("branch")
.arg("merge")
.arg("master")
.assert()
.context("branch-merge", "")
.success()
.stderr(ContainsHooks {
expected: &["migration.apply.before", "migration.apply.after"],
});

Command::new("edgedb")
.current_dir("tests/proj/project3")
.arg("branch")
.arg("wipe")
.arg("another")
.arg("--non-interactive")
.assert()
.context("branch-wipe", "")
.success()
.stderr(ContainsHooks {
expected: &["branch.wipe.before", "branch.wipe.after"],
});
}

#[derive(Debug)]
struct ContainsHooks<'a> {
expected: &'a [&'static str],
}

impl<'a> predicates::Predicate<str> for ContainsHooks<'a> {
fn eval(&self, variable: &str) -> bool {
let re = regex::RegexBuilder::new(r"^hook ([a-z.]+):")
.multi_line(true)
.build()
.unwrap();
let found_hooks: Vec<_> = re
.captures_iter(variable)
.map(|c| c.extract::<1>().1[0])
.collect();

self.expected == found_hooks.as_slice()
}
}

impl<'a> predicates::reflection::PredicateReflection for ContainsHooks<'a> {
fn parameters<'b>(
&'b self,
) -> Box<dyn Iterator<Item = predicates::reflection::Parameter<'b>> + 'b> {
let mut params = std::vec![];
for e in self.expected {
params.push(predicates::reflection::Parameter::new("hook", e));
}
Box::new(params.into_iter())
}
}

impl<'a> std::fmt::Display for ContainsHooks<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self, f)
}
}
6 changes: 6 additions & 0 deletions tests/proj/project3/database_schema/default.gel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module default {
type Hello {
property world: str;
property foo: int64;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE MIGRATION m1mdwoyrh5c677pkvx57hvsxlsqiycrhijh6wyytflykey5essjiba
ONTO initial
{
CREATE TYPE default::Hello {
CREATE PROPERTY world: std::str;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE MIGRATION m1bgeql5ie4pvxxcs63vu5b5h74ft6qmfte2f4febgcwqzdbo4tusa
ONTO m1mdwoyrh5c677pkvx57hvsxlsqiycrhijh6wyytflykey5essjiba
{
ALTER TYPE default::Hello {
CREATE PROPERTY foo: std::int64;
};
};
15 changes: 15 additions & 0 deletions tests/proj/project3/gel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[instance]
server-version = "nightly"

[project]
schema-dir = "./database_schema"

[hooks]
project.init.before = "true"
project.init.after = "true"
branch.switch.before = "true"
branch.switch.after = "true"
branch.wipe.before = "true"
branch.wipe.after = "true"
migration.apply.before = "true"
migration.apply.after = "true"

0 comments on commit 9242626

Please sign in to comment.