Skip to content

Commit

Permalink
feat!: remove gherkin, add events support
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Aug 29, 2023
1 parent bd13458 commit dfe5244
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 171 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
node_modules
node_modules
flags/changing-flag.json
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM ghcr.io/open-feature/flagd:v0.5.2
FROM ghcr.io/open-feature/flagd:v0.6.3 as flagd

COPY testing-flags.json testing-flags.json
FROM busybox:1.36

COPY --from=flagd /flagd-build /flagd
COPY flags/* .
COPY wrapper.sh .
LABEL org.opencontainers.image.source = "https://github.com/open-feature/test-harness"

ENTRYPOINT ["/flagd", "start", "-f", "file:testing-flags.json"]
ENTRYPOINT ["sh", "wrapper.sh"]
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# OpenFeature Test Harness

This repository contains the makings of an end-to-end test suite for OpenFeature SDKs.
This repository contains a docker image to support the [gherkin suites](https://github.com/open-feature/spec/blob/main/specification/appendix-b-gherkin-suites.md) in the OpenFeature specification.

## flagd-testbed container

The _flagd-testbed_ container is a docker image built on flagd, which essentially just adds a simple set of flags for the purposes of testing OpenFeature SDKs.

## Gherkin test suite

The test suite is a set of [_gherkin_](https://cucumber.io/docs/gherkin/) tests that define expected behavior associated with the flags defined in the flagd-testbed. Combined with the _flagd-provider_ for that SDK and the flagd-testbed, these comprise a complete end-to-end tests suite.

### Lint Gherkin files

The Gherkin files structure can be linted using [gherkin-lint](https://github.com/vsiakka/gherkin-lint). The following commands require Node.js 10 or later.

1. npm install
1. npm run gherkin-lint
`testing-flags.json` contains a set of flags consistent with the [evaluation feature](https://github.com/open-feature/spec/blob/main/specification/assets/gherkin/evaluation.feature).
`change-flag.sh` runs in the test container generates a file `changing-flag.json`, which contains a flag that changes once every seconds, allowing to easily test change events.
88 changes: 0 additions & 88 deletions features/caching.feature

This file was deleted.

67 changes: 0 additions & 67 deletions features/evaluation.feature

This file was deleted.

15 changes: 15 additions & 0 deletions flags/change-flag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# this simple script toggles a flag value for a easy way of testing events
cat ./changing-flag-foo.json > ./changing-flag.json

while true
do
sleep 1
cat ./changing-flag-foo.json > ./changing-flag.json
echo 'updated flag changing-flag value to "foo"'

sleep 1
cat ./changing-flag-bar.json > ./changing-flag.json
echo 'updated flag changing-flag value to "bar"'
done
12 changes: 12 additions & 0 deletions flags/changing-flag-bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"flags": {
"changing-flag": {
"state": "ENABLED",
"variants": {
"foo": "foo",
"bar": "bar"
},
"defaultVariant": "bar"
}
}
}
12 changes: 12 additions & 0 deletions flags/changing-flag-foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"flags": {
"changing-flag": {
"state": "ENABLED",
"variants": {
"foo": "foo",
"bar": "bar"
},
"defaultVariant": "foo"
}
}
}
File renamed without changes.
22 changes: 22 additions & 0 deletions wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# wrapper script to start change-flag.sh and flagd, and forward signals to the child process

# handle SIGINTs and SIGTERMs so we can kill the container
handle_term() {
kill -TERM "$child" 2>/dev/null
}

handle_int() {
kill -INT "$child" 2>/dev/null
}

trap handle_term SIGTERM
trap handle_int SIGINT

# start change scriptm and flagd
sh ./change-flag.sh &
./flagd start -f 'file:testing-flags.json' -f 'file:changing-flag.json' &

# wait on flagd
child=$!
wait "$child"

0 comments on commit dfe5244

Please sign in to comment.