(goctl)fix parser issues (#3930)

This commit is contained in:
kesonan
2024-03-02 22:27:39 +08:00
committed by GitHub
parent a5d2b971a1
commit e08ba2fee8
13 changed files with 179 additions and 24 deletions

View File

@@ -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)
})
}