Files
grafana/pkg/tests/apis/features/features_test.go
Charandas 16f5eab786 MTFF: Allow viewers access in cloud (#114607)
* Reapply "K8s: read resource configs from API Enablement for API Builders" (#114475)

This reverts commit 4130bd9cd3.

* revert part that broke things

* FF service changes are gonna come later

* MTFF: allow viewers access to MTFF by enforcing runtime_config for custom routes

* unused var

* removed now

* pass the test, include defaults

* revert sample.ini change
2025-12-08 17:37:10 -08:00

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":"enabled"}`, string(rsp.Body))
})
}