Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- name: install dependencies (ubuntu only)
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- uses: actions/cache@v5.0.4
with:
path: target
key: ${{ runner.os }}-target
- name: Install ${{ matrix.toolchain }}
uses: dtolnay/rust-toolchain@master
with:
Expand Down Expand Up @@ -82,10 +82,10 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- name: install dependencies (ubuntu only)
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- uses: actions/cache@v5.0.4
with:
path: target
key: ${{ runner.os }}-target
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions basalt-server-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version.workspace = true
rust-version.workspace = true

[features]
testing = ["dep:tracing-subscriber"]
doc-gen = []
webhooks = ["dep:reqwest"]
scripting = ["dep:rustyscript"]
Expand All @@ -17,7 +18,6 @@ uninlined_format_args = "allow"
[dependencies]
anyhow.workspace = true
argon2.workspace = true
async-tempfile.workspace = true
axum-extra.workspace = true
axum.workspace = true
bedrock.workspace = true
Expand Down Expand Up @@ -45,10 +45,11 @@ rustyscript = { git = "https://github.com/rscarson/rustyscript.git", branch = "m
reqwest = { version = "0.13.2", features = ["json"], optional = true }
futures = "0.3.31"
ident-str = "0.1.0"
tracing-subscriber = { workspace = true, optional = true }

[dev-dependencies]
async-tempfile = { workspace = true, features = ["uuid"] }
tracing-subscriber.workspace = true
async-tempfile.workspace = true

[build-dependencies]
tokio = { version = "1.43.0", features = ["full"] }
Expand Down
11 changes: 2 additions & 9 deletions basalt-server-lib/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::Path;

use anyhow::Context;

Expand All @@ -8,14 +8,7 @@ pub async fn main() -> anyhow::Result<()> {
let cargo_target_dir =
std::env::var("OUT_DIR").context("Failed to get cargo target directory")?;

let path = PathBuf::from(cargo_target_dir)
.join("initial_data")
.with_extension("db");

println!(
"cargo::rustc-env=INITIAL_DATA_PATH={}",
path.to_str().unwrap()
);
let path = Path::new(&cargo_target_dir).join("initial_data.db");

let sqlite_uri = format!("sqlite:{}", path.to_str().unwrap());

Expand Down
4 changes: 2 additions & 2 deletions basalt-server-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod services;
pub mod storage;
mod utils;

#[cfg(test)]
mod testing;
#[cfg(any(test, feature = "testing"))]
pub mod testing;
9 changes: 3 additions & 6 deletions basalt-server-lib/src/repositories/announcements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,19 @@ mod tests {

#[tokio::test]
async fn create_announcement() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
let announcement = super::create_announcement(&sql, &user.id, "hello world")
.await
.unwrap();

assert_eq!(announcement.sender, user.id);
assert_eq!(&announcement.message, "hello world");
drop(f)
}

#[tokio::test]
async fn get_announcements() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
super::create_announcement(&sql, &user.id, "foo")
.await
Expand All @@ -126,12 +125,11 @@ mod tests {

assert!(ann.iter().any(|a| a.message == "foo"));
assert!(ann.iter().any(|a| a.message == "bar"));
drop(f)
}

#[tokio::test]
async fn delete_announcement() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
let Announcement { id, .. } = super::create_announcement(&sql, &user.id, "foo")
.await
Expand All @@ -145,6 +143,5 @@ mod tests {

let ann = super::get_announcements(&sql).await.unwrap();
assert!(ann.is_empty());
drop(f)
}
}
22 changes: 6 additions & 16 deletions basalt-server-lib/src/repositories/submissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ mod tests {

#[tokio::test]
async fn create_submission() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
let history = create_submission_history(
&sql,
Expand Down Expand Up @@ -553,12 +553,11 @@ mod tests {
assert_eq!(history.question_index, 42);
assert_eq!(history.score, 42.);
assert!(!history.success);
drop(f)
}

#[tokio::test]
async fn create_submission_test() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
let history = create_submission_history(
&sql,
Expand Down Expand Up @@ -595,12 +594,11 @@ mod tests {
assert_eq!(test.stdout, "stdout");
assert_eq!(test.stderr, "stderr");
assert_eq!(test.exit_status, 1);
drop(f)
}

#[tokio::test]
async fn other_submissions() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;

for i in 0..5 {
let user = dummy_user(
Expand Down Expand Up @@ -652,13 +650,11 @@ mod tests {

let n = count_other_submissions(&sql, 1).await.unwrap();
assert_eq!(n, 5);

drop(f)
}

#[tokio::test]
async fn previous_submissions() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;

let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
for _ in 0..5 {
Expand All @@ -685,13 +681,11 @@ mod tests {

let n = count_previous_submissions(&sql, &user.id, 1).await.unwrap();
assert_eq!(n, 5);

drop(f)
}

#[tokio::test]
async fn user_score() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;

let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
for i in 0..5 {
Expand All @@ -716,13 +710,11 @@ mod tests {

let n = get_user_score(&sql, &user.id).await.unwrap();
assert_eq!(n, 42. * 5.);

drop(f)
}

#[tokio::test]
async fn latest_submissions() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;

let user = dummy_user(&sql, "dummy_user", "foobar", Role::Competitor).await;
for i in 0..5 {
Expand Down Expand Up @@ -772,7 +764,5 @@ mod tests {
for s in submissions {
assert_eq!(s.code, "latest");
}

drop(f)
}
}
9 changes: 3 additions & 6 deletions basalt-server-lib/src/repositories/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,14 @@ mod tests {
use super::*;
#[tokio::test]
async fn get_nonexistent_user() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let response = get_user_by_id(&sql, &UserId::new()).await;
assert!(response.is_err());
drop(f)
}

#[tokio::test]
async fn get_existing_user_by_id() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let dummy_user = create_user(
&sql,
"awesome_user".to_string(),
Expand All @@ -242,12 +241,11 @@ mod tests {
.await
.expect("Failed to find user");
assert_eq!(user.username, dummy_user.username);
drop(f)
}

#[tokio::test]
async fn get_correct_user() {
let (f, sql) = mock_db().await;
let sql = mock_db().await;
let dummy_user = crate::testing::users_repositories::dummy_user(
&sql,
"awesome_user".to_string(),
Expand All @@ -266,6 +264,5 @@ mod tests {
.await
.expect("Failed to find user");
assert_eq!(user.username, dummy_user.username);
drop(f)
}
}
Loading
Loading