Git Product home page Git Product logo

Comments (5)

endorama avatar endorama commented on September 7, 2024 2

Moving here some discussion I had with @girodav and @aspacca on how to improve the situation.

  1. Tests share setup code by inheriting from the same base class. This makes hard to distinguish which setup code is used for which test. By extracting functionalities from this single setup function we can then leverage composition over inheritance to split the single setup in multiple setups with shared logic.
  2. Writing helper functions that do not leverage a global state (i.e. _mock_awsclient) but get state through function arguments. This would allow to reuse the same logic by changing the underlying actors.
  3. Leverage subTest to group test with same setup code (helps with (1) too)
  4. Leverage testcontainers-py library to wrap test containers we need to use (localstack, elasticsearch, logstash). This library provides an easier to use API and allows for moving bootstrap code for related services out of tests files/setup functions.
  5. Implement file fixture loading through some conventions, to load test and config data from files instead of writing them in variables. This helps reusing the same data.
  6. Add suite setup code to bootstrap shared underlying testing infrastructure (i.e. localstack). To implement this all test need to make sure to use only resources created by them (i.e. S3 buckets) and not affect shared resources. By using type(self).__name__ is possible to use the class name as part of related resources name to achieve this.

from elastic-serverless-forwarder.

aspacca avatar aspacca commented on September 7, 2024

6. Add suite setup code to bootstrap shared underlying testing infrastructure (i.e. localstack). To implement this all test need to make sure to use only resources created by them (i.e. S3 buckets) and not affect shared resources. By using type(self).__name__ is possible to use the class name as part of related resources name to achieve this.

can you clarify on this?

from elastic-serverless-forwarder.

aspacca avatar aspacca commented on September 7, 2024

3. Leverage subTest to group test with same setup code (helps with (1) too)

do you mean replacing current test_lambda_handler_continuing/test_lambda_handler_replay with subTest instead?
I'd rather go the other way and remove subTest everywhere where possible, or in case replace with https://pypi.org/project/pytest-subtests/

from elastic-serverless-forwarder.

aspacca avatar aspacca commented on September 7, 2024

2. Writing helper functions that do not leverage a global state (i.e. _mock_awsclient) but get state through function arguments. This would allow to reuse the same logic by changing the underlying actors.

can you expand on this?
for _mock_awsclient we have both cases: global state storage.S3Storage._s3_client, but that's basically only that. the othercases are wrapping aws client getter helper functions (handlers.aws.handler.get_sqs_client, handlers.aws.utils.get_sqs_client, handlers.aws.utils.get_cloudwatch_logs_client, etc etc)

are you referring to this or to something else? :)

from elastic-serverless-forwarder.

aspacca avatar aspacca commented on September 7, 2024

closed by #260

from elastic-serverless-forwarder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.