Skip to content

Commit 1a77b1c

Browse files
committed
more tests
1 parent 9c00186 commit 1a77b1c

9 files changed

+178
-0
lines changed

cot-cli/src/handlers.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ mod tests {
145145
assert!(result.is_err());
146146
}
147147

148+
#[test]
149+
fn migration_new_wrong_directory() {
150+
let args = MigrationNewArgs {
151+
name: "test_migration".to_string(),
152+
path: Some(PathBuf::from("nonexistent")),
153+
app_name: None,
154+
};
155+
156+
let result = handle_migration_new(args);
157+
158+
assert!(result.is_err());
159+
}
160+
148161
#[test]
149162
fn generate_manpages() {
150163
let temp_dir = tempfile::tempdir().unwrap();

cot-cli/tests/snapshot_testing/migration/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,23 @@ fn migration_make_existing_model() {
114114
);
115115
}
116116
}
117+
118+
#[test]
119+
#[expect(clippy::cast_possible_truncation)]
120+
fn migration_new() {
121+
let cmd = cot_cli!("migration", "new", "custom");
122+
for (idx, mut cli) in cot_clis_with_verbosity(&cmd).into_iter().enumerate() {
123+
let filter = Verbosity::<OffLevel>::new(idx as u8, 0).filter();
124+
125+
let temp_dir = tempfile::TempDir::with_prefix("cot-test-").unwrap();
126+
test_utils::make_package(temp_dir.path()).unwrap();
127+
128+
insta::with_settings!(
129+
{
130+
description => format!("Verbosity level: {filter}"),
131+
filters => [GENERIC_FILTERS, TEMP_PATH_FILTERS, TEMP_PROJECT_FILTERS].concat()
132+
},
133+
{ assert_cmd_snapshot!(cli.current_dir(temp_dir.path())) }
134+
);
135+
}
136+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: cot-cli/tests/snapshot_testing/migration/mod.rs
3+
description: "Verbosity level: error"
4+
info:
5+
program: cot
6+
args:
7+
- migration
8+
- new
9+
- custom
10+
- "-v"
11+
---
12+
success: true
13+
exit_code: 0
14+
----- stdout -----
15+
16+
----- stderr -----
17+
 Creating Migration 'm_0001_custom'
18+
 Creating Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
19+
 Created Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
20+
 Created Migration 'm_0001_custom'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: cot-cli/tests/snapshot_testing/migration/mod.rs
3+
description: "Verbosity level: warn"
4+
info:
5+
program: cot
6+
args:
7+
- migration
8+
- new
9+
- custom
10+
- "-vv"
11+
---
12+
success: true
13+
exit_code: 0
14+
----- stdout -----
15+
16+
----- stderr -----
17+
 Creating Migration 'm_0001_custom'
18+
 Creating Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
19+
 Created Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
20+
 Created Migration 'm_0001_custom'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
source: cot-cli/tests/snapshot_testing/migration/mod.rs
3+
description: "Verbosity level: info"
4+
info:
5+
program: cot
6+
args:
7+
- migration
8+
- new
9+
- custom
10+
- "-vvv"
11+
---
12+
success: true
13+
exit_code: 0
14+
----- stdout -----
15+
TIMESTAMP DEBUG cot_cli::migration_generator: Parsing file: "/tmp/TEMP_PATH/src/main.rs"
16+
17+
----- stderr -----
18+
 Creating Migration 'm_0001_custom'
19+
 Creating Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
20+
 Created Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
21+
 Created Migration 'm_0001_custom'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: cot-cli/tests/snapshot_testing/migration/mod.rs
3+
description: "Verbosity level: debug"
4+
info:
5+
program: cot
6+
args:
7+
- migration
8+
- new
9+
- custom
10+
- "-vvvv"
11+
---
12+
success: true
13+
exit_code: 0
14+
----- stdout -----
15+
TIMESTAMP DEBUG cot_cli::migration_generator: Parsing file: "/tmp/TEMP_PATH/src/main.rs"
16+
TIMESTAMP TRACE cot_cli::migration_generator: Processing file: "main.rs"
17+
18+
----- stderr -----
19+
 Creating Migration 'm_0001_custom'
20+
 Creating Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
21+
 Created Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
22+
 Created Migration 'm_0001_custom'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: cot-cli/tests/snapshot_testing/migration/mod.rs
3+
description: "Verbosity level: trace"
4+
info:
5+
program: cot
6+
args:
7+
- migration
8+
- new
9+
- custom
10+
- "-vvvvv"
11+
---
12+
success: true
13+
exit_code: 0
14+
----- stdout -----
15+
TIMESTAMP DEBUG cot_cli::migration_generator: Parsing file: "/tmp/TEMP_PATH/src/main.rs"
16+
TIMESTAMP TRACE cot_cli::migration_generator: Processing file: "main.rs"
17+
18+
----- stderr -----
19+
 Creating Migration 'm_0001_custom'
20+
 Creating Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
21+
 Created Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
22+
 Created Migration 'm_0001_custom'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: cot-cli/tests/snapshot_testing/migration/mod.rs
3+
description: "Verbosity level: off"
4+
info:
5+
program: cot
6+
args:
7+
- migration
8+
- new
9+
- custom
10+
- "-q"
11+
---
12+
success: true
13+
exit_code: 0
14+
----- stdout -----
15+
16+
----- stderr -----
17+
 Creating Migration 'm_0001_custom'
18+
 Creating Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
19+
 Created Migration file '/tmp/TEMP_PATH/src/migrations/m_0001_custom.rs'
20+
 Created Migration 'm_0001_custom'

cot/src/db/migrations.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,26 @@ mod tests {
22052205
assert!(result.is_err());
22062206
}
22072207

2208+
#[cot::test]
2209+
#[cfg_attr(
2210+
miri,
2211+
ignore = "unsupported operation: can't call foreign function `sqlite3_open_v2`"
2212+
)]
2213+
async fn operation_custom_backwards_not_implemented() {
2214+
// test only on SQLite because we are using raw SQL
2215+
let test_db = TestDatabase::new_sqlite().await.unwrap();
2216+
2217+
#[migration_op]
2218+
async fn forwards(_ctx: MigrationContext<'_>) -> Result<()> {
2219+
Ok(())
2220+
}
2221+
2222+
let operation = Operation::custom(forwards).build();
2223+
let result = operation.backwards(&test_db.database()).await;
2224+
2225+
assert!(result.is_err());
2226+
}
2227+
22082228
#[test]
22092229
fn field_new() {
22102230
let field = Field::new(Identifier::new("id"), ColumnType::Integer)

0 commit comments

Comments
 (0)