Skip to content

Commit 651eb05

Browse files
authored
test: extend e2e tests (#38)
## 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.
1 parent 5c586be commit 651eb05

File tree

4 files changed

+130
-1
lines changed

4 files changed

+130
-1
lines changed

DEVELOPMENT.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Development
2+
3+
This document describes the intricacies of sloctl development workflow.
4+
5+
## Makefile
6+
7+
Run `make help` to display short description for each target.
8+
The provided Makefile will automatically install dev dependencies if they're
9+
missing and place them under `bin`
10+
(this does not apply to `yarn` managed dependencies).
11+
However, it does not detect if the binary you have is up to date with the
12+
versions declaration located in Makefile.
13+
If you see any discrepancies between CI and your local runs, remove the
14+
binaries from `bin` and let Makefile reinstall them with the latest version.
15+
16+
## Testing
17+
18+
In addition to standard unit tests, sloctl is tested with
19+
[bats](https://bats-core.readthedocs.io/en/stable/) framework.
20+
Bats is a testing framework for Bash, it provides a simple way to verify
21+
that shell programs behave as expected.
22+
Bats tests are located under `test` directory.
23+
Each test file ends with `.bats` suffix.
24+
In addition to helper test utilities which are part of the framework we also
25+
provide custom helpers which are located in `test/test_helper` directory.
26+
27+
Bats tests are currently divided into 2 categories, end-to-end and unit tests.
28+
The categorization is done through Bats tags. In order to categorize a whole
29+
file as a unit test, add this comment: `# bats file_tags=unit` anywhere in the
30+
file, preferably just below shebang.
31+
32+
The end-to-end tests are only run automatically for releases, be it official
33+
version or pre-release (release candidate).
34+
The tests are executed against the production application.
35+
If you want to run the tests manually against a different environment, you can
36+
run the following command:
37+
38+
```shell
39+
SLOCTL_CLIENT_ID=<client_id> \
40+
SLOCTL_CLIENT_SECRET=<client_secret> \
41+
SLOCTL_OKTA_ORG_URL=https://accounts.nobl9.dev \
42+
SLOCTL_OKTA_AUTH_SERVER=<dev_auth_server> \ # Runs against dev Okta.
43+
make test/e2e
44+
```
45+
46+
Bats tests are fully containerized, refer to Makefile for more details on
47+
how they're executed.
48+
49+
## Releases
50+
51+
We're using [Release Drafter](https://github.com/release-drafter/release-drafter)
52+
to automate release notes creation. Drafter also does its best to propose
53+
the next release version based on commit messages from `main` branch.
54+
55+
Release Drafter is also responsible for auto-labeling of pull requests.
56+
It checks both title and body of pull request and adds appropriate labels. \
57+
**NOTE:** The auto-labeling mechanism will not remove labels once they're
58+
created. For example, If you end up changing PR title from `sec:` to `fix:`
59+
you'll have to manually remove `security` label.
60+
61+
On each commit to `main` branch, Release Drafter will update the next release
62+
draft. Once you're ready to create new version, simply publish the draft.
63+
64+
In addition to Release Drafter, we're also running a script which extracts
65+
explicitly listed release notes and breaking changes which are optionally
66+
defined in `## Release Notes` and `## Breaking Changes` headers.
67+
68+
## Dependencies
69+
70+
Renovate is configured to automatically merge minor and patch updates.
71+
For major versions, which sadly includes GitHub Actions, manual approval
72+
is required.

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ test/bats/unit:
8787

8888
## Run bats unit tests.
8989
test/bats/e2e:
90-
echo "$(SLOCTL_CLIENT_ID)"
9190
$(call _print_step,Running bats e2e tests)
9291
$(call _build_docker,sloctl-e2e-test-bin,$(VERSION),$(BRANCH),$(REVISION))
9392
docker build -t sloctl-bats-e2e -f $(TEST_DIR)/Dockerfile.e2e .
9493
docker run --rm \
9594
-e SLOCTL_CLIENT_ID=$(SLOCTL_CLIENT_ID) \
9695
-e SLOCTL_CLIENT_SECRET=$(SLOCTL_CLIENT_SECRET) \
96+
-e SLOCTL_OKTA_ORG_URL=$(SLOCTL_OKTA_ORG_URL) \
97+
-e SLOCTL_OKTA_AUTH_SERVER=$(SLOCTL_OKTA_AUTH_SERVER) \
9798
-e SLOCTL_GIT_REVISION=$(REVISION) \
9899
sloctl-bats-e2e -F pretty --filter-tags e2e $(TEST_DIR)/*
99100

test/aws-iam-ids.bats

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# bats file_tags=e2e
3+
4+
# setup_file is run only once for the whole file.
5+
setup_file() {
6+
load "test_helper/load"
7+
load_lib "bats-assert"
8+
9+
generate_inputs "$BATS_FILE_TMPDIR"
10+
run_sloctl apply -f "'$TEST_INPUTS/**'"
11+
assert_success
12+
}
13+
14+
# teardown_file is run only once for the whole file.
15+
teardown_file() {
16+
run_sloctl delete -f "'$TEST_INPUTS/**'"
17+
}
18+
19+
# setup is run before each test.
20+
setup() {
21+
load "test_helper/load"
22+
load_lib "bats-support"
23+
load_lib "bats-assert"
24+
}
25+
26+
@test "dataexport" {
27+
run_sloctl aws-iam-ids dataexport
28+
assert_success
29+
assert_output --regexp "[-a-zA-Z0-9]+"
30+
}
31+
32+
@test "direct" {
33+
run_sloctl aws-iam-ids direct splunk-observability-direct
34+
assert_success
35+
assert_output --regexp "externalID: [-a-zA-Z0-9]+\naccountID: \"\d+\""
36+
}

test/inputs/aws-iam-ids/direct.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- apiVersion: n9/v1alpha
2+
kind: Project
3+
metadata:
4+
name: death-star
5+
spec:
6+
description: Dummy Project for 'sloctl aws-iam-ids' e2e tests
7+
- apiVersion: n9/v1alpha
8+
kind: Direct
9+
metadata:
10+
name: splunk-observability-direct
11+
displayName: Splunk Observability direct
12+
project: death-star
13+
spec:
14+
description: This Direct is just for the e2e 'sloctl aws-iam-ids' tests, it's not supposed to work!
15+
sourceOf:
16+
- Metrics
17+
- Services
18+
splunkObservability:
19+
realm: us1
20+
accessToken: super-secret

0 commit comments

Comments
 (0)