diff --git a/Makefile b/Makefile index 32c4f7910..353217a8d 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/go.mod b/go.mod index cc8ed7bc4..f7e4ac82d 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/tests/integration/README.md b/tests/integration/README.md index d357fc8e3..3a7069552 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -1,15 +1,15 @@ -#### 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 ``` @@ -17,3 +17,31 @@ 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 +``` diff --git a/tests/integration/caching_test.go b/tests/integration/caching_test.go index 0ea92bc1f..e843ad354 100644 --- a/tests/integration/caching_test.go +++ b/tests/integration/caching_test.go @@ -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" @@ -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", @@ -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") } } diff --git a/tests/integration/evaluation_test.go b/tests/integration/evaluation_test.go index 5decb94db..1fad17346 100644 --- a/tests/integration/evaluation_test.go +++ b/tests/integration/evaluation_test.go @@ -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" ) @@ -12,9 +15,19 @@ 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"}, @@ -22,7 +35,7 @@ func TestEvaluation(t *testing.T) { }, } - if suite.Run() != 0 { + if testSuite.Run() != 0 { t.Fatal("non-zero status returned, failed to run evaluation tests") } } diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go new file mode 100644 index 000000000..22b89c5eb --- /dev/null +++ b/tests/integration/integration_test.go @@ -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") +}