datarootsio / terraform-aws-ecs-airflow

A terraform module that creates an airflow instance in AWS ECS.
MIT License
58 stars 40 forks source link

Refactor Terratests #26

Open nicogelders opened 3 years ago

nicogelders commented 3 years ago

Right now the Terratests are a bit of a mess so I would like to refactor them by creating some basic methods that you can easily chain together to test the full setup.

The methods I suggest right now are:

All these methods (except for TerraformApplyAndDestroy) make sure that airflow is deployed in a usable state and that you for example didn't mess up something in the configuration of airflow.

An example test would look like this (pseudo code):

func TestAirflowWithRBAC(){
   options = {
        "airflow_authentication": "rbac"
   }

    TerraformApplyAndDestroy(t, options)
    AssertContainersAreRunning("my-test-cluster", ["airflow-webserver", "airflow-scheduler"])
    AssertAirflowWebserverIsReachable("http://airflow.test")
    AirflowLogin("admin", "admin", "http://airflow.test") // only needed when rbac is enabled
    AssertAirflowLoggedIn("http://airflow.test")  // only needed when rbac is enabled
    AirflowAddDag("path/to/dag.py", "s3-bucket-name", "s3/path/key/dag.py", "http://airflow.test")
    AssertAirflowDagExists("name_of_dag", "http://airflow.test")
    AirflowRunDag("name_of_dag", "http://airflow.test")
    AssertAirflowDagHasSucceeded("name_of_dag", "http://airflow.test")
}