Skip to content

Commit

Permalink
e2e/mongo: add e2e test for yaml multiple object (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
scbizu committed May 24, 2023
1 parent fe17eff commit 6bd6435
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
19 changes: 16 additions & 3 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"bytes"
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
Expand Down Expand Up @@ -68,7 +69,7 @@ var genCmd = &cobra.Command{
if err != nil {
return err
}
if err := yaml.NewDecoder(bytes.NewReader(data)).Decode(&objs); err != nil {
if err := decode(data, &objs); err != nil {
return err
}
return nil
Expand All @@ -80,7 +81,7 @@ var genCmd = &cobra.Command{
if err != nil {
return err
}
if err := yaml.NewDecoder(bytes.NewReader(data)).Decode(&objs); err != nil {
if err := decode(data, &objs); err != nil {
return err
}
}
Expand All @@ -90,7 +91,6 @@ var genCmd = &cobra.Command{
if genGoPackageName == "" {
genGoPackageName = genPackageName
}

if plugin != "" {
generators = append(generators, generator.NewPluginGenerator(plugin))
}
Expand All @@ -115,6 +115,19 @@ var genCmd = &cobra.Command{
},
}

func decode(data []byte, meta *generator.Metadata) error {
dc := yaml.NewDecoder(bytes.NewReader(data))
for {
if err := dc.Decode(meta); err != nil {
if err == io.EOF {
return nil
} else {
return err
}
}
}
}

var (
input string
output string
Expand Down
3 changes: 2 additions & 1 deletion e2e/mongo/nested/nested.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
User:
db: mongo
fields:
Expand All @@ -12,7 +13,7 @@ User:
- Blogs: list<Blog>
- RegisterDate: time.Time
attrs: {bsonTag: "registerDate", jsonTag: "registerDate"}

---
Blog:
db: mongo
# To describe that the Blog should only generate the structure , exclude the orm methods
Expand Down
3 changes: 2 additions & 1 deletion e2e/mongo/user/user.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
User:
db: mongo
fields:
Expand All @@ -15,7 +16,7 @@ User:
table: test_user
dbname: test
comment: "all registered user use our systems"

---
UserBlog:
db: mongo
fields:
Expand Down
1 change: 1 addition & 0 deletions e2e/mysql/blog.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
Blog:
db: mysql
dbname: test
Expand Down
1 change: 1 addition & 0 deletions e2e/mysql/user.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
User:
db: mysql
table: test_user
Expand Down
2 changes: 1 addition & 1 deletion e2e/mysqlr/blog.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

---
Blog:
db: mysqlr
dbname: test
Expand Down
1 change: 1 addition & 0 deletions e2e/mysqlr/user.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
User:
db: mysqlr
dbname: test
Expand Down

0 comments on commit 6bd6435

Please sign in to comment.