Skip to content

Commit 15d20b1

Browse files
chore(ci): Add BDD Test framework (#2640)
### Proposed Changes * Introduces BDD Testing Framework ### Checklist - [ ] I have added or updated unit tests - [ ] I have added or updated integration tests (if appropriate) - [ ] I have added or updated documentation ### Testing Instructions --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent e775e14 commit 15d20b1

24 files changed

+3228
-73
lines changed

.github/scripts/init-temp-keys.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,19 @@ openssl req -new -nodes -newkey rsa:2048 -keyout keys/sampleuser.key -out keys/s
6060
openssl x509 -req -in keys/sampleuser.req -CA keys/keycloak-ca.pem -CAkey keys/keycloak-ca-private.pem -CAcreateserial -out keys/sampleuser.crt -days 3650
6161

6262
openssl pkcs12 -export -in keys/keycloak-ca.pem -inkey keys/keycloak-ca-private.pem -out keys/ca.p12 -nodes -passout pass:password
63+
64+
# Use JAVA_OPTS_APPEND if set, otherwise default based on architecture
65+
# For Apple Silicon: export JAVA_OPTS_APPEND="-XX:UseSVE=0" before running this script
66+
if [ -n "$JAVA_OPTS_APPEND" ]; then
67+
JAVA_ENV_OPTS="-e JAVA_TOOL_OPTIONS=$JAVA_OPTS_APPEND"
68+
elif [ "$(uname -m)" = "arm64" ]; then
69+
JAVA_ENV_OPTS="-e JAVA_TOOL_OPTIONS=-XX:UseSVE=0"
70+
else
71+
JAVA_ENV_OPTS=""
72+
fi
73+
6374
docker run \
75+
$JAVA_ENV_OPTS \
6476
-v $(pwd)/keys:/keys \
6577
--entrypoint keytool \
6678
--user $(id -u):$(id -g) \

.github/workflows/checks.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
- lib/fixtures
4040
- lib/flattening
4141
- lib/identifier
42+
- tests-bdd
4243
steps:
4344
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.4.2
4445
with:
@@ -53,6 +54,7 @@ jobs:
5354
protocol/go/go.sum
5455
sdk/go.sum
5556
service/go.sum
57+
tests-bdd/go.sum
5658
- if: env.IS_RELEASE_BRANCH == 'true'
5759
name: prevent depending on unreleased upstream changes
5860
run: ./.github/scripts/work-init.sh
@@ -393,6 +395,64 @@ jobs:
393395
focus-sdk: go
394396
# use commit instead of ref so we can "go get" specific sdk version
395397
platform-ref: ${{ github.event.pull_request.head.sha || github.sha }} lts
398+
399+
tests-bdd:
400+
name: Cucumber BDD Tests
401+
runs-on: ubuntu-22.04
402+
strategy:
403+
fail-fast: false
404+
permissions:
405+
id-token: write
406+
contents: read
407+
steps:
408+
- name: Install Dependencies
409+
run: |
410+
sudo apt-get update
411+
# Remove containerd if present to prevent conflict
412+
sudo apt-get remove -y containerd containerd.io || true
413+
sudo apt-get install -y curl docker.io docker-compose-v2 lsof coreutils libnss3-tools
414+
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
415+
chmod +x mkcert-v*-linux-amd64
416+
sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert
417+
418+
- name: "Checkout"
419+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.4.2
420+
with:
421+
persist-credentials: false
422+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
423+
with:
424+
go-version-file: ./tests-bdd/go.mod
425+
cache: false
426+
427+
- name: Build local platform-cukes image for testing
428+
run: docker build -t platform-cukes .
429+
430+
- name: Run BDD Tests
431+
run: |
432+
CUKES_LOG_HANDLER=console go test ./tests-bdd -v --tags=cukes --godog.random --godog.format="cucumber:$(pwd)/cukes_platform_report.json,pretty:$(pwd)/cukes_platform_report.log,pretty" ./features
433+
434+
- name: Check for undefined steps
435+
run: |
436+
if grep -qi "Undefined" cukes_platform_report.log; then
437+
echo "❌ Undefined steps found in BDD tests!"
438+
exit 1
439+
fi
440+
441+
- name: Get logs on failure
442+
if: failure() || cancelled()
443+
run: |
444+
echo "********** Cukes Platform Compose log **********"
445+
cat cukes_platform_compose.log
446+
echo "********** Docker logs **********"
447+
docker ps -aq | xargs -L 1 docker logs
448+
- uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
449+
if: ${{ !cancelled() }}
450+
with:
451+
name: cukes-report
452+
path: |
453+
cukes_platform_report.json
454+
cukes_platform_report.log
455+
retention-days: 1
396456

397457
# test latest otdfctl CLI 'main' against platform PR branch
398458
otdfctl-test:
@@ -467,6 +527,7 @@ jobs:
467527
- benchmark
468528
- license
469529
- platform-xtest
530+
- tests-bdd
470531
- otdfctl-test
471532
runs-on: ubuntu-22.04
472533
if: ${{ !cancelled() }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ keys/
4747
/examples/sensitive.txt.ntdf
4848
sensitive.txt.ntdf
4949
traces/
50+
51+
# Cucumber / BDD log files
52+
*.log

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ COPY sdk/ sdk/
88
COPY lib/ lib/
99
COPY service/ service/
1010
COPY examples/ examples/
11+
COPY tests-bdd/ tests-bdd/
1112
COPY go.work ./
1213
RUN cd service \
1314
&& go mod download \

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ brew install buf go golangci-lint
3838
#### Optional tools
3939

4040
- _Optional_ [Air](https://github.com/cosmtrek/air) is used for hot-reload development
41-
- install with `go install github.com/cosmtrek/air@latest`
41+
- install with `go install github.com/air-verse/air@latest`
4242
- _Optional_ [grpcurl](https://github.com/fullstorydev/grpcurl) is used for testing gRPC services
4343
- install with `brew install grpcurl`
4444
- _Optional_ [openssl](https://www.openssl.org/) is used for generating certificates
@@ -52,7 +52,7 @@ There are two primary audiences for this project. Consumers and Contributors
5252
Consumers of the OpenTDF platform should begin their journey [here](./docs/Consuming.md).
5353

5454
2. Contributing
55-
To contribute to the OpenTDF platform, you'll need bit more set setup and should start [here](./docs/Contributing.md).
55+
To contribute to the OpenTDF platform, you'll need a bit more setup and should start [here](./docs/Contributing.md).
5656

5757
## Additional info for Project Consumers & Contributors
5858

@@ -76,24 +76,23 @@ https://github.com/opentdf/platform/blob/main/service/go.mod#L3
7676

7777
Generate development keys/certs for the platform infrastructure.
7878

79+
> **Note for Apple M4 chip users:**
80+
> If you are running on an Apple M4 chip, set the Java environment variable before running any commands:
81+
> ```sh
82+
> export JAVA_OPTS_APPEND="-XX:UseSVE=0"
83+
> ```
84+
> This resolves SIGILL with Code 134 errors when running Java processes.
85+
7986
```sh
8087
./.github/scripts/init-temp-keys.sh
8188
```
8289
8390
Start the required infrastructure with [compose-spec](https://compose-spec.io).
8491

8592
```sh
86-
# If you are on an M4 chip (Apple Silicon), use the provided script to ensure the correct Java environment:
87-
./run-compose.sh -f docker-compose.yaml up
88-
89-
# Otherwise, use docker compose directly:
9093
docker compose -f docker-compose.yaml up
9194
```
9295

93-
> **Note:**
94-
> The `run-compose.sh` script is required on Apple Silicon (M1/M2/M3/M4) Macs to ensure the correct Java environment is used for containers that require x86_64 Java images.
95-
> This is necessary because some images (such as Keycloak) may not have ARM-compatible builds, and the script sets up emulation as needed.
96-
9796
Copy the development configuration file from the example and update it with your own values (if necessary, not common).
9897

9998
```sh
@@ -137,7 +136,7 @@ platform. The SDKs contain a native Go SDK and generated Go service SDKs. A full
137136

138137
### How To Add a New Go Module
139138

140-
Within this repo, todefine a new, distinct [go module](https://go.dev/ref/mod),
139+
Within this repo, to define a new, distinct [go module](https://go.dev/ref/mod),
141140
for example to provide shared functionality between several existing modules,
142141
or to define new and unique functionality
143142
follow these steps.
@@ -198,7 +197,7 @@ COPY lib/foo/ lib/foo/
198197

199198
#### Updating the Workflow Files
200199

201-
1. Add your new `go.mod` directory to the `.github/workflows/checks.yaml`'s `go` job's `matrix.strategry.directory` line.
200+
1. Add your new `go.mod` directory to the `.github/workflows/checks.yaml`'s `go` job's `strategy.matrix.directory` line.
202201
2. Add the module to the `license` job in the `checks` workflow as well, especially if you declare _any_ dependencies.
203202
3. Do the same for any other workflows that should be running on your folder, such as `vuln-check` and `lint`.
204203

docker-compose.yaml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ networks:
44
services:
55
keycloak:
66
volumes:
7-
- ./keys/localhost.crt:/etc/x509/tls/localhost.crt
8-
- ./keys/localhost.key:/etc/x509/tls/localhost.key
9-
- ./keys/ca.jks:/truststore/truststore.jks
7+
- ${KEYS_DIR:-./keys}/localhost.crt:/etc/x509/tls/localhost.crt
8+
- ${KEYS_DIR:-./keys}/localhost.key:/etc/x509/tls/localhost.key
9+
- ${KEYS_DIR:-./keys}/ca.jks:/truststore/truststore.jks
1010
image: keycloak/keycloak:25.0
1111
restart: always
1212
command:
@@ -43,17 +43,23 @@ services:
4343
KC_HTTPS_CERTIFICATE_KEY_FILE: "/etc/x509/tls/localhost.key"
4444
KC_HTTPS_CLIENT_AUTH: "request"
4545
###
46-
# If you are running on a M4 chip use the run-compose.sh script to start the containers
47-
# The EXTRA_JAVA_OPTS variable allows users to pass additional Java options and is used by the run-compose.sh script
48-
# to set the JAVA_OPTS_APPEND environment variable in the Keycloak container
49-
JAVA_OPTS_APPEND: "${EXTRA_JAVA_OPTS}"
50-
# OR comment the above line and uncomment the JAVA_OPTS_APPEND line below
51-
# JAVA_OPTS_APPEND: "-XX:UseSVE=0" # Uncommenting resolves SIGILL with Code 134 when running on a machine with an M4 chip: https://github.com/keycloak/keycloak/issues/36008
46+
# The following environment variable resolves SIGILL with Code 134 when running Java processes on Apple M4 chips
47+
#
48+
# On Apple Silicon (M4 chip):
49+
# export JAVA_OPTS_APPEND="-XX:UseSVE=0"
50+
# docker-compose up
51+
#
52+
# On other architectures:
53+
# export JAVA_OPTS_APPEND=""
54+
# docker-compose up
55+
#
56+
# Or set directly: JAVA_OPTS_APPEND="-XX:UseSVE=0" docker-compose up
57+
JAVA_OPTS_APPEND: "${JAVA_OPTS_APPEND:-}"
5258
###
5359
ports:
54-
- "9001:9001"
55-
- "8888:8888"
56-
- "8443:8443"
60+
- "${KC_EXPOSE_PORT:-8443}:8443"
61+
- "${KC_EXPOSE_PORT_HTTP:-8888}:8888"
62+
- "${KC_EXPOSE_PORT_MGMT:-9001}:9001"
5763
healthcheck:
5864
test:
5965
- CMD-SHELL
@@ -73,7 +79,7 @@ services:
7379
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)new java.net.URL(args[0]).openConnection();
7480
System.exit(java.net.HttpURLConnection.HTTP_OK == conn.getResponseCode() ? 0 : 1);
7581
}
76-
}" > /tmp/HealthCheck.java && java /tmp/HealthCheck.java https://localhost:9001/auth/health/live
82+
}" > /tmp/HealthCheck.java && java ${JAVA_OPTS_APPEND} /tmp/HealthCheck.java https://localhost:9001/auth/health/live
7783
timeout: 10s
7884
retries: 3
7985
start_period: 2m
@@ -91,7 +97,7 @@ services:
9197
timeout: 5s
9298
retries: 10
9399
ports:
94-
- "5432:5432"
100+
- "${POSTGRES_EXPOSE_PORT:-5432}:5432"
95101

96102
jaeger:
97103
image: jaegertracing/all-in-one:latest

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ use (
1111
./protocol/go
1212
./sdk
1313
./service
14+
./tests-bdd
1415
)

run-compose.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

service/cmd/provisionKeycloak.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ const (
2222
provKcInsecure = "insecure"
2323
)
2424

25-
var (
26-
provKeycloakFilename = "./service/cmd/keycloak_data.yaml"
27-
keycloakData fixtures.KeycloakData
28-
)
25+
var provKeycloakFilename = "./service/cmd/keycloak_data.yaml"
2926

3027
var provisionKeycloakCmd = &cobra.Command{
3128
Use: "keycloak",
3229
Short: "Run local provision of keycloak data",
3330
Long: `
3431
** Local Development and Testing Only **
35-
This command will create the following Keyclaok resource:
32+
This command will create the following Keycloak resource:
3633
- Realm
3734
- Roles
3835
- Client
@@ -46,7 +43,7 @@ var provisionKeycloakCmd = &cobra.Command{
4643
kcPassword, _ := cmd.Flags().GetString(provKcPasswordFlag)
4744
keycloakFilename, _ := cmd.Flags().GetString(provKcFilenameFlag)
4845

49-
LoadKeycloakData(keycloakFilename)
46+
keycloakData := LoadKeycloakData(keycloakFilename)
5047
ctx := context.Background()
5148

5249
kcParams := fixtures.KeycloakConnectParams{
@@ -94,7 +91,7 @@ func convert(i interface{}) interface{} {
9491
return i
9592
}
9693

97-
func LoadKeycloakData(file string) {
94+
func LoadKeycloakData(file string) fixtures.KeycloakData {
9895
yamlData := make(map[interface{}]interface{})
9996

10097
f, err := os.Open(file)
@@ -118,11 +115,12 @@ func LoadKeycloakData(file string) {
118115
if err != nil {
119116
panic(fmt.Errorf("error converting yaml to json: %s", err.Error()))
120117
}
121-
118+
var keycloakData fixtures.KeycloakData
122119
if err := json.Unmarshal(kcData, &keycloakData); err != nil {
123120
slog.Error("could not unmarshal json into data object", slog.String("error", err.Error()))
124121
panic(err)
125122
}
123+
return keycloakData
126124
}
127125

128126
func init() {

0 commit comments

Comments
 (0)