postgres-operator icon indicating copy to clipboard operation
postgres-operator copied to clipboard

full test coverage

Open hitman99 opened this issue 5 years ago • 6 comments

Currently there are no tests of any kind for the operator code, this issue addresses that. Test coverage should be at least 80% Just unit tests are fine as integration tests might be a bit tricky to do.

hitman99 avatar Jan 03 '20 07:01 hitman99

I've been thinking about this as well. This will be a bit tricky as most of our business logic depends on a database being there and is PostgreSQL specific.

Do you have any plan of attack?

arnarg avatar Jan 03 '20 10:01 arnarg

For operator controller(s) logic, we could use mocked PG package, which we could generate. As for the actual Postgres package, we'd have to use integration tests, running tests in docker-compose where we could use real postgres database, in a container. Another and probably easier option would be to use github actions as it supports services (like Gitlab CI Services), where we could configure something like this for integration tests:

jobs:
    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
        - 5432:5432
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

Which oiption do you prefer? This will not be easy as for some queries we'd need to write more queries in tests to check if it worked or not.

hitman99 avatar Jan 03 '20 11:01 hitman99

Obvious first step would be to unit test the controllers' logic. There's even documentation on this from operator-sdk.

I'm fine with either option of integration tests. The github actions sounds really nice but we'd probably also need a way of running them locally.

arnarg avatar Jan 03 '20 20:01 arnarg

Yes, agree on the unit tests to be first. I have written them for my other operator, it's pretty straight forward: https://github.com/movetokube/do-operator/tree/master/pkg/controller/dns

As for integration tests, there's always an option to run them locally with docker compose, I'll look into it.

On Fri, Jan 3, 2020, 22:39 Arnar [email protected] wrote:

Obvious first step would be to unit test the controllers' logic. There's even documentation on this from operator-sdk https://github.com/operator-framework/operator-sdk/blob/master/doc/user/unit-testing.md .

I'm fine with either option of integration tests. The github actions sounds really nice but we'd probably also need a way of running them locally.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/movetokube/postgres-operator/issues/31?email_source=notifications&email_token=AAG5PQKTQ4LBYME6TDGUZXDQ36O7TA5CNFSM4KCKKRLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEICBAQI#issuecomment-570691649, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG5PQP6FORTHETYFD22WXLQ36O7TANCNFSM4KCKKRLA .

hitman99 avatar Jan 03 '20 20:01 hitman99

I'm splitting this issue in two as it's quite big. One will be for unit and another for integration tests

hitman99 avatar Jan 04 '20 18:01 hitman99

All work for this issue to be tracked in #32 and #33.

hitman99 avatar Jan 04 '20 18:01 hitman99