Skip to content

Commit

Permalink
Add more tests for optional metadata in registry
Browse files Browse the repository at this point in the history
We don’t force metadata in registry, add some tests to ensure all those
use cases.

Co-authored-by: Jean-Baptiste Lallement <jean-baptiste@ubuntu.com>
  • Loading branch information
didrocks and jibel committed Jan 11, 2022
1 parent d4de2e8 commit d0088b2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions internal/policies/ad/registry/registry_test.go
Expand Up @@ -80,6 +80,24 @@ func TestDecodePolicy(t *testing.T) {
Meta: "foo",
},
}},
"basic type with empty default has value filed in": {
want: []entry.Entry{
{
Key: `Software/Policies/Ubuntu/privilege/allow-local-admins/all`,
Value: "Default Value",
Disabled: false,
Meta: "foo",
},
}},
"basic type with empty default is not taken into account for disabled keys": {
want: []entry.Entry{
{
Key: `Software/Policies/Ubuntu/privilege/allow-local-admins/all`,
Value: "",
Disabled: true,
Meta: "foo",
},
}},

// Container and options test cases
"container with default elements override empty option values": {
Expand Down Expand Up @@ -144,6 +162,15 @@ func TestDecodePolicy(t *testing.T) {
Meta: "containerMetaValueForChild",
},
}},
"container without metavalues": {
want: []entry.Entry{
{
Key: `Software/Container/Child`,
Value: "MyValue",
Meta: "",
},
}},

"one container with 2 children don’t mix their default values": {
want: []entry.Entry{
{
Expand Down Expand Up @@ -175,6 +202,27 @@ func TestDecodePolicy(t *testing.T) {
Value: "",
},
}},
"two containers don’t mix their default values even when second has none": {
want: []entry.Entry{
{
Key: `Software/Container1/Child1`,
Value: "container1DefaultValueForChild1",
},
{
Key: `Software/Container1/Child2`,
Value: "container1DefaultValueForChild2",
},
{
Key: `Software/Container2/Child1`,
// No empty value inherited from Container 1, as Container 2 meta is nil
Value: "",
},
{
Key: `Software/Container2/Child2`,
// we didn't set default values for Child2 on Container2: keep empty (no leftover for Child1)
Value: "",
},
}},
"one container with 2 children don’t mix their meta values": {
want: []entry.Entry{
{
Expand All @@ -186,6 +234,25 @@ func TestDecodePolicy(t *testing.T) {
Meta: "container1MetaValueForChild2",
},
}},
"two containers don’t mix their meta values, even if second has none": {
want: []entry.Entry{
{
Key: `Software/Container1/Child1`,
Meta: "foo",
},
{
Key: `Software/Container1/Child2`,
Meta: "bar",
},
{
Key: `Software/Container2/Child1`,
Meta: "",
},
{
Key: `Software/Container2/Child2`,
Meta: "",
},
}},

"semicolon in data": {
want: []entry.Entry{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit d0088b2

Please sign in to comment.