used named table tests
@@ -35,35 +35,50 @@ var prefixSet = map[string]*gnmi.Path{
},
}
-var pathsSet = map[string]*gnmi.Path{
- "/": {},
- "origin:e1/e2": {
+var pathsTable = map[string]struct {
+ strPath string
+ gnmiPath *gnmi.Path
+}{
+ "test1": {
+ strPath: "/",
+ gnmiPath: &gnmi.Path{},
+ },
+ "test2": {
+ strPath: "origin:e1/e2",
+ gnmiPath: &gnmi.Path{
Origin: "origin",
Elem: []*gnmi.PathElem{
{Name: "e1"},
{Name: "e2"},
},
},
- "origin:/e1/e2": {
+ },
+ "test3": {
+ strPath: "origin:",
+ gnmiPath: &gnmi.Path{
Origin: "origin",
- Elem: []*gnmi.PathElem{
- {Name: "e1"},
- {Name: "e2"},
},
},
- "origin:": {Origin: "origin"},
- "e": {
+ "test4": {
+ strPath: "e",
+ gnmiPath: &gnmi.Path{
Elem: []*gnmi.PathElem{
{Name: "e"},
},
},
- "/e1/e2": {
+ },
+ "test5": {
+ strPath: "/e1/e2",
+ gnmiPath: &gnmi.Path{
Elem: []*gnmi.PathElem{
{Name: "e1"},
{Name: "e2"},
},
},
- "/e1/e2[k=v]": {
+ },
+ "test6": {
+ strPath: "/e1/e2[k=v]",
+ gnmiPath: &gnmi.Path{
Elem: []*gnmi.PathElem{
{Name: "e1"},
{Name: "e2",
@@ -72,7 +87,10 @@ var pathsSet = map[string]*gnmi.Path{
}},
},
},
- "origin:/e1/e2[k=v]": {
+ },
+ "test7": {
+ strPath: "origin:/e1/e2[k=v]",
+ gnmiPath: &gnmi.Path{
Origin: "origin",
Elem: []*gnmi.PathElem{
{Name: "e1"},
@@ -82,6 +100,7 @@ var pathsSet = map[string]*gnmi.Path{
}},
},
},
+ },
}
func TestCreatePrefix(t *testing.T) {
@@ -107,13 +126,15 @@ func TestCreatePrefix(t *testing.T) {
}
func TestParsePath(t *testing.T) {
- for p, g := range pathsSet {
- pg, err := ParsePath(p)
+ for name, tc := range pathsTable {
+ t.Run(name, func(t *testing.T) {
+ p, err := ParsePath(tc.strPath)
if err != nil {
t.Error(err)
}
- if !reflect.DeepEqual(g, pg) {
- t.Errorf("ParsePath failed with path: %s", p)
+ if !reflect.DeepEqual(p, tc.gnmiPath) {
+ t.Errorf("ParsePath failed with path: %s", tc.strPath)
}
+ })
}
}
