Skip to content

Commit

Permalink
Add unit tests and add small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Nov 20, 2024
1 parent 96a91b3 commit fe4cde6
Show file tree
Hide file tree
Showing 2 changed files with 459 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/datasources/rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ func (h *restHandler) ValidateArgs(args any) error {
func (h *restHandler) ValidateUpdate(obj any) error {
switch castedobj := obj.(type) {
case *structpb.Struct:
if _, err := schemavalidate.CompileSchemaFromPB(castedobj); err != nil {
return fmt.Errorf("update validation failed due to invalid schema: %w", err)
}
return schemaupdate.ValidateSchemaUpdate(h.rawnis, castedobj)
case map[string]any:
if _, err := schemavalidate.CompileSchemaFromMap(castedobj); err != nil {
return fmt.Errorf("update validation failed due to invalid schema: %w", err)
}
return schemaupdate.ValidateSchemaUpdateMap(h.rawnis.AsMap(), castedobj)
default:
return errors.New("invalid type")
Expand Down Expand Up @@ -136,7 +142,6 @@ func (h *restHandler) Call(args any) (any, error) {

func (h *restHandler) parseResponseBody(body io.Reader) (any, error) {
var data any
var err error

if body == nil {
return nil, nil
Expand All @@ -153,10 +158,12 @@ func (h *restHandler) parseResponseBody(body io.Reader) (any, error) {

data = jsonData
} else {
data, err = io.ReadAll(lr)
bytedata, err := io.ReadAll(lr)
if err != nil {
return nil, fmt.Errorf("cannot read response body: %w", err)
}

data = string(bytedata)
}

return data, nil
Expand Down
Loading

0 comments on commit fe4cde6

Please sign in to comment.