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
|
package filter_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/lxc/incus/v6/internal/filter"
"github.com/lxc/incus/v6/shared/api"
)
func TestDotPrefixMatch(t *testing.T) {
pass := true
pass = pass && filter.DotPrefixMatch("s.privileged", "security.privileged")
pass = pass && filter.DotPrefixMatch("u.blah", "user.blah")
if !pass {
t.Error("failed prefix matching")
}
}
func TestValueOf_Instance(t *testing.T) {
date := time.Date(2020, 1, 29, 11, 10, 32, 0, time.UTC)
instance := api.Instance{
InstancePut: api.InstancePut{
Architecture: "x86_64",
Config: map[string]string{
"image.os": "BusyBox",
},
Stateful: false,
},
CreatedAt: date,
Name: "c1",
ExpandedConfig: map[string]string{
"image.os": "BusyBox",
},
ExpandedDevices: map[string]map[string]string{
"root": {
"path": "/",
"pool": "default",
"type": "disk",
},
},
Status: "Running",
}
cases := map[string]any{}
cases["architecture"] = "x86_64"
cases["created_at"] = date
cases["config.image.os"] = "BusyBox"
cases["name"] = "c1"
cases["expanded_config.image.os"] = "BusyBox"
cases["expanded_config.im.os"] = "BusyBox"
cases["expanded_devices.root.pool"] = "default"
cases["status"] = "Running"
cases["stateful"] = false
for field := range cases {
t.Run(field, func(t *testing.T) {
value := filter.ValueOf(instance, field)
assert.Equal(t, cases[field], value)
})
}
}
|