mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-29 15:38:52 +00:00
feat: instance domain APIs with relational tables (#11051)
# Which Problems Are Solved This PR implements the endpoints listed in https://github.com/zitadel/zitadel/issues/10444 . # How the Problems Are Solved The implementation follows the same pattern as the Instance one. The `Add` and `Remove` are implementing the `Commander` interface, while `List` Domains endpoints are implementing the `Querier` interace. The PR adds also some forgotten calls to the relational logic for the Instance API. The commits are identifiable by the label `instance:` prepended to them. This is the complete list: bafce01b0 , 6fe7257ab , e27bc9c34 , 8133ede73 , fde667953 , a3e1135ed , ee1a6f9c1 # Additional Context - Closes #10444 --------- Co-authored-by: Elio Bischof <[email protected]> Co-authored-by: Lebogang Phoshoko <[email protected]> Co-authored-by: Wim Van Laer <[email protected]> Co-authored-by: Max Peintner <[email protected]> Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
co-authored by
Elio Bischof
Lebogang Phoshoko
Wim Van Laer
Max Peintner
Gayathri Vijayan
parent
d79bfe6eba
commit
b339a3e696
@@ -52,7 +52,7 @@ func TestDeleteInstanceCommand_Validate(t *testing.T) {
|
||||
|
||||
return permChecker
|
||||
},
|
||||
expectedError: zerrors.ThrowPermissionDenied(permissionErr, "DOM-Yz8f1X", "permission denied"),
|
||||
expectedError: zerrors.ThrowPermissionDenied(permissionErr, "DOM-Yz8f1X", "Errors.PermissionDenied"),
|
||||
inputID: "instance-1",
|
||||
},
|
||||
{
|
||||
@@ -116,6 +116,7 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
ctx := authz.NewMockContext("inst-1", "org-1", gofakeit.UUID())
|
||||
deleteErr := errors.New("delete error")
|
||||
getErr := errors.New("get error")
|
||||
noRowFoundErr := database.NewNoRowFoundError(nil)
|
||||
|
||||
tests := []struct {
|
||||
testName string
|
||||
@@ -126,12 +127,37 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
expectedError error
|
||||
expectedInstanceName string
|
||||
expectedInstanceDomains []string
|
||||
expectsDeleteTime bool
|
||||
}{
|
||||
{
|
||||
testName: "when retrieving instance fails should return error",
|
||||
instanceRepo: func(ctrl *gomock.Controller) domain.InstanceRepository {
|
||||
instanceRepo := domainmock.NewInstanceRepo(ctrl)
|
||||
|
||||
instanceRepo.EXPECT().
|
||||
LoadDomains().
|
||||
Times(1).
|
||||
Return(instanceRepo)
|
||||
|
||||
instanceRepo.EXPECT().
|
||||
Get(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
dbmock.QueryOptions(database.WithCondition(
|
||||
instanceRepo.IDCondition("instance-1"),
|
||||
)),
|
||||
).
|
||||
Times(1).
|
||||
Return(nil, noRowFoundErr)
|
||||
return instanceRepo
|
||||
},
|
||||
inputInstanceID: "instance-1",
|
||||
},
|
||||
{
|
||||
testName: "when retrieving instance fails with no row found should return no error",
|
||||
instanceRepo: func(ctrl *gomock.Controller) domain.InstanceRepository {
|
||||
instanceRepo := domainmock.NewInstanceRepo(ctrl)
|
||||
|
||||
instanceRepo.EXPECT().
|
||||
LoadDomains().
|
||||
Times(1).
|
||||
@@ -188,7 +214,46 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
return instanceRepo
|
||||
},
|
||||
inputInstanceID: "instance-1",
|
||||
expectedError: deleteErr,
|
||||
expectedError: zerrors.ThrowInternal(deleteErr, "DOM-caF4Vs", "Errors.Instance.Delete"),
|
||||
expectedInstanceName: "My instance 1",
|
||||
expectedInstanceDomains: []string{"d1.example.com", "d2.example.com", "d3.example.com"},
|
||||
},
|
||||
{
|
||||
testName: "when delete instance fails with no row found should return no error",
|
||||
instanceRepo: func(ctrl *gomock.Controller) domain.InstanceRepository {
|
||||
instanceRepo := domainmock.NewInstanceRepo(ctrl)
|
||||
|
||||
instanceRepo.EXPECT().
|
||||
LoadDomains().
|
||||
Times(1).
|
||||
Return(instanceRepo)
|
||||
|
||||
instanceRepo.EXPECT().
|
||||
Get(
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
dbmock.QueryOptions(database.WithCondition(
|
||||
instanceRepo.IDCondition("instance-1"),
|
||||
)),
|
||||
).
|
||||
Times(1).
|
||||
Return(&domain.Instance{
|
||||
ID: "instance-1",
|
||||
Name: "My instance 1",
|
||||
Domains: []*domain.InstanceDomain{
|
||||
{Domain: "d1.example.com"},
|
||||
{Domain: "d2.example.com"},
|
||||
{Domain: "d3.example.com"},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
instanceRepo.EXPECT().
|
||||
Delete(gomock.Any(), gomock.Any(), "instance-1").
|
||||
Times(1).
|
||||
Return(int64(0), database.NewNoRowFoundError(nil))
|
||||
return instanceRepo
|
||||
},
|
||||
inputInstanceID: "instance-1",
|
||||
expectedInstanceName: "My instance 1",
|
||||
expectedInstanceDomains: []string{"d1.example.com", "d2.example.com", "d3.example.com"},
|
||||
},
|
||||
@@ -228,12 +293,12 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
return instanceRepo
|
||||
},
|
||||
inputInstanceID: "instance-1",
|
||||
expectedError: zerrors.ThrowInternalf(nil, "DOM-Od04Jx", "expecting 1 row deleted, got %d", 2),
|
||||
expectedError: zerrors.ThrowInternal(nil, "DOM-Od04Jx", "Errors.Instsance.DeleteMismatch"),
|
||||
expectedInstanceName: "My instance 1",
|
||||
expectedInstanceDomains: []string{"d1.example.com", "d2.example.com", "d3.example.com"},
|
||||
},
|
||||
{
|
||||
testName: "when no rows deleted should return not found error",
|
||||
testName: "when no rows deleted should return no error",
|
||||
instanceRepo: func(ctrl *gomock.Controller) domain.InstanceRepository {
|
||||
instanceRepo := domainmock.NewInstanceRepo(ctrl)
|
||||
|
||||
@@ -268,7 +333,6 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
return instanceRepo
|
||||
},
|
||||
inputInstanceID: "instance-1",
|
||||
expectedError: zerrors.ThrowNotFound(nil, "DOM-daglwD", "instance not found"),
|
||||
expectedInstanceName: "My instance 1",
|
||||
expectedInstanceDomains: []string{"d1.example.com", "d2.example.com", "d3.example.com"},
|
||||
},
|
||||
@@ -310,6 +374,7 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
inputInstanceID: "instance-1",
|
||||
expectedInstanceName: "My instance 1",
|
||||
expectedInstanceDomains: []string{"d1.example.com", "d2.example.com", "d3.example.com"},
|
||||
expectsDeleteTime: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -335,6 +400,7 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) {
|
||||
assert.Equal(t, tc.expectedError, err)
|
||||
assert.Equal(t, tc.expectedInstanceName, d.InstanceName)
|
||||
assert.ElementsMatch(t, tc.expectedInstanceDomains, d.InstanceDomains)
|
||||
assert.Equal(t, tc.expectsDeleteTime, d.DeleteTime != nil && !d.DeleteTime.IsZero())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user