Add 'settings/' from commit '230545a4a75b0611988fbcea51336a6c316d6a3d'

git-subtree-dir: settings
git-subtree-mainline: c26f7b390a
git-subtree-split: 230545a4a7
This commit is contained in:
A.Unger
2020-09-18 12:43:43 +02:00
140 changed files with 28757 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
package util
import (
"testing"
"github.com/owncloud/ocis-settings/pkg/proto/v0"
"gotest.tools/assert"
)
func TestIsResourceMatched(t *testing.T) {
scenarios := []struct {
name string
definition *proto.Resource
example *proto.Resource
matched bool
}{
{
"same resource types without ids match",
&proto.Resource{
Type: proto.Resource_TYPE_SYSTEM,
},
&proto.Resource{
Type: proto.Resource_TYPE_SYSTEM,
},
true,
},
{
"different resource types without ids don't match",
&proto.Resource{
Type: proto.Resource_TYPE_SYSTEM,
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
},
false,
},
{
"same resource types with different ids don't match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "marie",
},
false,
},
{
"same resource types with same ids match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
true,
},
{
"same resource types with definition = ALL and without id in example is a match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: ResourceIDAll,
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
},
true,
},
{
"same resource types with definition.id = ALL and with some id in example is a match",
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: ResourceIDAll,
},
&proto.Resource{
Type: proto.Resource_TYPE_USER,
Id: "einstein",
},
true,
},
}
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
assert.Equal(t, scenario.matched, IsResourceMatched(scenario.definition, scenario.example))
})
}
}