2023-11-22 09:29:38 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package admin_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-12-05 11:12:01 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-11-22 09:29:38 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2024-02-28 10:21:11 +00:00
|
|
|
admin_pb "github.com/zitadel/zitadel/pkg/grpc/admin"
|
2023-11-22 09:29:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-09-06 12:47:57 +00:00
|
|
|
CTX, AdminCTX context.Context
|
|
|
|
Instance *integration.Instance
|
|
|
|
Client admin_pb.AdminServiceClient
|
2023-11-22 09:29:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(func() int {
|
2024-09-06 12:47:57 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
2023-11-22 09:29:38 +00:00
|
|
|
defer cancel()
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
Instance = integration.NewInstance(ctx)
|
2024-02-28 10:21:11 +00:00
|
|
|
CTX = ctx
|
2024-09-06 12:47:57 +00:00
|
|
|
AdminCTX = Instance.WithAuthorization(ctx, integration.UserTypeIAMOwner)
|
|
|
|
Client = Instance.Client.Admin
|
2023-11-22 09:29:38 +00:00
|
|
|
return m.Run()
|
|
|
|
}())
|
|
|
|
}
|
2023-12-05 11:12:01 +00:00
|
|
|
|
2023-12-07 08:43:23 +00:00
|
|
|
func await(t *testing.T, ctx context.Context, cb func(*assert.CollectT)) {
|
2023-12-05 11:12:01 +00:00
|
|
|
deadline, ok := ctx.Deadline()
|
|
|
|
require.True(t, ok, "context must have deadline")
|
2023-12-07 08:43:23 +00:00
|
|
|
require.EventuallyWithT(
|
2023-12-05 11:12:01 +00:00
|
|
|
t,
|
2023-12-07 08:43:23 +00:00
|
|
|
func(tt *assert.CollectT) {
|
2023-12-05 11:12:01 +00:00
|
|
|
defer func() {
|
|
|
|
// Panics are not recovered and don't mark the test as failed, so we need to do that ourselves
|
|
|
|
require.Nil(t, recover(), "panic in await callback")
|
|
|
|
}()
|
2023-12-07 08:43:23 +00:00
|
|
|
cb(tt)
|
2023-12-05 11:12:01 +00:00
|
|
|
},
|
|
|
|
time.Until(deadline),
|
2024-09-06 12:47:57 +00:00
|
|
|
time.Second,
|
2023-12-05 11:12:01 +00:00
|
|
|
"awaiting successful callback failed",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ assert.TestingT = (*noopAssertionT)(nil)
|
|
|
|
|
|
|
|
type noopAssertionT struct{}
|
|
|
|
|
|
|
|
func (*noopAssertionT) FailNow() {}
|
|
|
|
|
|
|
|
func (*noopAssertionT) Errorf(string, ...interface{}) {}
|