Skip to content

Commit

Permalink
Fix Batch Generation to only generate on root
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus committed Aug 15, 2023
1 parent 0b1901f commit 83867e4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pathgen/gnmigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func defaultTmplStruct(pathStructName string, node *NodeData) gnmiStruct {

// generateOneOff generates one-off free-form generated code.
func generateOneOff(b *strings.Builder, node *NodeData, tmplStruct gnmiStruct, compressPaths bool) error {
if node.SubsumingGoStructName == fakeRootName {
if strings.TrimLeft(node.LocalGoTypeName, "*") == fakeRootName {
tmplStruct.MethodName = "Query"
if compressPaths {
tmplStruct.MethodName = "State"
Expand Down
95 changes: 94 additions & 1 deletion pathgen/gnmigen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,99 @@ func (n *Container_LeafAny) State() ygnmi.WildcardQuery[int32] {
nil,
)
}
`,
}, {
desc: "scalar leaf without config directly below root",
dir: dirs["/root"],
pathStructName: "Leaf",
node: &NodeData{
GoTypeName: "int32",
LocalGoTypeName: "int32",
GoFieldName: "Leaf",
YANGFieldName: "leaf",
SubsumingGoStructName: "Root",
IsLeaf: true,
IsScalarField: true,
HasDefault: true,
YANGPath: "/leaf",
},
want: `
// State returns a Query that can be used in gNMI operations.
// Defining module: "root-module"
// Instantiating module: "root-module"
// Path from parent: "leaf"
// Path from root: "/leaf"
func (n *Leaf) State() ygnmi.SingletonQuery[int32] {
return ygnmi.NewSingletonQuery[int32](
"Root",
true,
true,
true,
true,
false,
ygnmi.NewNodePath(
[]string{"leaf"},
nil,
n.parent,
),
func(gs ygot.ValidatedGoStruct) (int32, bool) {
ret := gs.(*oc.Root).Leaf
if ret == nil {
var zero int32
return zero, false
}
return *ret, true
},
func() ygot.ValidatedGoStruct { return new(oc.Root) },
func() *ytypes.Schema {
return &ytypes.Schema{
Root: &oc.Root{},
SchemaTree: oc.SchemaTree,
Unmarshal: oc.Unmarshal,
}
},
nil,
nil,
)
}
// State returns a Query that can be used in gNMI operations.
// Defining module: "root-module"
// Instantiating module: "root-module"
// Path from parent: "leaf"
// Path from root: "/leaf"
func (n *LeafAny) State() ygnmi.WildcardQuery[int32] {
return ygnmi.NewWildcardQuery[int32](
"Root",
true,
true,
true,
true,
false,
ygnmi.NewNodePath(
[]string{"leaf"},
nil,
n.parent,
),
func(gs ygot.ValidatedGoStruct) (int32, bool) {
ret := gs.(*oc.Root).Leaf
if ret == nil {
var zero int32
return zero, false
}
return *ret, true
},
func() ygot.ValidatedGoStruct { return new(oc.Root) },
func() *ytypes.Schema {
return &ytypes.Schema{
Root: &oc.Root{},
SchemaTree: oc.SchemaTree,
Unmarshal: oc.Unmarshal,
}
},
nil,
)
}
`,
}, {
desc: "scalar leaf with config",
Expand Down Expand Up @@ -389,7 +482,7 @@ func (n *Container_LeafAny) State() ygnmi.WildcardQuery[E_Child_Three] {
pathStructName: "Root",
node: &NodeData{
GoTypeName: "*oc.Root",
LocalGoTypeName: "Root",
LocalGoTypeName: "*Root",
GoFieldName: "",
YANGFieldName: "",
SubsumingGoStructName: "Root",
Expand Down

0 comments on commit 83867e4

Please sign in to comment.