Skip to content

Commit

Permalink
fix: some code errors refer to the review
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiran committed Nov 3, 2020
1 parent 1741b19 commit 4c985ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion api/internal/core/store/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (v *APISIXJsonSchemaValidator) Validate(obj interface{}) error {
if plugins != nil {
for pluginName, pluginConf := range plugins {
var schemaDef string
schemaDef = conf.Schema.Get("plugins." + pluginName + "." +schemaType).String()
schemaDef = conf.Schema.Get("plugins." + pluginName + "." + schemaType).String()
if (schemaDef == "" && schemaType == "consumer_schema") {
schemaDef = conf.Schema.Get("plugins." + pluginName + ".schema").String()
}
Expand Down
36 changes: 16 additions & 20 deletions api/internal/handler/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ func TestPlugin(t *testing.T) {
//schema
input := &GetInput{}
reqBody := `{
"name": "limit-count"
}`
"name": "limit-count"
}`
json.Unmarshal([]byte(reqBody), input)
ctx.SetInput(input)
val, _ := handler.Schema(ctx)
assert.NotNil(t, val)

//not exists
input2 := &GetInput{}
reqBody = `{
"name": "not-exists"
}`
json.Unmarshal([]byte(reqBody), input2)
ctx.SetInput(input2)
"name": "not-exists"
}`
json.Unmarshal([]byte(reqBody), input)
ctx.SetInput(input)
val, _ = handler.Schema(ctx)
assert.Nil(t, val)

Expand All @@ -61,13 +60,12 @@ func TestPlugin(t *testing.T) {
plugin has consumer_schema
return plugin`s consumer_schema
*/
input3 := &GetInput{}
reqBody = `{
"name": "jwt-auth",
"name": "jwt-auth",
"schema_type": "consumer"
}`
json.Unmarshal([]byte(reqBody), input3)
ctx.SetInput(input3)
}`
json.Unmarshal([]byte(reqBody), input)
ctx.SetInput(input)
val, _ = handler.Schema(ctx)
assert.NotNil(t, val)

Expand All @@ -76,27 +74,25 @@ func TestPlugin(t *testing.T) {
plugin does not have consumer_schema
return plugin`s schema
*/
input4 := &GetInput{}
reqBody = `{
"name": "limit-count",
"schema_type": "consumer"
}`
json.Unmarshal([]byte(reqBody), input4)
ctx.SetInput(input4)
}`
json.Unmarshal([]byte(reqBody), input)
ctx.SetInput(input)
val, _ = handler.Schema(ctx)
assert.NotNil(t, val)

/*
get plugin schema with wrong schema_type: type,
return plugin`s schema
*/
input5 := &GetInput{}
reqBody = `{
"name": "jwt-auth",
"schema_type": "type"
}`
json.Unmarshal([]byte(reqBody), input5)
ctx.SetInput(input5)
}`
json.Unmarshal([]byte(reqBody), input)
ctx.SetInput(input)
val, _ = handler.Schema(ctx)
assert.NotNil(t, val)
}

0 comments on commit 4c985ff

Please sign in to comment.