diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b3ebe27..f08e3fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,33 +1,93 @@ -image: hatsoftwares/test-ci:latest +image: hatsoftwares/lutim-test-ci:latest stages: - - sqlite - - postgresql + - podcheck + - carton + - carton_bdd + - tests before_script: - - carton install - rm -f *db -sqlite1: - stage: sqlite - cache: - key: "$CI_BUILD_REF_NAME" - untracked: true +variables: + POSTGRES_DB: lutim_db + POSTGRES_USER: lutim + POSTGRES_PASSWORD: lutim_pwd + +### Jobs templates +## +# +.carton_bdd_template: &carton_bdd_definition + stage: carton_bdd + retry: 2 + artifacts: paths: - - local + - local/ + dependencies: + - carton +.sqlite_template: &sqlite_definition + stage: tests + retry: 2 + dependencies: + - carton_sqlite + coverage: '/Total .*\d+\.\d+$/' +.pg_template: &pg_definition + stage: tests + retry: 2 + dependencies: + - carton_postgresql + services: + - name: postgres:9.6 + alias: postgres + coverage: '/Total .*\d+\.\d+$/' + +### Podcheck +## +# +podcheck: + stage: podcheck script: - make podcheck + +### Install common dependencies +## +# +carton: + stage: carton + artifacts: + paths: + - local/ + dependencies: [] + script: + - carton install --deployment --without=sqlite --without=postgresql --without=minion --without=cache + when: always + retry: 2 + +### Install DB related dependencies +## +# +carton_sqlite: + <<: *carton_bdd_definition + script: + - carton install --deployment --without=postgresql --without=minion --without=cache +carton_postgresql: + <<: *carton_bdd_definition + script: + - carton install --deployment --without=sqlite --without=minion --without=cache + +### SQLite tests +## +# +sqlite1: + <<: *sqlite_definition + script: + - carton install --deployment --without=postgresql --without=minion --without=cache - MOJO_CONFIG=t/sqlite1.conf make test-sqlite - MOJO_CONFIG=t/sqlite1.conf make watch - MOJO_CONFIG=t/sqlite1.conf make cleanbdd - MOJO_CONFIG=t/sqlite1.conf make cleanfiles - MOJO_CONFIG=t/sqlite1.conf make stats sqlite2: - stage: sqlite - cache: - key: "$CI_BUILD_REF_NAME" - untracked: true - paths: - - local + <<: *sqlite_definition script: - - make podcheck + - carton install --deployment --without=postgresql --without=cache - MOJO_CONFIG=t/sqlite2.conf make minion & - sleep 3 - MOJO_CONFIG=t/sqlite2.conf make test-sqlite @@ -36,18 +96,13 @@ sqlite2: - MOJO_CONFIG=t/sqlite2.conf make cleanfiles - MOJO_CONFIG=t/sqlite2.conf make stats sqlite3: - stage: sqlite - cache: - key: "$CI_BUILD_REF_NAME" - untracked: true - paths: - - local + <<: *sqlite_definition + services: + - name: postgres:9.6 + alias: postgres script: - - make podcheck - - service postgresql restart - - sleep 10 - - service postgresql status - - make create-pg-test-db + - carton install --deployment --without=cache + - export PGPASSWORD=lutim_pwd; echo 'CREATE DATABASE lutim_minion WITH OWNER lutim;' | psql -h postgres -U lutim lutim_db - MOJO_CONFIG=t/sqlite3.conf make minion & - sleep 3 - MOJO_CONFIG=t/sqlite3.conf make test-sqlite @@ -55,40 +110,23 @@ sqlite3: - MOJO_CONFIG=t/sqlite3.conf make cleanbdd - MOJO_CONFIG=t/sqlite3.conf make cleanfiles - MOJO_CONFIG=t/sqlite3.conf make stats - tags: - - Debian - - Jessie + +### PostgreSQL tests +## +# postgresql1: - stage: postgresql - cache: - key: "$CI_BUILD_REF_NAME" - untracked: true - paths: - - local + <<: *pg_definition script: - - make podcheck - - service postgresql restart - - sleep 10 - - service postgresql status - - make create-pg-test-db + - carton install --deployment --without=sqlite --without=minion --without=cache - MOJO_CONFIG=t/postgresql1.conf make test-pg - MOJO_CONFIG=t/postgresql1.conf make watch - MOJO_CONFIG=t/postgresql1.conf make cleanbdd - MOJO_CONFIG=t/postgresql1.conf make cleanfiles - MOJO_CONFIG=t/postgresql1.conf make stats postgresql2: - stage: postgresql - cache: - key: "$CI_BUILD_REF_NAME" - untracked: true - paths: - - local + <<: *pg_definition script: - - make podcheck - - service postgresql restart - - sleep 10 - - service postgresql status - - make create-pg-test-db + - carton install --deployment --without=cache - MOJO_CONFIG=t/postgresql2.conf make minion & - sleep 3 - MOJO_CONFIG=t/postgresql2.conf make test-pg @@ -97,18 +135,10 @@ postgresql2: - MOJO_CONFIG=t/postgresql2.conf make cleanfiles - MOJO_CONFIG=t/postgresql2.conf make stats postgresql3: - stage: postgresql - cache: - key: "$CI_BUILD_REF_NAME" - untracked: true - paths: - - local + <<: *pg_definition script: - - make podcheck - - service postgresql restart - - sleep 10 - - service postgresql status - - make create-pg-test-db + - carton install --deployment --without=sqlite --without=cache + - export PGPASSWORD=lutim_pwd; echo 'CREATE DATABASE lutim_minion WITH OWNER lutim;' | psql -h postgres -U lutim lutim_db - MOJO_CONFIG=t/postgresql3.conf make minion & - sleep 3 - MOJO_CONFIG=t/postgresql3.conf make test-pg @@ -116,6 +146,3 @@ postgresql3: - MOJO_CONFIG=t/postgresql3.conf make cleanbdd - MOJO_CONFIG=t/postgresql3.conf make cleanfiles - MOJO_CONFIG=t/postgresql3.conf make stats - tags: - - Debian - - Jessie diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 58bc4d5..b7f5c25 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -24,7 +24,6 @@ sub startup { $self->{wait_for_it} = {}; $self->plugin('DebugDumperHelper'); - $self->plugin('PgURLHelper'); my $config = $self->plugin('Config', { default => { @@ -106,6 +105,7 @@ sub startup { $self->config('minion')->{db_path} = 'minion.db' unless defined $config->{minion}->{db_path}; $self->plugin('Minion' => { SQLite => 'sqlite:'.$config->{minion}->{db_path} }); } elsif ($config->{minion}->{dbtype} eq 'postgresql') { + $self->plugin('PgURLHelper'); $self->plugin('Minion' => { Pg => $self->pg_url($config->{minion}->{'pgdb'}) }); } $self->app->minion->add_task( diff --git a/lib/Lutim/Plugin/Helpers.pm b/lib/Lutim/Plugin/Helpers.pm index 64f0e52..dbf08a7 100644 --- a/lib/Lutim/Plugin/Helpers.pm +++ b/lib/Lutim/Plugin/Helpers.pm @@ -10,10 +10,10 @@ use DateTime; sub register { my ($self, $app) = @_; - $app->plugin('PgURLHelper'); if ($app->config('dbtype') eq 'postgresql') { require Mojo::Pg; + $app->plugin('PgURLHelper'); $app->helper(pg => \&_pg); # Database migration diff --git a/t/postgresql1.conf b/t/postgresql1.conf index 62f0d1a..7818747 100644 --- a/t/postgresql1.conf +++ b/t/postgresql1.conf @@ -128,10 +128,10 @@ # these are the credentials to access the PostgreSQL database # mandatory if you choosed postgresql as dbtype pgdb => { - database => 'lutimtest', - host => 'localhost', + database => 'lutim_db', + host => 'postgres', user => 'lutim', - pwd => 'lutim' + pwd => 'lutim_pwd' }, # use Minion instead of directly increase counters diff --git a/t/postgresql2.conf b/t/postgresql2.conf index 008d01d..5390bbc 100644 --- a/t/postgresql2.conf +++ b/t/postgresql2.conf @@ -128,10 +128,10 @@ # these are the credentials to access the PostgreSQL database # mandatory if you choosed postgresql as dbtype pgdb => { - database => 'lutimtest', - host => 'localhost', + database => 'lutim_db', + host => 'postgres', user => 'lutim', - pwd => 'lutim' + pwd => 'lutim_pwd' }, # use Minion instead of directly increase counters diff --git a/t/postgresql3.conf b/t/postgresql3.conf index dd81819..1aab7cf 100644 --- a/t/postgresql3.conf +++ b/t/postgresql3.conf @@ -128,10 +128,10 @@ # these are the credentials to access the PostgreSQL database # mandatory if you choosed postgresql as dbtype pgdb => { - database => 'lutimtest', - host => 'localhost', + database => 'lutim_db', + host => 'postgres', user => 'lutim', - pwd => 'lutim' + pwd => 'lutim_pwd' }, # use Minion instead of directly increase counters @@ -152,10 +152,10 @@ # these are the credentials to access the Minion's PostgreSQL database # mandatory if you choosed postgresql as Minion backend, no default pgdb => { - database => 'lutim_miniontest', - host => 'localhost', + database => 'lutim_minion', + host => 'postgres', user => 'lutim', - pwd => 'lutim' + pwd => 'lutim_pwd' } }, diff --git a/t/sqlite3.conf b/t/sqlite3.conf index 65d142a..744e8f2 100644 --- a/t/sqlite3.conf +++ b/t/sqlite3.conf @@ -152,10 +152,10 @@ # these are the credentials to access the Minion's PostgreSQL database # mandatory if you choosed postgresql as Minion backend, no default pgdb => { - database => 'lutim_miniontest', - host => 'localhost', + database => 'lutim_minion', + host => 'postgres', user => 'lutim', - pwd => 'lutim' + pwd => 'lutim_pwd' } },