Skip to content

Commit

Permalink
tls integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Skye Gill <[email protected]>
  • Loading branch information
skyerus committed Feb 9, 2023
1 parent 41ed0d1 commit 51c0d49
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ build:
test:
go test -cover -short ./...
integration-test: # dependent on: docker run -p 8013:8013 -v $PWD/test-harness/testing-flags.json:/testing-flags.json ghcr.io/open-feature/flagd:latest start -f file:/testing-flags.json
go test -cover ./...
cd test-harness; git restore testing-flags.json; cd .. # reset testing-flags.json
go test -cover ./tests/integration $(ARGS)
cd test-harness; git restore testing-flags.json # reset testing-flags.json
run:
go run main.go start -f file:config/samples/example_flags.json
install:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/golang/mock v1.6.0
github.com/mattn/go-colorable v0.1.13
github.com/open-feature/go-sdk-contrib/providers/flagd v0.1.2
github.com/open-feature/go-sdk-contrib/tests/flagd v1.0.1
github.com/open-feature/open-feature-operator v0.2.28
github.com/open-feature/schemas v0.2.8
Expand Down Expand Up @@ -80,7 +81,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/open-feature/go-sdk v1.1.0 // indirect
github.com/open-feature/go-sdk-contrib/providers/flagd v0.1.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
34 changes: 31 additions & 3 deletions tests/integration/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
#### Integration tests
# Integration tests

The continuous integration runs a set of [gherkin integration tests](https://github.com/open-feature/test-harness/blob/main/features).
If you'd like to run them locally, first pull the `test-harness` git submodule
```
git submodule update --init --recursive
```
then build the flagd binary
then build the `flagd` binary
```
make build
```
then run the flagd binary
then run the `flagd` binary
```
./flagd start -f file:test-harness/testing-flags.json
```
and finally run
```
make integration-test
```

## TLS

To run the integration tests against a `flagd` instance configured to use TLS, do the following:

Generate a cert and key in the repository root
```
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
```
build the `flagd` binary
```
make build
```
then run the `flagd` binary with tls configuration
```
./flagd start -f file:test-harness/testing-flags.json -c ./localhost.crt -k ./localhost.key
```
finally, either run the tests with an explicit path to the certificate:
```
make ARGS="-tls true -cert-path ./../../localhost.crt" integration-test
```
or, run without the path, defaulting to the host's root certificate authorities set (for this to work, the certificate must be registered and trusted in the host's system certificates)
```
make ARGS="-tls true" integration-test
```
20 changes: 16 additions & 4 deletions tests/integration/caching_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package integration_test

import (
"flag"
"testing"

flagd "github.com/open-feature/go-sdk-contrib/providers/flagd/pkg"
"github.com/open-feature/go-sdk-contrib/tests/flagd/pkg/integration"

"github.com/cucumber/godog"
Expand All @@ -15,13 +17,23 @@ func TestCaching(t *testing.T) {
t.Skip()
}

initializeCachingScenario, err := integration.InitializeCachingScenario(flagConfigurationPath)
flag.Parse()

var providerOptions []flagd.ProviderOption
name := "caching.feature"

if tls == "true" {
name = "caching_tls.feature"
providerOptions = []flagd.ProviderOption{flagd.WithTLS(certPath)}
}

initializeCachingScenario, err := integration.InitializeCachingScenario(flagConfigurationPath, providerOptions...)
if err != nil {
t.Fatal(err)
}

suite := godog.TestSuite{
Name: "caching.feature",
testSuite := godog.TestSuite{
Name: name,
ScenarioInitializer: initializeCachingScenario,
Options: &godog.Options{
Format: "pretty",
Expand All @@ -30,7 +42,7 @@ func TestCaching(t *testing.T) {
},
}

if suite.Run() != 0 {
if testSuite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run caching tests")
}
}
21 changes: 17 additions & 4 deletions tests/integration/evaluation_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package integration_test

import (
"flag"
"testing"

flagd "github.com/open-feature/go-sdk-contrib/providers/flagd/pkg"

"github.com/cucumber/godog"
"github.com/open-feature/go-sdk-contrib/tests/flagd/pkg/integration"
)
Expand All @@ -12,17 +15,27 @@ func TestEvaluation(t *testing.T) {
t.Skip()
}

suite := godog.TestSuite{
Name: "evaluation.feature",
ScenarioInitializer: integration.InitializeEvaluationScenario,
flag.Parse()

var providerOptions []flagd.ProviderOption
name := "evaluation.feature"

if tls == "true" {
name = "evaluation_tls.feature"
providerOptions = []flagd.ProviderOption{flagd.WithTLS(certPath)}
}

testSuite := godog.TestSuite{
Name: name,
ScenarioInitializer: integration.InitializeEvaluationScenario(providerOptions...),
Options: &godog.Options{
Format: "pretty",
Paths: []string{"../../test-harness/features/evaluation.feature"},
TestingT: t, // Testing instance that will run subtests.
},
}

if suite.Run() != 0 {
if testSuite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run evaluation tests")
}
}
13 changes: 13 additions & 0 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package integration_test

import "flag"

var (
tls string
certPath string
)

func init() {
flag.StringVar(&tls, "tls", "false", "tls enabled for testing")
flag.StringVar(&certPath, "cert-path", "", "path to cert to use in tls tests")
}

0 comments on commit 51c0d49

Please sign in to comment.