Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typo in JSON custom field tag for CRUDPath #149

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kong/custom/entity_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type EntityCRUD interface {
// EntityCRUDDefinition implements the EntityCRUD interface.
type EntityCRUDDefinition struct {
Name Type `yaml:"name" json:"name"`
CRUDPath string `yaml:"crud" json:"curd"`
CRUDPath string `yaml:"crud" json:"crud"`
PrimaryKey string `yaml:"primary_key" json:"primary_key"`
}

Expand Down
33 changes: 33 additions & 0 deletions kong/custom/entity_crud_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package custom

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

func TestRender(t *testing.T) {
Expand Down Expand Up @@ -89,3 +91,34 @@ func TestEntityCRUDDefinition(t *testing.T) {
assert.NotNil(err)
assert.Empty(url)
}

func TestEntityCRUDUnmarshal(t *testing.T) {
assert := assert.New(t)

t.Run("unmarshal JSON into EntityCRUDDefinition", func(t *testing.T) {
bytes := []byte(`{
"name": "name",
"crud": "crud-path",
"primary_key": "primary-key"
}`)
var def EntityCRUDDefinition
err := json.Unmarshal(bytes, &def)
assert.Nil(err)
assert.Equal(Type("name"), def.Name)
assert.Equal("crud-path", def.CRUDPath)
assert.Equal("primary-key", def.PrimaryKey)
})

t.Run("unmarshal YAML into EntityCRUDDefinition", func(t *testing.T) {
var def EntityCRUDDefinition
bytes := []byte(`
name: "name"
crud: "crud-path"
primary_key: "primary-key"`)
err := yaml.Unmarshal(bytes, &def)
assert.Nil(err)
assert.Equal(Type("name"), def.Name)
assert.Equal("crud-path", def.CRUDPath)
assert.Equal("primary-key", def.PrimaryKey)
})
}