Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove gherkin, add events support #51

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

busybox because we need some basic tools and a shell.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. Final image is ~60MB


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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script just swaps the value of the flag in changing-flag.json once a second.


# 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.
1 change: 0 additions & 1 deletion symlink_testing-flags.json

This file was deleted.

22 changes: 22 additions & 0 deletions wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this little wrapper script to start our flags/change-flag.sh script in the background, and to forward signals to flagd so we can gracefully shut down.

# 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 script and flagd
sh ./change-flag.sh &
./flagd start -f 'file:testing-flags.json' -f 'file:changing-flag.json' &

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