Replace PostgreSQL service with several docker containers in ci.yml

This commit is contained in:
Сырцев Вадим Игоревич 2024-01-26 13:52:55 +03:00
parent 3565186d61
commit fa32ff762e
3 changed files with 12 additions and 22 deletions

View file

@ -74,18 +74,6 @@ jobs:
test: test:
name: Test name: Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
services:
# Setup Postgres for testing PostgresStorage
postgres:
image: postgres
volumes:
- init.sql:/docker-entrypoint-initdb.d/init.sql
env:
POSTGRES_USER: teloxide
POSTGRES_PASSWORD: rewrite_it_in_rust
strategy: strategy:
matrix: matrix:
rust: rust:
@ -131,7 +119,11 @@ jobs:
redis-server --port 7777 > /dev/null & redis-server --port 7777 > /dev/null &
redis-server --port 7778 > /dev/null & redis-server --port 7778 > /dev/null &
redis-server --port 7779 > /dev/null & redis-server --port 7779 > /dev/null &
- name: Start PostgreSQL servers
run: |
docker run -d -p 5432:5432 -e POSTGRES_USER=teloxide -e POSTGRES_PASSWORD=rewrite_it_in_rust -e POSTGRES_DB=test_postgres_json postgres
docker run -d -p 5433:5432 -e POSTGRES_USER=teloxide -e POSTGRES_PASSWORD=rewrite_it_in_rust -e POSTGRES_DB=test_postgres_bincode postgres
docker run -d -p 5434:5432 -e POSTGRES_USER=teloxide -e POSTGRES_PASSWORD=rewrite_it_in_rust -e POSTGRES_DB=test_postgres_cbor postgres
- name: Test unit & integration tests - name: Test unit & integration tests
run: | run: |
cargo +${{ matrix.toolchain }} test --tests --verbose ${{ matrix.features }} cargo +${{ matrix.toolchain }} test --tests --verbose ${{ matrix.features }}

View file

@ -1,4 +0,0 @@
CREATE ROLE teloxide WITH LOGIN SUPERUSER PASSWORD 'rewrite_it_in_rust'
CREATE DATABASE test_postgres_json;
CREATE DATABASE test_postgres_bincode;
CREATE_DATABASE test_postgres_cbor;

View file

@ -7,12 +7,14 @@ use teloxide::{
types::ChatId, types::ChatId,
}; };
// These examples are meant to run under the CI with the postgres service
// Were checked locally
#[tokio::test] #[tokio::test]
#[cfg_attr(not(CI_POSTGRES), ignore)] #[cfg_attr(not(CI_POSTGRES), ignore)]
async fn test_postgres_json() { async fn test_postgres_json() {
let storage = PostgresStorage::open( let storage = PostgresStorage::open(
"postgres://teloxide:rewrite_it_in_rust@localhost:5432/test_postgres_json", "postgres://teloxide:rewrite_it_in_rust@localhost:5432/test_postgres_json",
4, 1,
teloxide::dispatching::dialogue::serializer::Json, teloxide::dispatching::dialogue::serializer::Json,
) )
.await .await
@ -25,8 +27,8 @@ async fn test_postgres_json() {
#[cfg_attr(not(CI_POSTGRES), ignore)] #[cfg_attr(not(CI_POSTGRES), ignore)]
async fn test_postgres_bincode() { async fn test_postgres_bincode() {
let storage = PostgresStorage::open( let storage = PostgresStorage::open(
"postgres://teloxide:rewrite_it_in_rust@localhost:5432/test_postgres_bincode", "postgres://teloxide:rewrite_it_in_rust@localhost:5433/test_postgres_bincode",
4, 1,
teloxide::dispatching::dialogue::serializer::Bincode, teloxide::dispatching::dialogue::serializer::Bincode,
) )
.await .await
@ -39,8 +41,8 @@ async fn test_postgres_bincode() {
#[cfg_attr(not(CI_POSTGRES), ignore)] #[cfg_attr(not(CI_POSTGRES), ignore)]
async fn test_postgres_cbor() { async fn test_postgres_cbor() {
let storage = PostgresStorage::open( let storage = PostgresStorage::open(
"postgres://teloxide:rewrite_it_in_rust@localhost:5432/test_postgres_cbor", "postgres://teloxide:rewrite_it_in_rust@localhost:5434/test_postgres_cbor",
4, 1,
teloxide::dispatching::dialogue::serializer::Cbor, teloxide::dispatching::dialogue::serializer::Cbor,
) )
.await .await