2024-04-09 17:21:21 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package action_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/muhlemmer/gu"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2024-08-12 20:32:01 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/feature/v2"
|
2024-04-09 17:21:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-08-12 20:32:01 +00:00
|
|
|
IAMOwnerCTX, SystemCTX context.Context
|
|
|
|
Tester *integration.Tester
|
2024-04-09 17:21:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(func() int {
|
2024-08-12 20:32:01 +00:00
|
|
|
ctx, _, cancel := integration.Contexts(5 * time.Minute)
|
2024-04-09 17:21:21 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
Tester = integration.NewTester(ctx)
|
|
|
|
defer Tester.Done()
|
|
|
|
|
2024-08-12 20:32:01 +00:00
|
|
|
IAMOwnerCTX = Tester.WithAuthorization(ctx, integration.IAMOwner)
|
|
|
|
SystemCTX = Tester.WithAuthorization(ctx, integration.SystemUser)
|
|
|
|
|
2024-04-09 17:21:21 +00:00
|
|
|
return m.Run()
|
|
|
|
}())
|
|
|
|
}
|
|
|
|
|
2024-08-12 20:32:01 +00:00
|
|
|
func ensureFeatureEnabled(t *testing.T, iamOwnerCTX context.Context) {
|
|
|
|
f, err := Tester.Client.FeatureV2.GetInstanceFeatures(iamOwnerCTX, &feature.GetInstanceFeaturesRequest{
|
2024-04-09 17:21:21 +00:00
|
|
|
Inheritance: true,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
if f.Actions.GetEnabled() {
|
|
|
|
return
|
|
|
|
}
|
2024-08-12 20:32:01 +00:00
|
|
|
_, err = Tester.Client.FeatureV2.SetInstanceFeatures(iamOwnerCTX, &feature.SetInstanceFeaturesRequest{
|
2024-04-09 17:21:21 +00:00
|
|
|
Actions: gu.Ptr(true),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
retryDuration := time.Minute
|
2024-08-12 20:32:01 +00:00
|
|
|
if ctxDeadline, ok := iamOwnerCTX.Deadline(); ok {
|
2024-04-09 17:21:21 +00:00
|
|
|
retryDuration = time.Until(ctxDeadline)
|
|
|
|
}
|
|
|
|
require.EventuallyWithT(t,
|
|
|
|
func(ttt *assert.CollectT) {
|
2024-08-12 20:32:01 +00:00
|
|
|
f, err := Tester.Client.FeatureV2.GetInstanceFeatures(iamOwnerCTX, &feature.GetInstanceFeaturesRequest{
|
2024-04-09 17:21:21 +00:00
|
|
|
Inheritance: true,
|
|
|
|
})
|
|
|
|
require.NoError(ttt, err)
|
|
|
|
if f.Actions.GetEnabled() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
},
|
|
|
|
retryDuration,
|
|
|
|
100*time.Millisecond,
|
|
|
|
"timed out waiting for ensuring instance feature")
|
|
|
|
}
|