mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-09 16:10:00 +08:00
(goctl)fix parser issues (#3930)
This commit is contained in:
@@ -8,14 +8,40 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/parser/api/assertx"
|
||||
)
|
||||
|
||||
func Test_Parse(t *testing.T) {
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
_, err := Parse("./testdata/example.api", nil)
|
||||
apiSpec, err := Parse("./testdata/example.api", nil)
|
||||
assert.Nil(t, err)
|
||||
ast := assert.New(t)
|
||||
ast.Equal(spec.Info{
|
||||
Title: "type title here",
|
||||
Desc: "type desc here",
|
||||
Version: "type version here",
|
||||
Author: "type author here",
|
||||
Email: "type email here",
|
||||
Properties: map[string]string{
|
||||
"title": "type title here",
|
||||
"desc": "type desc here",
|
||||
"version": "type version here",
|
||||
"author": "type author here",
|
||||
"email": "type email here",
|
||||
},
|
||||
}, apiSpec.Info)
|
||||
ast.True(func() bool {
|
||||
for _, group := range apiSpec.Service.Groups {
|
||||
value, ok := group.Annotation.Properties["summary"]
|
||||
if ok {
|
||||
return value == "test"
|
||||
}
|
||||
}
|
||||
return false
|
||||
}())
|
||||
})
|
||||
t.Run("invalid", func(t *testing.T) {
|
||||
data, err := os.ReadFile("./testdata/invalid.api")
|
||||
@@ -46,4 +72,9 @@ func Test_Parse(t *testing.T) {
|
||||
_, err := Parse("./testdata/link_import.api", nil)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("duplicate_types", func(t *testing.T) {
|
||||
_, err := Parse("./testdata/duplicate_type.api", nil)
|
||||
assertx.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user