mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-08 07:44:27 +00:00
feat: Tests for instance v2 input validation (#9452)
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
|||||||
|
|
||||||
func (s *Server) DeleteInstance(ctx context.Context, request *instance.DeleteInstanceRequest) (*instance.DeleteInstanceResponse, error) {
|
func (s *Server) DeleteInstance(ctx context.Context, request *instance.DeleteInstanceRequest) (*instance.DeleteInstanceResponse, error) {
|
||||||
instanceID := strings.TrimSpace(request.GetInstanceId())
|
instanceID := strings.TrimSpace(request.GetInstanceId())
|
||||||
if instanceID == "" {
|
if err := validateParam(instanceID, "instance_id"); err != nil {
|
||||||
return nil, zerrors.ThrowInvalidArgument(nil, "instance_id", "instance id must not be empty")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := s.command.RemoveInstance(ctx, instanceID)
|
obj, err := s.command.RemoveInstance(ctx, instanceID)
|
||||||
@@ -28,8 +28,8 @@ func (s *Server) DeleteInstance(ctx context.Context, request *instance.DeleteIns
|
|||||||
|
|
||||||
func (s *Server) UpdateInstance(ctx context.Context, request *instance.UpdateInstanceRequest) (*instance.UpdateInstanceResponse, error) {
|
func (s *Server) UpdateInstance(ctx context.Context, request *instance.UpdateInstanceRequest) (*instance.UpdateInstanceResponse, error) {
|
||||||
instanceName := strings.TrimSpace(request.GetInstanceName())
|
instanceName := strings.TrimSpace(request.GetInstanceName())
|
||||||
if instanceName == "" {
|
if err := validateParam(instanceName, "instance_name"); err != nil {
|
||||||
return nil, zerrors.ThrowInvalidArgument(nil, "instance_name", "instance name must not be empty")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := s.command.UpdateInstance(ctx, instanceName)
|
obj, err := s.command.UpdateInstance(ctx, instanceName)
|
||||||
@@ -41,3 +41,10 @@ func (s *Server) UpdateInstance(ctx context.Context, request *instance.UpdateIns
|
|||||||
Details: object.DomainToDetailsPb(obj),
|
Details: object.DomainToDetailsPb(obj),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateParam(param string, paramName string) error {
|
||||||
|
if strings.TrimSpace(param) == "" {
|
||||||
|
return zerrors.ThrowInvalidArgument(nil, paramName, paramName+" must not be empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
27
internal/api/grpc/instance/v2/instance_test.go
Normal file
27
internal/api/grpc/instance/v2/instance_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package instance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/zitadel/zitadel/internal/zerrors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidateParam(t *testing.T) {
|
||||||
|
tt := []struct {
|
||||||
|
param string
|
||||||
|
paramName string
|
||||||
|
expectedErr error
|
||||||
|
}{
|
||||||
|
{"", "instance_id", zerrors.ThrowInvalidArgument(nil, "instance_id", "instance_id must not be empty")},
|
||||||
|
{" ", "instance_id", zerrors.ThrowInvalidArgument(nil, "instance_id", "instance_id must not be empty")},
|
||||||
|
{"valid_id", "instance_id", nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tt {
|
||||||
|
t.Run(tc.param, func(t *testing.T) {
|
||||||
|
err := validateParam(tc.param, tc.paramName)
|
||||||
|
assert.Equal(t, tc.expectedErr, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user