forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ecde1d
commit eedb0ce
Showing
20 changed files
with
304 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[alias] | ||
cov = "llvm-cov" | ||
cov-lcov = "llvm-cov --lcov --output-path=./.coverage/lcov.info" | ||
cov-html = "llvm-cov --html" | ||
time = "build --timings --all-targets" | ||
e2e = "test --features e2e-tests" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
/.coverage/ | ||
/.env | ||
/config.toml | ||
/data_v2.db* | ||
/data.db* | ||
/storage/ | ||
/target | ||
/uploads/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
docker compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ | ||
docker compose build | ||
|
||
TORRUST_IDX_BACK_USER_UID=${TORRUST_IDX_BACK_USER_UID:-1000} \ | ||
TORRUST_IDX_BACK_CONFIG=$(cat config-idx-back.toml.local) \ | ||
TORRUST_TRACKER_CONFIG=$(cat config-tracker.toml.local) \ | ||
TORRUST_TRACKER_API_TOKEN=${TORRUST_TRACKER_API_TOKEN:-MyAccessToken} \ | ||
docker compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
CURRENT_USER_NAME=$(whoami) | ||
CURRENT_USER_ID=$(id -u) | ||
echo "User name: $CURRENT_USER_NAME" | ||
echo "User id: $CURRENT_USER_ID" | ||
|
||
TORRUST_IDX_BACK_USER_UID=$CURRENT_USER_ID | ||
TORRUST_TRACKER_USER_UID=$CURRENT_USER_ID | ||
export TORRUST_IDX_BACK_USER_UID | ||
export TORRUST_TRACKER_USER_UID | ||
|
||
wait_for_container_to_be_healthy() { | ||
local container_name="$1" | ||
local max_retries="$2" | ||
local retry_interval="$3" | ||
local retry_count=0 | ||
|
||
while [ $retry_count -lt "$max_retries" ]; do | ||
container_health="$(docker inspect --format='{{json .State.Health}}' "$container_name")" | ||
if [ "$container_health" != "{}" ]; then | ||
container_status="$(echo "$container_health" | jq -r '.Status')" | ||
if [ "$container_status" == "healthy" ]; then | ||
echo "Container $container_name is healthy" | ||
return 0 | ||
fi | ||
fi | ||
|
||
retry_count=$((retry_count + 1)) | ||
echo "Waiting for container $container_name to become healthy (attempt $retry_count of $max_retries)..." | ||
sleep "$retry_interval" | ||
done | ||
|
||
echo "Timeout reached, container $container_name is not healthy" | ||
return 1 | ||
} | ||
|
||
cp .env.local .env | ||
./bin/install.sh | ||
|
||
# Start E2E testing environment | ||
./docker/bin/e2e-env-up.sh | ||
|
||
wait_for_container_to_be_healthy torrust-mysql-1 10 3 | ||
# todo: implement healthchecks for tracker and backend and wait until they are healthy | ||
#wait_for_container torrust-tracker-1 10 3 | ||
#wait_for_container torrust-idx-back-1 10 3 | ||
sleep 20s | ||
|
||
# Just to make sure that everything is up and running | ||
docker ps | ||
|
||
# Run E2E tests | ||
cargo test --features e2e-tests | ||
|
||
# Stop E2E testing environment | ||
./docker/bin/e2e-env-down.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use reqwest::Response; | ||
|
||
use crate::e2e::connection_info::ConnectionInfo; | ||
use crate::e2e::http::{Query, ReqwestQuery}; | ||
|
||
/// API Client | ||
pub struct Client { | ||
connection_info: ConnectionInfo, | ||
base_path: String, | ||
} | ||
|
||
impl Client { | ||
pub fn new(connection_info: ConnectionInfo) -> Self { | ||
Self { | ||
connection_info, | ||
base_path: "/".to_string(), | ||
} | ||
} | ||
|
||
pub async fn entrypoint(&self) -> Response { | ||
self.get("", Query::default()).await | ||
} | ||
|
||
pub async fn get(&self, path: &str, params: Query) -> Response { | ||
self.get_request_with_query(path, params).await | ||
} | ||
|
||
/* | ||
pub async fn post(&self, path: &str) -> Response { | ||
reqwest::Client::new().post(self.base_url(path).clone()).send().await.unwrap() | ||
} | ||
async fn delete(&self, path: &str) -> Response { | ||
reqwest::Client::new() | ||
.delete(self.base_url(path).clone()) | ||
.send() | ||
.await | ||
.unwrap() | ||
} | ||
pub async fn get_request(&self, path: &str) -> Response { | ||
get(&self.base_url(path), None).await | ||
} | ||
*/ | ||
|
||
pub async fn get_request_with_query(&self, path: &str, params: Query) -> Response { | ||
get(&self.base_url(path), Some(params)).await | ||
} | ||
|
||
fn base_url(&self, path: &str) -> String { | ||
format!("http://{}{}{path}", &self.connection_info.bind_address, &self.base_path) | ||
} | ||
} | ||
|
||
async fn get(path: &str, query: Option<Query>) -> Response { | ||
match query { | ||
Some(params) => reqwest::Client::builder() | ||
.build() | ||
.unwrap() | ||
.get(path) | ||
.query(&ReqwestQuery::from(params)) | ||
.send() | ||
.await | ||
.unwrap(), | ||
None => reqwest::Client::builder().build().unwrap().get(path).send().await.unwrap(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pub fn connection_with_no_token(bind_address: &str) -> ConnectionInfo { | ||
ConnectionInfo::anonymous(bind_address) | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct ConnectionInfo { | ||
pub bind_address: String, | ||
} | ||
|
||
impl ConnectionInfo { | ||
pub fn anonymous(bind_address: &str) -> Self { | ||
Self { | ||
bind_address: bind_address.to_string(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::e2e::client::Client; | ||
use crate::e2e::connection_info::connection_with_no_token; | ||
|
||
#[tokio::test] | ||
#[cfg_attr(not(feature = "e2e-tests"), ignore)] | ||
async fn it_should_load_the_about_page_at_the_api_entrypoint() { | ||
let client = Client::new(connection_with_no_token("localhost:3000")); | ||
|
||
let response = client.entrypoint().await; | ||
|
||
assert_eq!(response.status(), 200); | ||
assert_eq!(response.headers().get("content-type").unwrap(), "text/html; charset=utf-8"); | ||
|
||
let title = format!("<title>About</title>"); | ||
let response_text = response.text().await.unwrap(); | ||
|
||
assert!( | ||
response_text.contains(&title), | ||
":\n response: `\"{response_text}\"`\n does not contain: `\"{title}\"`." | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod about; |
Oops, something went wrong.