You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2021/03/19 01:08:43 UTC

[servicecomb-service-center] branch master updated: SCB-2176 Fix: Allow erase tags (#905)

This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fdcb25  SCB-2176 Fix: Allow erase tags (#905)
3fdcb25 is described below

commit 3fdcb25d1b65272c7e8587dd1680faaf9eb1b333
Author: little-cui <su...@qq.com>
AuthorDate: Fri Mar 19 09:08:38 2021 +0800

    SCB-2176 Fix: Allow erase tags (#905)
---
 integration/tags_test.go        | 24 ++++++++++++++++++------
 server/service/tag_test.go      | 16 +++++++++-------
 server/service/tag_validator.go |  2 +-
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/integration/tags_test.go b/integration/tags_test.go
index c700ff1..af671a1 100644
--- a/integration/tags_test.go
+++ b/integration/tags_test.go
@@ -101,11 +101,8 @@ var _ = Describe("MicroService Api Test", func() {
 				Expect(resp.StatusCode).To(Equal(http.StatusOK))
 			})
 
-			It("Create MicroService tags with invalid params", func() {
-				tags := map[string]interface{}{}
-				bodyParams := map[string]interface{}{
-					"tags": tags,
-				}
+			It("Create MicroService tags with empty collections, should be pass", func() {
+				bodyParams := map[string]interface{}{}
 				url := strings.Replace(ADDTAGE, ":serviceId", serviceId, 1)
 				body, _ := json.Marshal(bodyParams)
 				bodyBuf := bytes.NewReader(body)
@@ -115,7 +112,22 @@ var _ = Describe("MicroService Api Test", func() {
 				Expect(err).To(BeNil())
 				defer resp.Body.Close()
 
-				Expect(resp.StatusCode).To(Equal(http.StatusBadRequest))
+				Expect(resp.StatusCode).To(Equal(http.StatusOK))
+
+				tags := map[string]interface{}{}
+				bodyParams = map[string]interface{}{
+					"tags": tags,
+				}
+				url = strings.Replace(ADDTAGE, ":serviceId", serviceId, 1)
+				body, _ = json.Marshal(bodyParams)
+				bodyBuf = bytes.NewReader(body)
+				req, _ = http.NewRequest(POST, SCURL+url, bodyBuf)
+				req.Header.Set("X-Domain-Name", "default")
+				resp, err = scclient.Do(req)
+				Expect(err).To(BeNil())
+				defer resp.Body.Close()
+
+				Expect(resp.StatusCode).To(Equal(http.StatusOK))
 			})
 
 			It("Create MicroService tags with invalid serviceID", func() {
diff --git a/server/service/tag_test.go b/server/service/tag_test.go
index 40f5c85..39f8f2c 100644
--- a/server/service/tag_test.go
+++ b/server/service/tag_test.go
@@ -86,13 +86,6 @@ var _ = Describe("'Tag' service", func() {
 				})
 				Expect(respAddTags.Response.GetCode()).ToNot(Equal(pb.ResponseSuccess))
 
-				By("tag is empty")
-				respAddTags, _ = serviceResource.AddTags(getContext(), &pb.AddServiceTagsRequest{
-					ServiceId: serviceId1,
-					Tags:      map[string]string{},
-				})
-				Expect(respAddTags.Response.GetCode()).ToNot(Equal(pb.ResponseSuccess))
-
 				By("tag key is empty")
 				respAddTags, _ = serviceResource.AddTags(getContext(), &pb.AddServiceTagsRequest{
 					ServiceId: serviceId1,
@@ -119,6 +112,15 @@ var _ = Describe("'Tag' service", func() {
 				})
 				Expect(err).To(BeNil())
 				Expect(respAddTags.Response.GetCode()).To(Equal(pb.ResponseSuccess))
+
+				By("tag is empty")
+				respAddTags, _ = serviceResource.AddTags(getContext(), &pb.AddServiceTagsRequest{
+					ServiceId: serviceId1,
+					Tags:      map[string]string{},
+				})
+				Expect(respAddTags.Response.GetCode()).To(Equal(pb.ResponseSuccess))
+				getServiceTagsResponse, _ := serviceResource.GetTags(getContext(), &pb.GetServiceTagsRequest{ServiceId: serviceId1})
+				Expect(getServiceTagsResponse.Tags).To(BeEmpty())
 			})
 		})
 
diff --git a/server/service/tag_validator.go b/server/service/tag_validator.go
index 926f562..4acc235 100644
--- a/server/service/tag_validator.go
+++ b/server/service/tag_validator.go
@@ -44,7 +44,7 @@ func GetTagsReqValidator() *validate.Validator {
 func AddTagsReqValidator() *validate.Validator {
 	return addTagsReqValidator.Init(func(v *validate.Validator) {
 		v.AddRule("ServiceId", GetServiceReqValidator().GetRule("ServiceId"))
-		v.AddRule("Tags", &validate.Rule{Min: 1, Max: quota.DefaultTagQuota, Regexp: tagRegex})
+		v.AddRule("Tags", &validate.Rule{Max: quota.DefaultTagQuota, Regexp: tagRegex})
 	})
 }