added simple test for transformer.go

This commit is contained in:
Christian Goll
2022-11-29 14:30:41 +01:00
parent 53be931f87
commit 79ed2a33ff
3 changed files with 55 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package node
import (
"fmt"
"reflect"
"regexp"
"strings"
@@ -347,3 +348,19 @@ func NewInfo() (nodeInfo NodeInfo) {
nodeInfo.NetDevs = make(map[string]*NetDevEntry)
return nodeInfo
}
/*
Get a entry by its name
*/
func GetByName(node interface{}, name string) (string, error) {
valEntry := reflect.ValueOf(node)
entryField := valEntry.Elem().FieldByName(name)
if entryField == (reflect.Value{}) {
return "", fmt.Errorf("couldn't find field with name: %s", name)
}
if entryField.Type() != reflect.TypeOf(Entry{}) {
return "", fmt.Errorf("field %s is not of type node.Entry", name)
}
myEntry := entryField.Interface().(Entry)
return myEntry.Get(), nil
}