github.com/redhat-appstudio/e2e-tests@v0.0.0-20230619105049-9a422b2094d7/README.md (about) 1 # Red Hat AppStudio E2E Tests and Testing Framework 2 3 Testing framework and E2E tests are written in [Go](https://go.dev/) using [Ginkgo](https://onsi.github.io/ginkgo/) and [Gomega](https://onsi.github.io/gomega/) frameworks to cover Red Hat AppStudio. 4 It is recommended to install AppStudio in E2E mode, but the E2E suite can be also usable in [development and preview modes](https://github.com/redhat-appstudio/infra-deployments#preview-mode-for-your-clusters). 5 6 # Features 7 8 * Instrumented tests with Ginkgo 2.0 framework. You can find more information in [Ginkgo documentation](https://onsi.github.io/ginkgo/). 9 * Uses client-go to connect to OpenShift Cluster. 10 * Ability to run the E2E tests everywhere: locally([CRC/OpenShift local](https://developers.redhat.com/products/openshift-local/overview)), OpenShift Cluster, OSD... 11 * Writes tests results in JUnit XML/JSON file to a custom directory by using `--ginkgo.junit(or json)-report` flag. 12 * Ability to run the test suites separately. 13 14 # Running the tests 15 When you want to run the E2E tests for AppStudio you need to have installed tools(in Requirements chapter), installed the AppStudio in E2E mode and compiled `e2e-appstudio` binary. 16 17 ## Requirements 18 Requirements for installing AppStudio in E2E mode and running the E2E tests: 19 20 * An OpenShift 4.11 or higher Environment (If you are using CRC/OpenShift Local please also review [optional-codeready-containers-post-bootstrap-configuration](https://github.com/redhat-appstudio/infra-deployments#optional-codeready-containers-post-bootstrap-configuration)) 21 * A machine from which to run the install (usually your laptop) with required tools: 22 * A properly setup Go workspace using **Go 1.19 is required** 23 * The OpenShift Command Line Tool (oc) **Use the version coresponding to the Openshift version** 24 * yq 25 * jq 26 * git 27 * helm 28 * Tokens 29 * Github Token with the following permissions 30 * `repo` 31 * `delete_repo` 32 * Valid quay token where to push AppStudio components images generated by the e2e framework 33 34 ## Install AppStudio in E2E mode 35 36 Before executing the e2e suites you need to have deployed AppStudio in E2E Mode to your cluster. 37 38 1. Before deploying AppStudio in E2E mode you need to login to your OpenShift cluster with OpenShift Command Line Tool as `admin` (by default `kubeadmin`): 39 40 ```bash 41 oc login -u <user> -p <password> --server=<oc_api_url> 42 ``` 43 44 2. Export required (and recommended) environment variables (i.e. `export ENV_VAR_NAME=value ENV_VAR2_NAME=value`) from the table below. 45 46 The following environment variables are used to launch the Red Hat AppStudio installation in E2E mode and the tests execution (tokens are also used for running the tests): 47 48 | Variable | Required | Explanation | Default Value | 49 |---|---|---|---| 50 | `GITHUB_TOKEN` | yes | A github token used to create AppStudio applications in github | '' | 51 | `QUAY_TOKEN` | yes | A quay token to push components images to quay.io. Note the quay token must be your dockerconfigjson encoded in base64 format. Example: `export QUAY_TOKEN=$(base64 < ~/.docker/config.json)` | '' | 52 | `DEFAULT_QUAY_ORG` | yes | A quay organization where repositories for component images will be created | 'redhat-appstudio-qe' | 53 | `DEFAULT_QUAY_ORG_TOKEN` | yes | A quay token of OAuth application for `DEFAULT_QUAY_ORG` with scopes - Administer organizations, Adminster repositories, Create Repositories | '' | 54 | `MY_GITHUB_ORG` | no (recommended) | GitHub organization (must be organization, cannot use regular GitHub account!) where to create/push Red Hat AppStudio Applications. You can create your GitHub organization for free | `redhat-appstudio-qe` | 55 | `QUAY_E2E_ORGANIZATION` | no (recommended) | Quay organization/account where to push components containers. It is recommended to create your own account | `redhat-appstudio-qe` | 56 | `E2E_APPLICATIONS_NAMESPACE` | no | Name of the namespace used for running build-templates E2E tests | '' | 57 | `PRIVATE_DEVFILE_SAMPLE` | no | The name of the private git repository used in HAS E2E tests. Your GITHUB_TOKEN should be able to read from it. | `https://github.com/redhat-appstudio-qe/private-quarkus-devfile-sample` | 58 | `QUAY_OAUTH_USER` | no | A valid quay robot account username to make quay oauth | '' | 59 | `QUAY_OAUTH_TOKEN` | no | A valid quay quay robot account token to make oauth against quay.io. | '' | 60 | `DOCKER_IO_AUTH` | no | A valid docker.io token to avoid pull limits in the format: username:access_token, eg. `export DOCKER_IO_AUTH=susdas:43228532-b374-11ec-989b-98fa9b70b97d` | '' | 61 | `INFRA_DEPLOYMENTS_ORG` | no | A specific github organization from where to download infra-deployments repository | `redhat-appstudio` | 62 | `INFRA_DEPLOYMENTS_BRANCH` | no | A valid infra-deployments branch. | `main` | 63 | `E2E_TEST_SUITE_LABEL` | no | Run only test suites with the given Giknkgo label | '' | 64 | `KLOG_VERBOSITY` | no | Level of verbosity for `klog` | 1 | 65 | `IMAGE_TAG_EXPIRATION` | no | Expiration for tags created by pull-request pipelineruns, format: digits + `h` (hours), `d` (days) or `w` (weeks), e. g. `5d` | `6h` | 66 67 1. Install dependencies: 68 69 ``` bash 70 # Install dependencies 71 $ go mod tidy 72 # or go mod tidy -compat=1.19 73 # Copy the dependencies to vendor folder 74 $ go mod vendor 75 ``` 76 77 1. Install Red Hat AppStudio in e2e mode. By default the installation script will use the `redhat-appstudio-qe` GitHub organization for pushing changes to `infra-deployments` repository. 78 79 **It is recommended to use your fork of [infra-deployments repo](https://github.com/redhat-appstudio/infra-deployments) in your GitHub org instead** - you can change the GitHub organization with environment variable `export MY_GITHUB_ORG=<name-of-your-github-org>`. 80 81 ```bash 82 make local/cluster/prepare 83 ``` 84 85 More information about how to deploy Red Hat AppStudio 86 are in the [infra-deployments](https://github.com/redhat-appstudio/infra-deployments) repository. 87 88 ## Building and running the e2e tests 89 You can use the following make target to build and run the tests: 90 ```bash 91 make local/test/e2e 92 ``` 93 94 Or build and run the tests without scripts: 95 1. Install dependencies and build the tests: 96 97 ``` bash 98 # Install dependencies 99 $ go mod tidy 100 # Copy the dependencies to vendor folder 101 $ go mod vendor 102 # Create `e2e-appstudio` binary in bin folder. Please add the binary to the path or just execute `./bin/e2e-appstudio` 103 $ make build 104 ``` 105 106 2. Run the e2e tests: 107 The `e2e-appstudio` command is the root command that executes all test functionality. To obtain all available flags for the binary please use `--help` flags. All ginkgo flags and go tests are available in `e2e-appstudio` binary. 108 109 Some tests could require you to have specific container image repo's created (if you're using your own container image org/user account (`QUAY_E2E_ORGANIZATION`) or your own GitHub organization (`MY_GITHUB_ORG`) 110 In that case, before you run the test, make sure you have created 111 * `test-images` repo in quay.io, i.e. `quay.io/<QUAY_E2E_ORGANIZATION>/test-images` and make it **public** 112 * also make sure that the docker config, that is encoded in the value of `QUAY_TOKEN` environment variable, contains a correct credentials required to push to `test-images` repo. And make sure the robot account or user account has the **write** permissions set for `test-images` repo which is required by the tests to push the generated artifacts. 113 * forked following GitHub repositories to your org (specified in `MY_GITHUB_ORG` env var) 114 * https://github.com/redhat-appstudio-qe/devfile-sample-hello-world (for running build-service tests) 115 * https://github.com/redhat-appstudio-qe/hacbs-test-project (for mvp-demo test) 116 * https://github.com/redhat-appstudio-qe/strategy-configs (for mvp-demo test) 117 118 ```bash 119 `./bin/e2e-appstudio` 120 ``` 121 122 The instructions for every test suite can be found in the [tests folder](tests), e.g. [has Readme.md](tests/has/README.md). 123 You can also specify which tests you want to run using [labels](docs/LabelsNaming.md) or [Ginkgo Focus](docs/DeveloperFocus.md). 124 125 # Red Hat AppStudio Load Tests 126 127 Load tests for AppStudio are also in this repository. More information about load tests are in [LoadTests.md](docs/LoadTests.md). 128 129 # Running Red Hat AppStudio Tests in OpenShift CI 130 131 Overview for OpenShift CI and AppStudio E2E tests is in [OpenshiftCI.md](docs/OpenShiftCI.md). How to install E2E binary is in [Installation.md](docs/Installation.md). 132 133 # Develop new tests 134 135 The current structure of how tests are stored in this repo are as follows: 136 137 * The equivalent of Ginkgo Suites, `*_suite_test.go`, reside in the `cmd/` directory 138 * The equivalent of Ginkgo Tests, `*_test.go`, reside in the `tests/` directory 139 140 We've provided some tooling to generate test suite packages and test spec files to get you up and running a little faster: 141 142 ```bash 143 make local/template/generate-test-spec 144 make local/template/generate-test-suite 145 ``` 146 147 For more information refer to [Generate Tests](docs/DeveloperGenerateTest.md). 148 149 ## Tips 150 * Make sure you've implemented any required controller functionality that is required for your tests within the following files 151 * `pkg/utils/<new controller directory>` - net new controller logic for a new service or component 152 * `pkg/framework/framework.go` - import the new controller and update the `Framework` struct to be able to initialize the new controller 153 * Every test package should be imported to `cmd/e2e_test.go`, e.g. [has](https://github.com/redhat-appstudio/e2e-tests/blob/main/cmd/e2e_test.go#L15). 154 * Every new test should have correct [labels](docs/LabelsNaming.md). 155 * Every test should have meaningful description with JIRA/GitHub issue key. 156 * (Recommended) Use JIRA integration for linking issues and commits (just add JIRA issue key in the commit message). 157 * When running via mage you can filter the suites run by specifying the 158 `E2E_TEST_SUITE_LABEL` environment variable. For example: 159 `E2E_TEST_SUITE_LABEL=ec ./mage runE2ETests` 160 * `klog` level can be controled via `KLOG_VERBOSITY` environment variable. For 161 example: `KLOG_VERBOSITY=9 ./mage runE2ETests` would output `curl` commands 162 issued via Kubernetes client from sigs.k8s.io/controller-runtime 163 164 ```golang 165 // cmd/e2e_test.go 166 package common 167 168 import ( 169 // ensure these packages are scanned by ginkgo for e2e tests 170 _ "github.com/redhat-appstudio/e2e-tests/tests/common" 171 _ "github.com/redhat-appstudio/e2e-tests/tests/has" 172 ) 173 ``` 174 175 # Troubleshooting e2e-tests issues in openshift-ci 176 The whole process of investigating issues is defined in [InvestigatingCIFailures](docs/InvestigatingCIFailures.md). 177 178 # Reporting issues 179 Please follow the process in [Reporting and escalating CI Issue](docs/InvestigatingCIFailures.md#reporting-and-escalating-ci-issue) for reporting issues. 180 181 # Debugging tests 182 ## In vscode 183 There is launch configuration in `.vscode/launch.json` called `Launch demo suites`. 184 Running this configuration, you'll be asked for github token and then e2e-demos suite will run with default configuration. 185 If you want to run/debug different suite, change `-ginkgo.focus` parameter in `.vscode/launch.json`. 186 187 # Cleanup of redhat-appstudio-qe org 188 189 Our automated tests running in CI create lot of repositories in our redhat-appstudio-qe github org. 190 191 There is a mage target that can cleanup those repositories - `mage local:cleanupGithubOrg`. 192 193 For more infor & usage, please run `mage -h local:cleanupGithubOrg`.