[lxc-devel] [distrobuilder/master] shared: Fix filters

monstermunchkin on Github lxc-bot at linuxcontainers.org
Thu Aug 15 07:00:01 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190815/ce80653c/attachment.bin>
-------------- next part --------------
From 6469b378f41c1df7709a9374385592f1ea07375f Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Thu, 15 Aug 2019 08:59:27 +0200
Subject: [PATCH] shared: Fix filters

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/definition.go      | 26 +++++++++++++-------------
 shared/definition_test.go | 17 +++++++++++++++++
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/shared/definition.go b/shared/definition.go
index 977cb8b..f4087ef 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -22,9 +22,9 @@ type DefinitionFilter struct {
 // A DefinitionPackagesSet is a set of packages which are to be installed
 // or removed.
 type DefinitionPackagesSet struct {
-	DefinitionFilter
-	Packages []string `yaml:"packages"`
-	Action   string   `yaml:"action"`
+	DefinitionFilter `yaml:",inline"`
+	Packages         []string `yaml:"packages"`
+	Action           string   `yaml:"action"`
 }
 
 // A DefinitionPackagesRepository contains data of a specific repository
@@ -115,13 +115,13 @@ type DefinitionTarget struct {
 
 // A DefinitionFile represents a file which is to be created inside to chroot.
 type DefinitionFile struct {
-	DefinitionFilter
-	Generator string                 `yaml:"generator"`
-	Path      string                 `yaml:"path,omitempty"`
-	Content   string                 `yaml:"content,omitempty"`
-	Name      string                 `yaml:"name,omitempty"`
-	Template  DefinitionFileTemplate `yaml:"template,omitempty"`
-	Templated bool                   `yaml:"templated,omitempty"`
+	DefinitionFilter `yaml:",inline"`
+	Generator        string                 `yaml:"generator"`
+	Path             string                 `yaml:"path,omitempty"`
+	Content          string                 `yaml:"content,omitempty"`
+	Name             string                 `yaml:"name,omitempty"`
+	Template         DefinitionFileTemplate `yaml:"template,omitempty"`
+	Templated        bool                   `yaml:"templated,omitempty"`
 }
 
 // A DefinitionFileTemplate represents the settings used by generators
@@ -133,9 +133,9 @@ type DefinitionFileTemplate struct {
 // A DefinitionAction specifies a custom action (script) which is to be run after
 // a certain action.
 type DefinitionAction struct {
-	DefinitionFilter
-	Trigger string `yaml:"trigger"`
-	Action  string `yaml:"action"`
+	DefinitionFilter `yaml:",inline"`
+	Trigger          string `yaml:"trigger"`
+	Action           string `yaml:"action"`
 }
 
 // DefinitionMappings defines custom mappings.
diff --git a/shared/definition_test.go b/shared/definition_test.go
index a4099d9..8d84dad 100644
--- a/shared/definition_test.go
+++ b/shared/definition_test.go
@@ -6,6 +6,7 @@ import (
 
 	"github.com/lxc/lxd/shared"
 	"github.com/stretchr/testify/require"
+	yaml "gopkg.in/yaml.v2"
 )
 
 func TestSetDefinitionDefaults(t *testing.T) {
@@ -486,3 +487,19 @@ func TestDefinitionSetValue(t *testing.T) {
 	require.NoError(t, err)
 	require.Equal(t, true, d.Source.IgnoreRelease)
 }
+
+func TestDefinitionFilter(t *testing.T) {
+	input := `packages:
+  sets:
+  - packages:
+    - foo
+    architectures:
+    - amd64`
+	def := Definition{}
+
+	err := yaml.Unmarshal([]byte(input), &def)
+	require.NoError(t, err)
+
+	require.Contains(t, def.Packages.Sets[0].Packages, "foo")
+	require.Contains(t, def.Packages.Sets[0].Architectures, "amd64")
+}


More information about the lxc-devel mailing list