mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
chore(tests): use a coverage server binary (#8407)
# Which Problems Are Solved Use a single server instance for API integration tests. This optimizes the time taken for the integration test pipeline, because it allows running tests on multiple packages in parallel. Also, it saves time by not start and stopping a zitadel server for every package. # How the Problems Are Solved - Build a binary with `go build -race -cover ....` - Integration tests only construct clients. The server remains running in the background. - The integration package and tested packages now fully utilize the API. No more direct database access trough `query` and `command` packages. - Use Makefile recipes to setup, start and stop the server in the background. - The binary has the race detector enabled - Init and setup jobs are configured to halt immediately on race condition - Because the server runs in the background, races are only logged. When the server is stopped and race logs exist, the Makefile recipe will throw an error and print the logs. - Makefile recipes include logic to print logs and convert coverage reports after the server is stopped. - Some tests need a downstream HTTP server to make requests, like quota and milestones. A new `integration/sink` package creates an HTTP server and uses websockets to forward HTTP request back to the test packages. The package API uses Go channels for abstraction and easy usage. # Additional Changes - Integration test files already used the `//go:build integration` directive. In order to properly split integration from unit tests, integration test files need to be in a `integration_test` subdirectory of their package. - `UseIsolatedInstance` used to overwrite the `Tester.Client` for each instance. Now a `Instance` object is returned with a gRPC client that is connected to the isolated instance's hostname. - The `Tester` type is now `Instance`. The object is created for the first instance, used by default in any test. Isolated instances are also `Instance` objects and therefore benefit from the same methods and values. The first instance and any other us capable of creating an isolated instance over the system API. - All test packages run in an Isolated instance by calling `NewInstance()` - Individual tests that use an isolated instance use `t.Parallel()` # Additional Context - Closes #6684 - https://go.dev/doc/articles/race_detector - https://go.dev/doc/build-cover --------- Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
207
internal/api/grpc/org/v2/integration_test/org_test.go
Normal file
207
internal/api/grpc/org/v2/integration_test/org_test.go
Normal file
@@ -0,0 +1,207 @@
|
||||
//go:build integration
|
||||
|
||||
package org_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/muhlemmer/gu"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/org/v2"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
CTX, OwnerCTX, UserCTX context.Context
|
||||
Instance *integration.Instance
|
||||
Client org.OrganizationServiceClient
|
||||
User *user.AddHumanUserResponse
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(func() int {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
Instance = integration.NewInstance(ctx)
|
||||
Client = Instance.Client.OrgV2
|
||||
|
||||
CTX = Instance.WithAuthorization(ctx, integration.UserTypeIAMOwner)
|
||||
OwnerCTX = Instance.WithAuthorization(ctx, integration.UserTypeOrgOwner)
|
||||
UserCTX = Instance.WithAuthorization(ctx, integration.UserTypeLogin)
|
||||
User = Instance.CreateHumanUser(CTX)
|
||||
return m.Run()
|
||||
}())
|
||||
}
|
||||
|
||||
func TestServer_AddOrganization(t *testing.T) {
|
||||
idpResp := Instance.AddGenericOAuthProvider(CTX, Instance.DefaultOrg.Id)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
req *org.AddOrganizationRequest
|
||||
want *org.AddOrganizationResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "missing permission",
|
||||
ctx: Instance.WithAuthorization(context.Background(), integration.UserTypeOrgOwner),
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: "name",
|
||||
Admins: nil,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty name",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: "",
|
||||
Admins: nil,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid admin type",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||
Admins: []*org.AddOrganizationRequest_Admin{
|
||||
{},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "admin with init",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||
Admins: []*org.AddOrganizationRequest_Admin{
|
||||
{
|
||||
UserType: &org.AddOrganizationRequest_Admin_Human{
|
||||
Human: &user.AddHumanUserRequest{
|
||||
Profile: &user.SetHumanProfile{
|
||||
GivenName: "firstname",
|
||||
FamilyName: "lastname",
|
||||
},
|
||||
Email: &user.SetHumanEmail{
|
||||
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
||||
Verification: &user.SetHumanEmail_ReturnCode{
|
||||
ReturnCode: &user.ReturnEmailVerificationCode{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &org.AddOrganizationResponse{
|
||||
OrganizationId: integration.NotEmpty,
|
||||
CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{
|
||||
{
|
||||
UserId: integration.NotEmpty,
|
||||
EmailCode: gu.Ptr(integration.NotEmpty),
|
||||
PhoneCode: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "existing user and new human with idp",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||
Admins: []*org.AddOrganizationRequest_Admin{
|
||||
{
|
||||
UserType: &org.AddOrganizationRequest_Admin_UserId{UserId: User.GetUserId()},
|
||||
},
|
||||
{
|
||||
UserType: &org.AddOrganizationRequest_Admin_Human{
|
||||
Human: &user.AddHumanUserRequest{
|
||||
Profile: &user.SetHumanProfile{
|
||||
GivenName: "firstname",
|
||||
FamilyName: "lastname",
|
||||
},
|
||||
Email: &user.SetHumanEmail{
|
||||
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
||||
Verification: &user.SetHumanEmail_IsVerified{
|
||||
IsVerified: true,
|
||||
},
|
||||
},
|
||||
IdpLinks: []*user.IDPLink{
|
||||
{
|
||||
IdpId: idpResp.Id,
|
||||
UserId: "userID",
|
||||
UserName: "username",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
want: &org.AddOrganizationResponse{
|
||||
CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{
|
||||
// a single admin is expected, because the first provided already exists
|
||||
{
|
||||
UserId: integration.NotEmpty,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := Client.AddOrganization(tt.ctx, tt.req)
|
||||
if tt.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// check details
|
||||
assert.NotZero(t, got.GetDetails().GetSequence())
|
||||
gotCD := got.GetDetails().GetChangeDate().AsTime()
|
||||
now := time.Now()
|
||||
assert.WithinRange(t, gotCD, now.Add(-time.Minute), now.Add(time.Minute))
|
||||
assert.NotEmpty(t, got.GetDetails().GetResourceOwner())
|
||||
|
||||
// organization id must be the same as the resourceOwner
|
||||
assert.Equal(t, got.GetDetails().GetResourceOwner(), got.GetOrganizationId())
|
||||
|
||||
// check the admins
|
||||
require.Len(t, got.GetCreatedAdmins(), len(tt.want.GetCreatedAdmins()))
|
||||
for i, admin := range tt.want.GetCreatedAdmins() {
|
||||
gotAdmin := got.GetCreatedAdmins()[i]
|
||||
assertCreatedAdmin(t, admin, gotAdmin)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func assertCreatedAdmin(t *testing.T, expected, got *org.AddOrganizationResponse_CreatedAdmin) {
|
||||
if expected.GetUserId() != "" {
|
||||
assert.NotEmpty(t, got.GetUserId())
|
||||
} else {
|
||||
assert.Empty(t, got.GetUserId())
|
||||
}
|
||||
if expected.GetEmailCode() != "" {
|
||||
assert.NotEmpty(t, got.GetEmailCode())
|
||||
} else {
|
||||
assert.Empty(t, got.GetEmailCode())
|
||||
}
|
||||
if expected.GetPhoneCode() != "" {
|
||||
assert.NotEmpty(t, got.GetPhoneCode())
|
||||
} else {
|
||||
assert.Empty(t, got.GetPhoneCode())
|
||||
}
|
||||
}
|
443
internal/api/grpc/org/v2/integration_test/query_test.go
Normal file
443
internal/api/grpc/org/v2/integration_test/query_test.go
Normal file
@@ -0,0 +1,443 @@
|
||||
//go:build integration
|
||||
|
||||
package org_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/org/v2"
|
||||
)
|
||||
|
||||
type orgAttr struct {
|
||||
ID string
|
||||
Name string
|
||||
Details *object.Details
|
||||
}
|
||||
|
||||
func TestServer_ListOrganizations(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req *org.ListOrganizationsRequest
|
||||
dep func(ctx context.Context, request *org.ListOrganizationsRequest) ([]orgAttr, error)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *org.ListOrganizationsResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "list org by id, ok, multiple",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationIdQuery(Instance.DefaultOrg.Id),
|
||||
},
|
||||
},
|
||||
func(ctx context.Context, request *org.ListOrganizationsRequest) ([]orgAttr, error) {
|
||||
count := 3
|
||||
orgs := make([]orgAttr, count)
|
||||
prefix := fmt.Sprintf("ListOrgs%d", time.Now().UnixNano())
|
||||
for i := 0; i < count; i++ {
|
||||
name := prefix + strconv.Itoa(i)
|
||||
orgResp := Instance.CreateOrganization(ctx, name, fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()))
|
||||
orgs[i] = orgAttr{
|
||||
ID: orgResp.GetOrganizationId(),
|
||||
Name: name,
|
||||
Details: orgResp.GetDetails(),
|
||||
}
|
||||
}
|
||||
request.Queries = []*org.SearchQuery{
|
||||
OrganizationNamePrefixQuery(prefix),
|
||||
}
|
||||
return orgs, nil
|
||||
},
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 3,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
},
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
},
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by id, ok",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationIdQuery(Instance.DefaultOrg.Id),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
Name: Instance.DefaultOrg.Name,
|
||||
Details: &object.Details{
|
||||
Sequence: Instance.DefaultOrg.Details.Sequence,
|
||||
ChangeDate: Instance.DefaultOrg.Details.ChangeDate,
|
||||
ResourceOwner: Instance.DefaultOrg.Details.ResourceOwner,
|
||||
},
|
||||
Id: Instance.DefaultOrg.Id,
|
||||
PrimaryDomain: Instance.DefaultOrg.PrimaryDomain,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by name, ok",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationNameQuery(Instance.DefaultOrg.Name),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
Name: Instance.DefaultOrg.Name,
|
||||
Details: &object.Details{
|
||||
Sequence: Instance.DefaultOrg.Details.Sequence,
|
||||
ChangeDate: Instance.DefaultOrg.Details.ChangeDate,
|
||||
ResourceOwner: Instance.DefaultOrg.Details.ResourceOwner,
|
||||
},
|
||||
Id: Instance.DefaultOrg.Id,
|
||||
PrimaryDomain: Instance.DefaultOrg.PrimaryDomain,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by domain, ok",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationDomainQuery(Instance.DefaultOrg.PrimaryDomain),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
Name: Instance.DefaultOrg.Name,
|
||||
Details: &object.Details{
|
||||
Sequence: Instance.DefaultOrg.Details.Sequence,
|
||||
ChangeDate: Instance.DefaultOrg.Details.ChangeDate,
|
||||
ResourceOwner: Instance.DefaultOrg.Details.ResourceOwner,
|
||||
},
|
||||
Id: Instance.DefaultOrg.Id,
|
||||
PrimaryDomain: Instance.DefaultOrg.PrimaryDomain,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by inactive state, ok",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{},
|
||||
},
|
||||
func(ctx context.Context, request *org.ListOrganizationsRequest) ([]orgAttr, error) {
|
||||
name := gofakeit.Name()
|
||||
orgResp := Instance.CreateOrganization(ctx, name, gofakeit.Email())
|
||||
deactivateOrgResp := Instance.DeactivateOrganization(ctx, orgResp.GetOrganizationId())
|
||||
request.Queries = []*org.SearchQuery{
|
||||
OrganizationIdQuery(orgResp.GetOrganizationId()),
|
||||
OrganizationStateQuery(org.OrganizationState_ORGANIZATION_STATE_INACTIVE),
|
||||
}
|
||||
return []orgAttr{{
|
||||
ID: orgResp.GetOrganizationId(),
|
||||
Name: name,
|
||||
Details: &object.Details{
|
||||
ResourceOwner: deactivateOrgResp.GetDetails().GetResourceOwner(),
|
||||
Sequence: deactivateOrgResp.GetDetails().GetSequence(),
|
||||
ChangeDate: deactivateOrgResp.GetDetails().GetChangeDate(),
|
||||
},
|
||||
}}, nil
|
||||
},
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_INACTIVE,
|
||||
Details: &object.Details{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by domain, ok, sorted",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationDomainQuery(Instance.DefaultOrg.PrimaryDomain),
|
||||
},
|
||||
SortingColumn: org.OrganizationFieldName_ORGANIZATION_FIELD_NAME_NAME,
|
||||
},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 1,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
Name: Instance.DefaultOrg.Name,
|
||||
Details: &object.Details{
|
||||
Sequence: Instance.DefaultOrg.Details.Sequence,
|
||||
ChangeDate: Instance.DefaultOrg.Details.ChangeDate,
|
||||
ResourceOwner: Instance.DefaultOrg.Details.ResourceOwner,
|
||||
},
|
||||
Id: Instance.DefaultOrg.Id,
|
||||
PrimaryDomain: Instance.DefaultOrg.PrimaryDomain,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org, no result",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationDomainQuery("notexisting"),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 0,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org, no login",
|
||||
args: args{
|
||||
context.Background(),
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationDomainQuery("nopermission"),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "list org, no permission",
|
||||
args: args{
|
||||
UserCTX,
|
||||
&org.ListOrganizationsRequest{},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 0,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 1,
|
||||
Result: []*org.Organization{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org, no permission org owner",
|
||||
args: args{
|
||||
OwnerCTX,
|
||||
&org.ListOrganizationsRequest{
|
||||
Queries: []*org.SearchQuery{
|
||||
OrganizationDomainQuery("nopermission"),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 0,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 1,
|
||||
Result: []*org.Organization{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org, org owner",
|
||||
args: args{
|
||||
OwnerCTX,
|
||||
&org.ListOrganizationsRequest{},
|
||||
nil,
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 1,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
Name: Instance.DefaultOrg.Name,
|
||||
Details: &object.Details{
|
||||
Sequence: Instance.DefaultOrg.Details.Sequence,
|
||||
ChangeDate: Instance.DefaultOrg.Details.ChangeDate,
|
||||
ResourceOwner: Instance.DefaultOrg.Details.ResourceOwner,
|
||||
},
|
||||
Id: Instance.DefaultOrg.Id,
|
||||
PrimaryDomain: Instance.DefaultOrg.PrimaryDomain,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.dep != nil {
|
||||
orgs, err := tt.args.dep(tt.args.ctx, tt.args.req)
|
||||
require.NoError(t, err)
|
||||
if len(orgs) > 0 {
|
||||
for i, org := range orgs {
|
||||
tt.want.Result[i].Name = org.Name
|
||||
tt.want.Result[i].Id = org.ID
|
||||
tt.want.Result[i].Details = org.Details
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retryDuration := time.Minute
|
||||
if ctxDeadline, ok := CTX.Deadline(); ok {
|
||||
retryDuration = time.Until(ctxDeadline)
|
||||
}
|
||||
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
||||
got, listErr := Client.ListOrganizations(tt.args.ctx, tt.args.req)
|
||||
assertErr := assert.NoError
|
||||
if tt.wantErr {
|
||||
assertErr = assert.Error
|
||||
}
|
||||
assertErr(ttt, listErr)
|
||||
if listErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// totalResult is unrelated to the tests here so gets carried over, can vary from the count of results due to permissions
|
||||
tt.want.Details.TotalResult = got.Details.TotalResult
|
||||
// always first check length, otherwise its failed anyway
|
||||
assert.Len(ttt, got.Result, len(tt.want.Result))
|
||||
|
||||
for i := range tt.want.Result {
|
||||
// domain from result, as it is generated though the create
|
||||
tt.want.Result[i].PrimaryDomain = got.Result[i].PrimaryDomain
|
||||
// sequence from result, as it can be with different sequence from create
|
||||
tt.want.Result[i].Details.Sequence = got.Result[i].Details.Sequence
|
||||
}
|
||||
|
||||
for i := range tt.want.Result {
|
||||
assert.Contains(ttt, got.Result, tt.want.Result[i])
|
||||
}
|
||||
integration.AssertListDetails(t, tt.want, got)
|
||||
}, retryDuration, time.Millisecond*100, "timeout waiting for expected user result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func OrganizationIdQuery(resourceowner string) *org.SearchQuery {
|
||||
return &org.SearchQuery{Query: &org.SearchQuery_IdQuery{
|
||||
IdQuery: &org.OrganizationIDQuery{
|
||||
Id: resourceowner,
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
func OrganizationNameQuery(name string) *org.SearchQuery {
|
||||
return &org.SearchQuery{Query: &org.SearchQuery_NameQuery{
|
||||
NameQuery: &org.OrganizationNameQuery{
|
||||
Name: name,
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
func OrganizationNamePrefixQuery(name string) *org.SearchQuery {
|
||||
return &org.SearchQuery{Query: &org.SearchQuery_NameQuery{
|
||||
NameQuery: &org.OrganizationNameQuery{
|
||||
Name: name,
|
||||
Method: object.TextQueryMethod_TEXT_QUERY_METHOD_STARTS_WITH,
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
func OrganizationDomainQuery(domain string) *org.SearchQuery {
|
||||
return &org.SearchQuery{Query: &org.SearchQuery_DomainQuery{
|
||||
DomainQuery: &org.OrganizationDomainQuery{
|
||||
Domain: domain,
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
func OrganizationStateQuery(state org.OrganizationState) *org.SearchQuery {
|
||||
return &org.SearchQuery{Query: &org.SearchQuery_StateQuery{
|
||||
StateQuery: &org.OrganizationStateQuery{
|
||||
State: state,
|
||||
},
|
||||
}}
|
||||
}
|
Reference in New Issue
Block a user