Skip to content

Unable to unmarshal BoolVal to Yempty (GNMIEncoding) #291

Open
@cho-m

Description

@cho-m

Currently in ytypes/leaf.go, the gNMIToYANGTypeMatches and sanitizeGNMI functions do not support yang.Yempty.

A simple testcase to check this:

$ git diff
diff --git a/ytypes/leaf_test.go b/ytypes/leaf_test.go
index 8d0181a..00ce92d 100644
--- a/ytypes/leaf_test.go
+++ b/ytypes/leaf_test.go
@@ -1657,6 +1657,16 @@ func TestUnmarshalLeafGNMIEncoding(t *testing.T) {
                        },
                        wantVal: &LeafContainerStruct{BoolLeaf: ygot.Bool(true)},
                },
+               {
+                       desc:     "success gNMI BoolVal to Yempty",
+                       inSchema: typeToLeafSchema("empty-leaf", yang.Yempty),
+                       inVal: &gpb.TypedValue{
+                               Value: &gpb.TypedValue_BoolVal{
+                                       BoolVal: true,
+                               },
+                       },
+                       wantVal: &LeafContainerStruct{EmptyLeaf: YANGEmpty(true)},
+               },
                {
                        desc:     "success gNMI StringVal to Ystring",
                        inSchema: typeToLeafSchema("string-leaf", yang.Ystring),

Test result:

--- FAIL: TestUnmarshalLeafGNMIEncoding (0.00s)
    leaf_test.go:1848: success gNMI BoolVal to Yempty: unmarshalLeaf(&{<nil> <nil> empty-leaf    [] Leaf unset <nil> unset map[]  0xc00042efc0 [] <nil> <nil> [] [] [] [] map[] [] map[] map[] <nil>}, &{<nil> [] <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> [] <nil> <nil> 0 <nil> <nil> false [] []}, bool_val:true , GNMIEncoding): got err=failed to unmarshal &{true} into empty, want err=nil
E0706 17:29:38.442149   18766 util_types.go:170] unexpected type bits in yangBuiltinTypeToGoPtrType
FAIL
exit status 1
FAIL	github.com/openconfig/ygot/ytypes	0.063s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions