Skip to content

Commit 3c99430

Browse files
committed
cargo fmt
1 parent 9dcf58b commit 3c99430

File tree

5 files changed

+64
-29
lines changed

5 files changed

+64
-29
lines changed

crates/cli/src/tasks/rust.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ fn cargo_cmd(subcommand: &str, build_debug: bool, args: &[&str]) -> duct::Expres
2323
)
2424
}
2525

26-
pub(crate) fn build_rust(project_path: &Path, features: Option<&std::ffi::OsString>, lint_dir: Option<&Path>, build_debug: bool) -> anyhow::Result<PathBuf> {
26+
pub(crate) fn build_rust(
27+
project_path: &Path,
28+
features: Option<&std::ffi::OsString>,
29+
lint_dir: Option<&Path>,
30+
build_debug: bool,
31+
) -> anyhow::Result<PathBuf> {
2732
// Make sure that we have the wasm target installed
2833
if !has_wasm32_target() {
2934
if has_rust_up() {
@@ -85,9 +90,7 @@ pub(crate) fn build_rust(project_path: &Path, features: Option<&std::ffi::OsStri
8590
// Convert Vec<String> to Vec<&str>
8691
let args_str: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
8792

88-
let reader = cargo_cmd("build", build_debug, &args_str)
89-
.dir(project_path)
90-
.reader()?;
93+
let reader = cargo_cmd("build", build_debug, &args_str).dir(project_path).reader()?;
9194

9295
let mut artifact = None;
9396
for message in Message::parse_stream(io::BufReader::new(reader)) {

crates/cli/tests/publish.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,38 @@ fn cli_can_publish_breaking_change_with_on_conflict_flag() {
162162
.assert()
163163
.success();
164164
}
165+
166+
#[test]
167+
fn cli_can_publish_no_conflict_does_not_delete_data() {
168+
let spacetime = SpacetimeDbGuard::spawn_in_temp_data_dir();
169+
170+
// Workspace root for `cargo run -p ...`
171+
let workspace_dir = cargo_metadata::MetadataCommand::new().exec().unwrap().workspace_root;
172+
let dir = workspace_dir.join("modules").join("module-test");
173+
174+
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
175+
cmd.args([
176+
"publish",
177+
"--server",
178+
&spacetime.host_url.to_string(),
179+
"no-conflict-test",
180+
])
181+
.current_dir(dir.clone())
182+
.assert()
183+
.success();
184+
185+
// Can republish without conflict even with --on-conflict=delete-data flag
186+
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
187+
cmd.args([
188+
"publish",
189+
"--server",
190+
&spacetime.host_url.to_string(),
191+
"--delete-data=on-conflict",
192+
// NOTE: deleting data requires --yes,
193+
// so not providing it here ensures that no data deletion is attempted.
194+
"no-conflict-test",
195+
])
196+
.current_dir(dir)
197+
.assert()
198+
.success();
199+
}

crates/cli/tests/server.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
mod util;
22

3-
use assert_cmd::cargo::cargo_bin_cmd;
43
use crate::util::SpacetimeDbGuard;
4+
use assert_cmd::cargo::cargo_bin_cmd;
55

66
#[test]
77
fn cli_can_ping_spacetimedb_on_disk() {
88
let spacetime = SpacetimeDbGuard::spawn_in_temp_data_dir();
99
let mut cmd = cargo_bin_cmd!("spacetimedb-cli");
10-
cmd.args([
11-
"server",
12-
"ping",
13-
&spacetime.host_url.to_string(),
14-
])
15-
.assert()
16-
.success();
17-
}
10+
cmd.args(["server", "ping", &spacetime.host_url.to_string()])
11+
.assert()
12+
.success();
13+
}

crates/cli/tests/util.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
21
use std::{
3-
env, io::{BufReader, BufRead}, net::SocketAddr, process::{Child, Command, Stdio}, sync::{Arc, Mutex}, thread::{self, sleep}, time::{Duration, Instant}
2+
env,
3+
io::{BufRead, BufReader},
4+
net::SocketAddr,
5+
process::{Child, Command, Stdio},
6+
sync::{Arc, Mutex},
7+
thread::{self, sleep},
8+
time::{Duration, Instant},
49
};
510

611
use reqwest::blocking::Client;
@@ -16,18 +21,13 @@ pub struct SpacetimeDbGuard {
1621
}
1722

1823
impl SpacetimeDbGuard {
19-
2024
/// Start `spacetimedb` in a temporary data directory via:
2125
/// cargo run -p spacetimedb-cli -- start --data-dir <temp-dir> --listen-addr <addr>
2226
pub fn spawn_in_temp_data_dir() -> Self {
2327
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
2428
let data_dir = temp_dir.path().display().to_string();
2529

26-
Self::spawn_spacetime_start(&[
27-
"start",
28-
"--data-dir",
29-
&data_dir,
30-
])
30+
Self::spawn_spacetime_start(&["start", "--data-dir", &data_dir])
3131
}
3232

3333
fn spawn_spacetime_start(extra_args: &[&str]) -> Self {
@@ -41,11 +41,7 @@ impl SpacetimeDbGuard {
4141

4242
Self::build_prereqs(workspace_dir);
4343

44-
let mut cargo_args = vec![
45-
"run",
46-
"-p", "spacetimedb-cli",
47-
"--",
48-
];
44+
let mut cargo_args = vec!["run", "-p", "spacetimedb-cli", "--"];
4945

5046
cargo_args.extend(extra_args);
5147
cargo_args.extend(["--listen-addr", &address]);

modules/module-test/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,14 @@ pub fn repeating_test(ctx: &ReducerContext, arg: RepeatingTestArg) {
233233

234234
#[spacetimedb::reducer]
235235
pub fn add(ctx: &ReducerContext, name: String, age: u8) {
236-
#[cfg(feature = "test-add-column")]
237-
ctx.db.person().insert(Person { id: 0, name, age, edited: false });
238-
#[cfg(not(feature = "test-add-column"))]
236+
#[cfg(feature = "test-add-column")]
237+
ctx.db.person().insert(Person {
238+
id: 0,
239+
name,
240+
age,
241+
edited: false,
242+
});
243+
#[cfg(not(feature = "test-add-column"))]
239244
ctx.db.person().insert(Person { id: 0, name, age });
240245
}
241246

0 commit comments

Comments
 (0)