Skip to content

Commit

Permalink
test: extend e2e tests (#38)
Browse files Browse the repository at this point in the history
## Motivation

Extended e2e tests coverage with `sloctl aws-iam-ids` command.

## Summary

Added `DEVELOPMENT.md` which should answer some of the questions in
regards to the development workflow.
  • Loading branch information
nieomylnieja authored Jan 31, 2024
1 parent 5c586be commit 651eb05
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 1 deletion.
72 changes: 72 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Development

This document describes the intricacies of sloctl development workflow.

## Makefile

Run `make help` to display short description for each target.
The provided Makefile will automatically install dev dependencies if they're
missing and place them under `bin`
(this does not apply to `yarn` managed dependencies).
However, it does not detect if the binary you have is up to date with the
versions declaration located in Makefile.
If you see any discrepancies between CI and your local runs, remove the
binaries from `bin` and let Makefile reinstall them with the latest version.

## Testing

In addition to standard unit tests, sloctl is tested with
[bats](https://bats-core.readthedocs.io/en/stable/) framework.
Bats is a testing framework for Bash, it provides a simple way to verify
that shell programs behave as expected.
Bats tests are located under `test` directory.
Each test file ends with `.bats` suffix.
In addition to helper test utilities which are part of the framework we also
provide custom helpers which are located in `test/test_helper` directory.

Bats tests are currently divided into 2 categories, end-to-end and unit tests.
The categorization is done through Bats tags. In order to categorize a whole
file as a unit test, add this comment: `# bats file_tags=unit` anywhere in the
file, preferably just below shebang.

The end-to-end tests are only run automatically for releases, be it official
version or pre-release (release candidate).
The tests are executed against the production application.
If you want to run the tests manually against a different environment, you can
run the following command:

```shell
SLOCTL_CLIENT_ID=<client_id> \
SLOCTL_CLIENT_SECRET=<client_secret> \
SLOCTL_OKTA_ORG_URL=https://accounts.nobl9.dev \
SLOCTL_OKTA_AUTH_SERVER=<dev_auth_server> \ # Runs against dev Okta.
make test/e2e
```

Bats tests are fully containerized, refer to Makefile for more details on
how they're executed.

## Releases

We're using [Release Drafter](https://github.com/release-drafter/release-drafter)
to automate release notes creation. Drafter also does its best to propose
the next release version based on commit messages from `main` branch.

Release Drafter is also responsible for auto-labeling of pull requests.
It checks both title and body of pull request and adds appropriate labels. \
**NOTE:** The auto-labeling mechanism will not remove labels once they're
created. For example, If you end up changing PR title from `sec:` to `fix:`
you'll have to manually remove `security` label.

On each commit to `main` branch, Release Drafter will update the next release
draft. Once you're ready to create new version, simply publish the draft.

In addition to Release Drafter, we're also running a script which extracts
explicitly listed release notes and breaking changes which are optionally
defined in `## Release Notes` and `## Breaking Changes` headers.

## Dependencies

Renovate is configured to automatically merge minor and patch updates.
For major versions, which sadly includes GitHub Actions, manual approval
is required.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ test/bats/unit:

## Run bats unit tests.
test/bats/e2e:
echo "$(SLOCTL_CLIENT_ID)"
$(call _print_step,Running bats e2e tests)
$(call _build_docker,sloctl-e2e-test-bin,$(VERSION),$(BRANCH),$(REVISION))
docker build -t sloctl-bats-e2e -f $(TEST_DIR)/Dockerfile.e2e .
docker run --rm \
-e SLOCTL_CLIENT_ID=$(SLOCTL_CLIENT_ID) \
-e SLOCTL_CLIENT_SECRET=$(SLOCTL_CLIENT_SECRET) \
-e SLOCTL_OKTA_ORG_URL=$(SLOCTL_OKTA_ORG_URL) \
-e SLOCTL_OKTA_AUTH_SERVER=$(SLOCTL_OKTA_AUTH_SERVER) \
-e SLOCTL_GIT_REVISION=$(REVISION) \
sloctl-bats-e2e -F pretty --filter-tags e2e $(TEST_DIR)/*

Expand Down
36 changes: 36 additions & 0 deletions test/aws-iam-ids.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# bats file_tags=e2e

# setup_file is run only once for the whole file.
setup_file() {
load "test_helper/load"
load_lib "bats-assert"

generate_inputs "$BATS_FILE_TMPDIR"
run_sloctl apply -f "'$TEST_INPUTS/**'"
assert_success
}

# teardown_file is run only once for the whole file.
teardown_file() {
run_sloctl delete -f "'$TEST_INPUTS/**'"
}

# setup is run before each test.
setup() {
load "test_helper/load"
load_lib "bats-support"
load_lib "bats-assert"
}

@test "dataexport" {
run_sloctl aws-iam-ids dataexport
assert_success
assert_output --regexp "[-a-zA-Z0-9]+"
}

@test "direct" {
run_sloctl aws-iam-ids direct splunk-observability-direct
assert_success
assert_output --regexp "externalID: [-a-zA-Z0-9]+\naccountID: \"\d+\""
}
20 changes: 20 additions & 0 deletions test/inputs/aws-iam-ids/direct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- apiVersion: n9/v1alpha
kind: Project
metadata:
name: death-star
spec:
description: Dummy Project for 'sloctl aws-iam-ids' e2e tests
- apiVersion: n9/v1alpha
kind: Direct
metadata:
name: splunk-observability-direct
displayName: Splunk Observability direct
project: death-star
spec:
description: This Direct is just for the e2e 'sloctl aws-iam-ids' tests, it's not supposed to work!
sourceOf:
- Metrics
- Services
splunkObservability:
realm: us1
accessToken: super-secret

0 comments on commit 651eb05

Please sign in to comment.