Skip to content

Commit

Permalink
add enum support for modelgen
Browse files Browse the repository at this point in the history
Fix #133
  • Loading branch information
halfcrazy committed Jun 8, 2021
1 parent 1294653 commit 2d1cbdf
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 14 deletions.
73 changes: 69 additions & 4 deletions cmd/modelgen/table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 33 additions & 10 deletions cmd/modelgen/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNewTableGenerator(t *testing.T) {
"name": "AtomicDB",
"version": "0.0.0",
"tables": {
"atomicTable": {
"AtomicTable": {
"columns": {
"str": {
"type": "string"
Expand All @@ -24,7 +24,13 @@ func TestNewTableGenerator(t *testing.T) {
},
"float": {
"type": "real"
}
},
"protocol": {
"type": {"key": {"type": "string",
"enum": ["set", ["tcp", "udp", "sctp"]]},
"min": 0, "max": 1}},
"event_type": {"type": {"key": {"type": "string",
"enum": ["set", ["empty_lb_backends"]]}}}
}
}
}
Expand All @@ -35,12 +41,28 @@ func TestNewTableGenerator(t *testing.T) {
package test
// test defines an object in test table
type test struct {
UUID string ` + "`" + `ovs:"_uuid"` + "`" + `
Float float64 ` + "`" + `ovs:"float"` + "`" + `
Int int ` + "`" + `ovs:"int"` + "`" + `
Str string ` + "`" + `ovs:"str"` + "`" + `
type (
AtomicTableEventType string
AtomicTableProtocol string
)
const (
AtomicTableEventTypeEmptyLbBackends AtomicTableEventType = "empty_lb_backends"
AtomicTableProtocolTCP AtomicTableProtocol = "tcp"
AtomicTableProtocolUDP AtomicTableProtocol = "udp"
AtomicTableProtocolSCTP AtomicTableProtocol = "sctp"
)
// AtomicTable defines an object in AtomicTable table
type AtomicTable struct {
UUID string ` + "`" + `ovs:"_uuid"` + "`" + `
EventType AtomicTableEventType ` + "`" + `ovs:"event_type"` + "`" + `
Float float64 ` + "`" + `ovs:"float"` + "`" + `
Int int ` + "`" + `ovs:"int"` + "`" + `
Protocol []AtomicTableProtocol ` + "`" + `ovs:"protocol"` + "`" + `
Str string ` + "`" + `ovs:"str"` + "`" + `
}
`

Expand All @@ -49,10 +71,11 @@ type test struct {
if err != nil {
t.Fatal(err)
}
table := schema.Tables["atomicTable"]
fakeTable := "AtomicTable"
table := schema.Tables[fakeTable]
gen := NewTableGenerator(
"test",
"test",
fakeTable,
&table,
)

Expand Down

0 comments on commit 2d1cbdf

Please sign in to comment.