Skip to content

Commit

Permalink
add labels on the entity before validate (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
I065450 authored Nov 1, 2021
1 parent eb56489 commit f315b2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 4 additions & 5 deletions api/base_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/tidwall/sjson"
"net/http"
"strconv"
"time"

"github.com/Peripli/service-manager/operations"

"github.com/tidwall/sjson"

"github.com/gofrs/uuid"

"github.com/Peripli/service-manager/storage"
Expand Down Expand Up @@ -498,6 +497,9 @@ func (c *BaseController) PatchObject(r *web.Request) (*web.Response, error) {
createdAt := objFromDB.GetCreatedAt()
updatedAt := objFromDB.GetUpdatedAt()

labels, _, _ := query.ApplyLabelChangesToLabels(labelChanges, objFromDB.GetLabels())
objFromDB.SetLabels(labels)

if err := util.BytesToObject(r.Body, objFromDB); err != nil {
return nil, err
}
Expand All @@ -507,9 +509,6 @@ func (c *BaseController) PatchObject(r *web.Request) (*web.Response, error) {
objFromDB.SetUpdatedAt(updatedAt)
objFromDB.SetReady(true)

labels, _, _ := query.ApplyLabelChangesToLabels(labelChanges, objFromDB.GetLabels())
objFromDB.SetLabels(labels)

action := func(ctx context.Context, repository storage.Repository) (types.Object, error) {
object, err := repository.Update(ctx, objFromDB, labelChanges, criteria...)
return object, util.HandleStorageError(err, c.objectType.String())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,27 @@ var _ = DescribeTestsFor(TestCase{
Expect(method).To(Not(Equal("PATCH")))
})
})
When("invalid label key", func() {
It("returns error", func() {
labels := []*types.LabelChange{
{
Operation: types.AddLabelOperation,
Key: "label Key1",
Values: []string{"labelValue1"},
},
}
patchLabelsBody = make(map[string]interface{})
patchLabelsBody["labels"] = labels
testCtx.SMWithOAuthForTenant.PATCH(web.ServiceInstancesURL+"/"+SID).
WithQuery("async", "false").
WithJSON(patchLabelsBody).Expect().Status(http.StatusBadRequest)

testCtx.SMWithOAuthForTenant.PATCH(web.ServiceInstancesURL+"/"+SID).
WithQuery("async", "false").
WithJSON(patchLabelsBody).Expect().Status(http.StatusBadRequest)

})
})
When("name and label is provided in request body", func() {
It("returns 404", func() {
patchLabelsBody["name"] = "name"
Expand Down

0 comments on commit f315b2b

Please sign in to comment.