Skip to content

Commit e4b71f2

Browse files
committed
Add test for getting the API doc
1 parent 020212b commit e4b71f2

5 files changed

Lines changed: 35 additions & 7 deletions

File tree

graphannis/src/annis/db/corpusstorage.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ pub struct CorpusStorage {
384384
}
385385

386386
fn init_locale() {
387-
// use collation as defined by the environment variables (LANGUAGE, LC_*, etc.)
387+
// Use collation as defined by the environment variables (LANGUAGE, LC_*, etc.)
388+
// Setting it to an empty value will use the users choice:
389+
// https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html
388390
unsafe {
389391
let locale = CString::new("").unwrap_or_default();
390392
libc::setlocale(libc::LC_COLLATE, locale.as_ptr());

graphannis/src/annis/db/sort_matches.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ mod tests {
254254
fn tiger_doc_name_sort_strcoll() {
255255
use std::time::Duration;
256256

257+
std::env::set_var("LANG", "en_US.utf8");
257258
unsafe {
258-
let locale = CString::new("POSIX").unwrap_or_default();
259+
let locale = CString::new("").unwrap_or_default();
259260
libc::setlocale(libc::LC_COLLATE, locale.as_ptr());
260261
std::thread::sleep(Duration::from_millis(500));
261262
}

verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
cargo fmt --check
88
cargo clippy
99

10-
export LANG="POSIX"
10+
export LC_COLLATE="en_US.utf8"
1111

1212
# Execute tests and calculate the code coverage both as lcov and HTML report
1313
cargo llvm-cov clean --workspace

webservice/src/snapshots/graphannis_webservice__tests__logfile_debug.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ source: webservice/src/tests.rs
33
expression: logfile_content
44
---
55
12:00:00[INFO] Hello World
6-
12:00:00[DEBUG] (7) : Debug Message
6+
12:00:00[DEBUG] (1) : Debug Message

webservice/src/tests.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::{
66
use actix_web::{
77
body::MessageBody,
88
dev::{ServiceFactory, ServiceRequest, ServiceResponse},
9-
web, App,
9+
http::StatusCode,
10+
test,
11+
web::{self, Bytes},
12+
App,
1013
};
1114
use diesel::{r2d2::ConnectionManager, SqliteConnection};
1215
use diesel_migrations::MigrationHarness;
@@ -130,11 +133,15 @@ fn standard_filter() -> insta::Settings {
130133
settings.add_filter("[0-9.]+[MG]B / [0-9.]+[MG]B", "100MB / 300MB");
131134
// The loading and time can vary
132135
settings.add_filter("in [0-9]+ ms", "in 10 ms");
136+
137+
// Debug messages have an additional ID
138+
settings.add_filter("\\[DEBUG\\] \\([0-9]+\\)", "[DEBUG] (1)");
139+
133140
settings
134141
}
135142

136143
#[test]
137-
fn test_logfile() -> Result<(), Box<dyn std::error::Error>> {
144+
async fn test_logfile() -> Result<(), Box<dyn std::error::Error>> {
138145
let logfile = NamedTempFile::new()?;
139146
let mut settings = Settings::default();
140147
settings.logging.file = Some(logfile.path().to_string_lossy().to_string());
@@ -163,7 +170,7 @@ fn test_logfile() -> Result<(), Box<dyn std::error::Error>> {
163170
}
164171

165172
#[test]
166-
fn test_logfile_debug() -> Result<(), Box<dyn std::error::Error>> {
173+
async fn test_logfile_debug() -> Result<(), Box<dyn std::error::Error>> {
167174
let logfile = NamedTempFile::new()?;
168175
let mut settings = Settings::default();
169176
settings.logging.file = Some(logfile.path().to_string_lossy().to_string());
@@ -191,3 +198,21 @@ fn test_logfile_debug() -> Result<(), Box<dyn std::error::Error>> {
191198

192199
Ok(())
193200
}
201+
202+
#[actix_web::test]
203+
async fn serve_static_files() {
204+
let db_dir = tempfile::TempDir::new().unwrap();
205+
let cs = graphannis::CorpusStorage::with_auto_cache_size(db_dir.path(), false).unwrap(); // Import three corpora A,B and C
206+
import_test_corpora(&cs);
207+
208+
let app = test::init_service(create_test_app(web::Data::new(cs), Settings::default())).await;
209+
210+
// Unauthorized user should not see any corpora
211+
let req = test::TestRequest::get()
212+
.uri("/v1/api-docs.html")
213+
.to_request();
214+
let resp = test::call_service(&app, req).await;
215+
assert_eq!(resp.status(), StatusCode::OK);
216+
let response_body: Bytes = test::read_body(resp).await;
217+
assert_eq!(false, response_body.is_empty());
218+
}

0 commit comments

Comments
 (0)