1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
package api
import (
"fmt"
"testing"
"github.com/muka/go-bluetooth/bluez"
"github.com/muka/go-bluetooth/props"
"github.com/muka/go-bluetooth/util"
"github.com/stretchr/testify/assert"
)
type testStruct struct {
IgnoreFlag bool `dbus:"ignore"`
ToOmit map[string]interface{} `dbus:"omitEmpty,writable"`
Ignored string `dbus:"ignore"`
IgnoredByProperty []string `dbus:"ignore=IgnoreFlag"`
Avail string
}
func (s testStruct) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{}
util.StructToMap(s, m)
return m, nil
}
func (s testStruct) Lock() {}
func (s testStruct) Unlock() {}
func TestParseTag(t *testing.T) {
s := testStruct{
IgnoreFlag: true,
Ignored: "foo",
IgnoredByProperty: []string{"bar"},
Avail: "foo",
}
prop := &DBusProperties{
props: make(map[string]bluez.Properties),
propsConfig: make(map[string]map[string]*props.PropInfo),
}
err := prop.AddProperties("test", s)
if err != nil {
t.Fatal(err)
}
err = prop.parseProperties()
if err != nil {
t.Fatal(err)
}
cfg := prop.propsConfig["test"]
for field, cfg := range cfg {
fmt.Printf("%s: %++v\n", field, cfg)
}
assert.True(t, cfg["ToOmit"].Skip)
assert.True(t, cfg["ToOmit"].Writable)
assert.True(t, cfg["Ignored"].Skip)
assert.True(t, cfg["IgnoredByProperty"].Skip)
assert.Equal(t, "foo", cfg["Avail"].Value)
}
|