Skip to content

Commit 0188c08

Browse files
author
Alexei Pastuchov
committed
setup cli tests for mysql
1 parent 463dafc commit 0188c08

File tree

1 file changed

+52
-2
lines changed
  • wundergraph_cli/src/print_schema

1 file changed

+52
-2
lines changed

wundergraph_cli/src/print_schema/mod.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ mod tests {
125125
);"#,
126126
];
127127

128+
#[cfg(feature = "mysql")]
129+
const MIGRATION: &[&str] = &[
130+
"CREATE TABLE users(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name TEXT NOT NULL);",
131+
r#"CREATE TABLE posts(
132+
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
133+
author INTEGER REFERENCES users(id),
134+
title TEXT NOT NULL,
135+
datetime TIMESTAMP,
136+
content TEXT
137+
);"#,
138+
r#"CREATE TABLE comments(
139+
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
140+
post INTEGER REFERENCES posts(id),
141+
commenter INTEGER REFERENCES users(id),
142+
content TEXT NOT NULL
143+
);"#,
144+
];
145+
128146
fn setup_simple_schema(conn: &InferConnection) {
129147
use diesel::prelude::*;
130148
use diesel::sql_query;
@@ -141,6 +159,12 @@ mod tests {
141159
sql_query(*m).execute(conn).unwrap();
142160
}
143161
}
162+
#[cfg(feature = "mysql")]
163+
InferConnection::Mysql(conn) => {
164+
for m in MIGRATION {
165+
sql_query(*m).execute(conn).unwrap();
166+
}
167+
}
144168
}
145169
}
146170

@@ -153,7 +177,7 @@ mod tests {
153177

154178
#[cfg(feature = "postgres")]
155179
print(&conn, Some("infer_test"), &mut out).unwrap();
156-
#[cfg(feature = "sqlite")]
180+
#[cfg(any(feature = "mysql", feature = "sqlite"))]
157181
print(&conn, None, &mut out).unwrap();
158182

159183
let s = String::from_utf8(out).unwrap();
@@ -187,7 +211,7 @@ mod tests {
187211
let mut api_file = File::create(api).unwrap();
188212
#[cfg(feature = "postgres")]
189213
print(&conn, Some("infer_test"), &mut api_file).unwrap();
190-
#[cfg(feature = "sqlite")]
214+
#[cfg(any(feature = "mysql", feature = "sqlite"))]
191215
print(&conn, None, &mut api_file).unwrap();
192216

193217
let main = tmp_dir
@@ -224,6 +248,17 @@ mod tests {
224248
)
225249
.unwrap();
226250

251+
#[cfg(feature = "mysql")]
252+
write!(
253+
main_file,
254+
include_str!("template_main.rs"),
255+
conn = "MysqlConnection",
256+
db_url = std::env::var("DATABASE_URL").unwrap(),
257+
migrations = migrations,
258+
listen_url = listen_url
259+
)
260+
.unwrap();
261+
227262
let cargo_toml = tmp_dir.path().join("wundergraph_roundtrip_test/Cargo.toml");
228263
let mut cargo_toml_file = std::fs::OpenOptions::new()
229264
.write(true)
@@ -269,6 +304,21 @@ mod tests {
269304
)
270305
.unwrap();
271306
}
307+
#[cfg(feature = "mysql")]
308+
{
309+
writeln!(
310+
cargo_toml_file,
311+
r#"diesel = {{version = "1.4", features = ["mysql", "chrono"]}}"#
312+
)
313+
.unwrap();
314+
315+
writeln!(
316+
cargo_toml_file,
317+
"wundergraph = {{path = \"{}\", features = [\"mysql\", \"chrono\"] }}",
318+
wundergraph_dir
319+
)
320+
.unwrap();
321+
}
272322
writeln!(cargo_toml_file, r#"juniper = "0.14""#).unwrap();
273323
writeln!(cargo_toml_file, r#"failure = "0.1""#).unwrap();
274324
writeln!(cargo_toml_file, r#"actix-web = "1""#).unwrap();

0 commit comments

Comments
 (0)