Skip to content

Commit 094d06d

Browse files
author
Alexei Pastuchov
committed
setup cli tests for mysql
1 parent e3c50f4 commit 094d06d

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

+52-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ mod tests {
119119
);"#,
120120
];
121121

122+
#[cfg(feature = "mysql")]
123+
const MIGRATION: &[&str] = &[
124+
"CREATE TABLE users(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name TEXT NOT NULL);",
125+
r#"CREATE TABLE posts(
126+
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
127+
author INTEGER REFERENCES users(id),
128+
title TEXT NOT NULL,
129+
datetime TIMESTAMP,
130+
content TEXT
131+
);"#,
132+
r#"CREATE TABLE comments(
133+
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
134+
post INTEGER REFERENCES posts(id),
135+
commenter INTEGER REFERENCES users(id),
136+
content TEXT NOT NULL
137+
);"#,
138+
];
139+
122140
fn setup_simple_schema(conn: &InferConnection) {
123141
use diesel::prelude::*;
124142
use diesel::sql_query;
@@ -135,6 +153,12 @@ mod tests {
135153
sql_query(*m).execute(conn).unwrap();
136154
}
137155
}
156+
#[cfg(feature = "mysql")]
157+
InferConnection::Mysql(conn) => {
158+
for m in MIGRATION {
159+
sql_query(*m).execute(conn).unwrap();
160+
}
161+
}
138162
}
139163
}
140164

@@ -147,7 +171,7 @@ mod tests {
147171

148172
#[cfg(feature = "postgres")]
149173
print(&conn, Some("infer_test"), &mut out).unwrap();
150-
#[cfg(feature = "sqlite")]
174+
#[cfg(any(feature = "mysql", feature = "sqlite"))]
151175
print(&conn, None, &mut out).unwrap();
152176

153177
let s = String::from_utf8(out).unwrap();
@@ -179,7 +203,7 @@ mod tests {
179203
let mut api_file = File::create(api).unwrap();
180204
#[cfg(feature = "postgres")]
181205
print(&conn, Some("infer_test"), &mut api_file).unwrap();
182-
#[cfg(feature = "sqlite")]
206+
#[cfg(any(feature = "mysql", feature = "sqlite"))]
183207
print(&conn, None, &mut api_file).unwrap();
184208

185209
let main = tmp_dir
@@ -216,6 +240,17 @@ mod tests {
216240
)
217241
.unwrap();
218242

243+
#[cfg(feature = "mysql")]
244+
write!(
245+
main_file,
246+
include_str!("template_main.rs"),
247+
conn = "MysqlConnection",
248+
db_url = std::env::var("DATABASE_URL").unwrap(),
249+
migrations = migrations,
250+
listen_url = listen_url
251+
)
252+
.unwrap();
253+
219254
let cargo_toml = tmp_dir.path().join("wundergraph_roundtrip_test/Cargo.toml");
220255
let mut cargo_toml_file = std::fs::OpenOptions::new()
221256
.write(true)
@@ -261,6 +296,21 @@ mod tests {
261296
)
262297
.unwrap();
263298
}
299+
#[cfg(feature = "mysql")]
300+
{
301+
writeln!(
302+
cargo_toml_file,
303+
r#"diesel = {{version = "1.4", features = ["mysql", "chrono"]}}"#
304+
)
305+
.unwrap();
306+
307+
writeln!(
308+
cargo_toml_file,
309+
"wundergraph = {{path = \"{}\", features = [\"mysql\", \"chrono\"] }}",
310+
wundergraph_dir
311+
)
312+
.unwrap();
313+
}
264314
writeln!(cargo_toml_file, r#"juniper = "0.14""#).unwrap();
265315
writeln!(cargo_toml_file, r#"failure = "0.1""#).unwrap();
266316
writeln!(cargo_toml_file, r#"actix-web = "1""#).unwrap();

0 commit comments

Comments
 (0)