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-02-28 10:21:11 +00:00
|
|
|
CTX, AdminCTX, SystemCTX context.Context
|
|
|
|
Tester *integration.Tester
|
|
|
|
Client admin_pb.AdminServiceClient
|
2023-11-22 09:29:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(func() int {
|
|
|
|
ctx, _, cancel := integration.Contexts(3 * time.Minute)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
Tester = integration.NewTester(ctx)
|
|
|
|
defer Tester.Done()
|
|
|
|
|
2024-02-28 10:21:11 +00:00
|
|
|
CTX = ctx
|
2023-11-22 09:29:38 +00:00
|
|
|
AdminCTX = Tester.WithAuthorization(ctx, integration.IAMOwner)
|
|
|
|
SystemCTX = Tester.WithAuthorization(ctx, integration.SystemUser)
|
2024-02-28 10:21:11 +00:00
|
|
|
Client = Tester.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),
|
|
|
|
100*time.Millisecond,
|
|
|
|
"awaiting successful callback failed",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ assert.TestingT = (*noopAssertionT)(nil)
|
|
|
|
|
|
|
|
type noopAssertionT struct{}
|
|
|
|
|
|
|
|
func (*noopAssertionT) FailNow() {}
|
|
|
|
|
|
|
|
func (*noopAssertionT) Errorf(string, ...interface{}) {}
|