You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/08/14 10:18:42 UTC
[servicecomb-kie] branch master updated: value of labels could be
null (#201)
This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git
The following commit(s) were added to refs/heads/master by this push:
new 020b888 value of labels could be null (#201)
020b888 is described below
commit 020b8887e621d5afd23609b6718111a19ffde7fc
Author: Sphairis <56...@users.noreply.github.com>
AuthorDate: Sat Aug 14 18:18:36 2021 +0800
value of labels could be null (#201)
* labels is a required parameter
* add labels
* labels could be null
* the maximum value of config is 128KB
* change description
* change and add tests
* value of labels could be null
Co-authored-by: SphaIris <aaalixiaopei123>
---
pkg/validator/rule.go | 2 +-
pkg/validator/rule_test.go | 2 +-
server/resource/v1/kv_resource_test.go | 11 +++++++++--
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/pkg/validator/rule.go b/pkg/validator/rule.go
index 9de914e..401c1b7 100644
--- a/pkg/validator/rule.go
+++ b/pkg/validator/rule.go
@@ -23,7 +23,7 @@ const (
key = "key"
commonNameRegexString = `^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$`
labelKeyRegexString = `^[a-zA-Z0-9]{1,32}$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]{1,30}[a-zA-Z0-9]$`
- labelValueRegexString = `^[a-zA-Z0-9]{1,160}$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]{1,158}[a-zA-Z0-9]$`
+ labelValueRegexString = `^[a-zA-Z0-9]{0,160}$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]{0,158}[a-zA-Z0-9]$`
getKeyRegexString = `^[a-zA-Z0-9]*$|^[a-zA-Z0-9][a-zA-Z0-9_\-.]*[a-zA-Z0-9]$|^beginWith\([a-zA-Z0-9][a-zA-Z0-9_\-.]*\)$|^wildcard\([a-zA-Z0-9][a-zA-Z0-9_\-.*]*\)$`
asciiRegexString = `^[\x00-\x7F]*$`
allCharString = `.*`
diff --git a/pkg/validator/rule_test.go b/pkg/validator/rule_test.go
index e9b26a4..9a98da3 100644
--- a/pkg/validator/rule_test.go
+++ b/pkg/validator/rule_test.go
@@ -112,7 +112,7 @@ func TestLabels(t *testing.T) {
Value: "a",
Labels: map[string]string{"a": ""},
}
- assert.Error(t, validator.Validate(kvDoc))
+ assert.NoError(t, validator.Validate(kvDoc))
kvDoc = &model.KVDoc{Project: "a", Domain: "a",
Key: "a",
diff --git a/server/resource/v1/kv_resource_test.go b/server/resource/v1/kv_resource_test.go
index a84e9e2..02f1148 100644
--- a/server/resource/v1/kv_resource_test.go
+++ b/server/resource/v1/kv_resource_test.go
@@ -208,7 +208,7 @@ func TestKVResource_Post(t *testing.T) {
c.ServeHTTP(resp, r)
assert.Equal(t, http.StatusBadRequest, resp.Result().StatusCode)
})
- t.Run("post kv, has one label, value of label is a empty string, should return err", func(t *testing.T) {
+ t.Run("post kv, has one label, value of label is a empty string, should success", func(t *testing.T) {
kv := &model.KVDoc{
Key: "withoutValueOfLabels",
Value: "withoutValueOfLabels",
@@ -221,7 +221,14 @@ func TestKVResource_Post(t *testing.T) {
c, _ := restfultest.New(kvr, nil)
resp := httptest.NewRecorder()
c.ServeHTTP(resp, r)
- assert.Equal(t, http.StatusBadRequest, resp.Result().StatusCode)
+ assert.Equal(t, http.StatusOK, resp.Result().StatusCode)
+
+ body, err := ioutil.ReadAll(resp.Body)
+ assert.NoError(t, err)
+ data := &model.KVDoc{}
+ err = json.Unmarshal(body, data)
+ assert.NoError(t, err)
+ assert.Equal(t, 0, len(data.Labels["a"]))
})
t.Run("post kv, length of value is 131072, should success", func(t *testing.T) {
kv := &model.KVDoc{