@@ -2,7 +2,6 @@ package datamodel
22
33import (
44 "errors"
5- "fmt"
65 "testing"
76 "time"
87
@@ -86,6 +85,76 @@ func TestGetValue(t *testing.T) {
8685 assert .Equal (t , "Residential Gateway" , param .Value )
8786}
8887
88+ func TestGetValueFormatGen (t * testing.T ) {
89+ const path1 = "Device.Ethernet.Interface.5.Stats.BytesReceived"
90+ const path2 = "Device.Ethernet.Interface.5.Enabled"
91+ t .Run ("int" , func (t * testing.T ) {
92+ state := newState ()
93+ dm := New (state .WithDefaults (map [string ]Parameter {
94+ path1 : {
95+ Path : path1 ,
96+ Type : "xsd:int" ,
97+ gen : func () float64 { return 123.456 },
98+ },
99+ }))
100+ param , ok := dm .GetValue (path1 )
101+ assert .True (t , ok )
102+ assert .Equal (t , "123" , param .GetValue ())
103+ })
104+ t .Run ("uint" , func (t * testing.T ) {
105+ state := newState ()
106+ dm := New (state .WithDefaults (map [string ]Parameter {
107+ path1 : {
108+ Path : path1 ,
109+ Type : "unsignedInt" ,
110+ gen : func () float64 { return 123.456 },
111+ },
112+ }))
113+ param , ok := dm .GetValue (path1 )
114+ assert .True (t , ok )
115+ assert .Equal (t , "123" , param .GetValue ())
116+ })
117+ t .Run ("float" , func (t * testing.T ) {
118+ state := newState ()
119+ dm := New (state .WithDefaults (map [string ]Parameter {
120+ path1 : {
121+ Path : path1 ,
122+ Type : "double" ,
123+ gen : func () float64 { return 123.456 },
124+ },
125+ }))
126+ param , ok := dm .GetValue (path1 )
127+ assert .True (t , ok )
128+ assert .Equal (t , "123.456" , param .GetValue ())
129+ })
130+ t .Run ("bool" , func (t * testing.T ) {
131+ state := newState ()
132+ dm := New (state .WithDefaults (map [string ]Parameter {
133+ path2 : {
134+ Path : path2 ,
135+ Type : "xsd:boolean" ,
136+ gen : func () float64 { return 1 },
137+ },
138+ }))
139+ param , ok := dm .GetValue (path2 )
140+ assert .True (t , ok )
141+ assert .Equal (t , "true" , param .GetValue ())
142+ })
143+ t .Run ("unsupported" , func (t * testing.T ) {
144+ state := newState ()
145+ dm := New (state .WithDefaults (map [string ]Parameter {
146+ path2 : {
147+ Path : path2 ,
148+ Type : "xsd:string" ,
149+ gen : func () float64 { return 123 },
150+ },
151+ }))
152+ param , ok := dm .GetValue (path2 )
153+ assert .True (t , ok )
154+ assert .Equal (t , "" , param .GetValue ())
155+ })
156+ }
157+
89158func TestGetValues (t * testing.T ) {
90159 state := newState ()
91160 dm := New (state .WithDefaults (map [string ]Parameter {
@@ -106,7 +175,6 @@ func TestGetValues(t *testing.T) {
106175 "Device.DeviceInfo.Description" ,
107176 "Device.DeviceInfo.HardwareVersion" ,
108177 )
109- fmt .Println (ok , params )
110178 assert .True (t , ok )
111179 assert .Len (t , params , 2 )
112180}
0 commit comments