2023-10-25 19:20:12 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package system_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2024-04-03 10:43:43 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
2023-10-25 19:20:12 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/instance"
|
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/object"
|
|
|
|
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_ListInstances(t *testing.T) {
|
2024-09-06 12:47:57 +00:00
|
|
|
isoInstance := integration.NewInstance(CTX)
|
2023-10-25 19:20:12 +00:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
req *system_pb.ListInstancesRequest
|
|
|
|
want []*instance.Instance
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty query error",
|
|
|
|
req: &system_pb.ListInstancesRequest{
|
|
|
|
Queries: []*instance.Query{{}},
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "non-existing id",
|
|
|
|
req: &system_pb.ListInstancesRequest{
|
|
|
|
Queries: []*instance.Query{{
|
|
|
|
Query: &instance.Query_IdQuery{
|
|
|
|
IdQuery: &instance.IdsQuery{
|
|
|
|
Ids: []string{"foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []*instance.Instance{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get 1 by id",
|
|
|
|
req: &system_pb.ListInstancesRequest{
|
|
|
|
Query: &object.ListQuery{
|
|
|
|
Limit: 1,
|
|
|
|
},
|
|
|
|
Queries: []*instance.Query{{
|
|
|
|
Query: &instance.Query_IdQuery{
|
|
|
|
IdQuery: &instance.IdsQuery{
|
2024-09-06 12:47:57 +00:00
|
|
|
Ids: []string{isoInstance.ID()},
|
2023-10-25 19:20:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []*instance.Instance{{
|
2024-09-06 12:47:57 +00:00
|
|
|
Id: isoInstance.ID(),
|
2023-10-25 19:20:12 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "non-existing domain",
|
|
|
|
req: &system_pb.ListInstancesRequest{
|
|
|
|
Queries: []*instance.Query{{
|
|
|
|
Query: &instance.Query_DomainQuery{
|
|
|
|
DomainQuery: &instance.DomainsQuery{
|
|
|
|
Domains: []string{"foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []*instance.Instance{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "get 1 by domain",
|
|
|
|
req: &system_pb.ListInstancesRequest{
|
|
|
|
Query: &object.ListQuery{
|
|
|
|
Limit: 1,
|
|
|
|
},
|
|
|
|
Queries: []*instance.Query{{
|
|
|
|
Query: &instance.Query_DomainQuery{
|
|
|
|
DomainQuery: &instance.DomainsQuery{
|
2024-09-06 12:47:57 +00:00
|
|
|
Domains: []string{isoInstance.Domain},
|
2023-10-25 19:20:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
want: []*instance.Instance{{
|
2024-09-06 12:47:57 +00:00
|
|
|
Id: isoInstance.ID(),
|
2023-10-25 19:20:12 +00:00
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-09-06 12:47:57 +00:00
|
|
|
resp, err := integration.SystemClient().ListInstances(CTX, tt.req)
|
2023-10-25 19:20:12 +00:00
|
|
|
if tt.wantErr {
|
|
|
|
require.Error(t, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
got := resp.GetResult()
|
2024-10-17 21:20:57 +00:00
|
|
|
require.Len(t, got, len(tt.want))
|
2023-10-25 19:20:12 +00:00
|
|
|
for i := 0; i < len(tt.want); i++ {
|
|
|
|
assert.Equalf(t, tt.want[i].GetId(), got[i].GetId(), "instance[%d] id", i)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|