2024-02-05 11:47:56 +01:00
use meili_snap ::* ;
use crate ::common ::Server ;
use crate ::json ;
#[ actix_rt::test ]
2024-02-07 12:13:57 +01:00
async fn logs_stream_bad_target ( ) {
2024-02-05 11:47:56 +01:00
let server = Server ::new ( ) . await ;
// Wrong type
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " target " : true } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value type at `.target`: expected a string, but found a boolean: `true` " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// Wrong type
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " target " : [ ] } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value type at `.target`: expected a string, but found an array: `[]` " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// Our help message
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " target " : " " } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
2024-02-08 13:49:27 +01:00
" message " : " Invalid value at `.target`: Empty string is not a valid target. If you want to get no logs use `OFF`. Usage: `info`, `meilisearch=info`, or you can write multiple filters in one target: `index_scheduler=info,milli=trace` " ,
2024-02-05 11:47:56 +01:00
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// An error from the target parser
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " target " : " == " } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value at `.target`: invalid filter directive: too many '=' in filter directive, expected 0 or 1 " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
}
#[ actix_rt::test ]
2024-02-07 12:13:57 +01:00
async fn logs_stream_bad_mode ( ) {
2024-02-05 11:47:56 +01:00
let server = Server ::new ( ) . await ;
// Wrong type
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " mode " : true } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value type at `.mode`: expected a string, but found a boolean: `true` " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// Wrong type
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " mode " : [ ] } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value type at `.mode`: expected a string, but found an array: `[]` " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// Wrong value
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { " mode " : " tamo " } ) ) . await ;
2024-02-05 11:47:56 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
2024-02-14 15:34:39 +01:00
" message " : " Unknown value `tamo` at `.mode`: expected one of `human`, `json`, `profile` " ,
2024-02-05 11:47:56 +01:00
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
}
2024-02-05 14:05:24 +01:00
2024-02-07 14:45:40 +01:00
#[ actix_rt::test ]
async fn logs_stream_bad_profile_memory ( ) {
let server = Server ::new ( ) . await ;
// Wrong type
let ( response , code ) =
server . service . post ( " /logs/stream " , json! ( { " profileMemory " : " tamo " } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value type at `.profileMemory`: expected a boolean, but found a string: ` \" tamo \" ` " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// Wrong type
let ( response , code ) =
server . service . post ( " /logs/stream " , json! ( { " profileMemory " : [ " hello " , " kefir " ] } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Invalid value type at `.profileMemory`: expected a boolean, but found an array: `[ \" hello \" , \" kefir \" ]` " ,
" code " : " bad_request " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#bad_request "
}
" ###);
// Used with default parameters
let ( response , code ) =
server . service . post ( " /logs/stream " , json! ( { " profileMemory " : true } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
2024-02-08 13:59:30 +01:00
" message " : " Invalid value: `profile_memory` can only be used while profiling code and is not compatible with the Human mode. " ,
2024-02-07 14:45:40 +01:00
" code " : " invalid_settings_typo_tolerance " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#invalid_settings_typo_tolerance "
}
" ###);
// Used with an unsupported mode
let ( response , code ) =
server . service . post ( " /logs/stream " , json! ( { " mode " : " fmt " , " profileMemory " : true } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
2024-02-14 15:34:39 +01:00
" message " : " Unknown value `fmt` at `.mode`: expected one of `human`, `json`, `profile` " ,
2024-02-08 13:59:30 +01:00
" code " : " bad_request " ,
2024-02-07 14:45:40 +01:00
" type " : " invalid_request " ,
2024-02-08 13:59:30 +01:00
" link " : " https://docs.meilisearch.com/errors#bad_request "
2024-02-07 14:45:40 +01:00
}
" ###);
}
2024-02-05 14:05:24 +01:00
#[ actix_rt::test ]
2024-02-07 12:13:57 +01:00
async fn logs_stream_without_enabling_the_route ( ) {
2024-02-05 14:05:24 +01:00
let server = Server ::new ( ) . await ;
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . post ( " /logs/stream " , json! ( { } ) ) . await ;
2024-02-05 14:05:24 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
2024-02-12 11:06:37 +01:00
" message " : " Modifying logs through the `/logs/*` routes requires enabling the `logs route` experimental feature. See https://github.com/orgs/meilisearch/discussions/721 " ,
2024-02-05 14:05:24 +01:00
" code " : " feature_not_enabled " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#feature_not_enabled "
}
" ###);
2024-02-07 12:13:57 +01:00
let ( response , code ) = server . service . delete ( " /logs/stream " ) . await ;
2024-02-05 14:05:24 +01:00
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
2024-02-12 11:06:37 +01:00
" message " : " Modifying logs through the `/logs/*` routes requires enabling the `logs route` experimental feature. See https://github.com/orgs/meilisearch/discussions/721 " ,
" code " : " feature_not_enabled " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#feature_not_enabled "
}
" ###);
let ( response , code ) = server . service . post ( " /logs/stderr " , json! ( { } ) ) . await ;
snapshot! ( code , @ " 400 Bad Request " ) ;
snapshot! ( response , @ r ###"
{
" message " : " Modifying logs through the `/logs/*` routes requires enabling the `logs route` experimental feature. See https://github.com/orgs/meilisearch/discussions/721 " ,
2024-02-05 14:05:24 +01:00
" code " : " feature_not_enabled " ,
" type " : " invalid_request " ,
" link " : " https://docs.meilisearch.com/errors#feature_not_enabled "
}
" ###);
}