ce9ab6a89a
* initial commit * add support of integerts * finialise the static provider * minor refactoring * the rest * revert: the rest * add new thiongs * more tests added * add ff parsing tests to check if types are handled correctly * update tests according to recent changes * address golint issues * Update pkg/setting/setting_feature_toggles.go Co-authored-by: Dave Henderson <dave.henderson@grafana.com> * fix rebase issues * addressing review comments * add test cases for enterprise * handle enterprise cases * minor refactoring to make api a bit easier to debug * make test names a bit more precise * fix linter * add openfeature sdk to goleak ignore in testutil * Remove only boolean check in ff gen tests * add non-boolean types top the doc in default.ini and doc string in FeatureFlag type * apply remarks, add docs to sample.ini * reflect changes in feature flags in the public grafana configuration doc * fix doc formatting * apply suggestions to the doc file --------- Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package features
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/tests/apis"
|
|
"github.com/grafana/grafana/pkg/tests/testinfra"
|
|
"github.com/grafana/grafana/pkg/tests/testsuite"
|
|
"github.com/grafana/grafana/pkg/util/testutil"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
testsuite.Run(m)
|
|
}
|
|
|
|
func TestIntegrationFeatures(t *testing.T) {
|
|
testutil.SkipIntegrationTestInShortMode(t)
|
|
|
|
// Enable a random flag -- check that it is reported as enabled
|
|
flag := featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs
|
|
// the test below tests using enable_api = true, without that, the runtime_config has been instructed to skip the API
|
|
helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
|
|
OpenFeatureAPIEnabled: true,
|
|
AppModeProduction: true,
|
|
DisableAnonymous: false, // allow anon user
|
|
EnableFeatureToggles: []string{
|
|
flag, // used in test below
|
|
},
|
|
})
|
|
|
|
t.Run("Test evaluate flags", func(t *testing.T) {
|
|
rsp := apis.DoRequest(helper, apis.RequestParams{
|
|
Method: http.MethodPost,
|
|
Path: "/apis/features.grafana.app/v0alpha1/namespaces/default/ofrep/v1/evaluate/flags/" + flag,
|
|
User: helper.Org1.Admin,
|
|
}, &map[string]any{})
|
|
|
|
require.Equal(t, 200, rsp.Response.StatusCode)
|
|
require.JSONEq(t, `{
|
|
"value": true,
|
|
"key":"`+flag+`",
|
|
"reason":"static provider evaluation result",
|
|
"variant":"default"}`, string(rsp.Body))
|
|
})
|
|
}
|