From ff970fa06367a6fc7ffa27ae75742c3bc2b1b936 Mon Sep 17 00:00:00 2001 From: Sohan Kunkerkar Date: Mon, 26 Oct 2020 00:30:49 -0400 Subject: [PATCH] tests/positive/general: add test for merging multiple base configs --- tests/positive/general/general.go | 101 ++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/tests/positive/general/general.go b/tests/positive/general/general.go index ff7722f715..c58be0568c 100644 --- a/tests/positive/general/general.go +++ b/tests/positive/general/general.go @@ -41,8 +41,40 @@ func init() { register.Register(register.PositiveTest, AppendConfigWithRemoteConfigData()) register.Register(register.PositiveTest, VersionOnlyConfig()) register.Register(register.PositiveTest, EmptyUserdata()) + register.Register(register.PositiveTest, VerifyMergingOfMultipleBaseConfigs()) } +var ( + baseConfig = []byte(`{ + "ignition": { "version": "3.0.0" }, + "storage": { + "files": [{ + "path": "/foo/bar", + "contents": { "source": "data:,base%20config%0A" } + }] + } + }`) + + baseConfig2 = []byte(`{ + "ignition": { "version": "3.0.0" }, + "storage": { + "files": [{ + "path": "/foo/bar2", + "contents": { "source": "data:,base%20config2%0A" } + }] + } + }`) + platformConfig = []byte(`{ + "ignition": { "version": "3.0.0" }, + "storage": { + "files": [{ + "path": "/foo/bar3", + "contents": { "source": "data:,platform%20config%0A" } + }] + } + }`) +) + func ReformatFilesystemAndWriteFile() types.Test { name := "genernal.reformat.withfile" in := types.GetBaseDisk() @@ -706,3 +738,72 @@ func EmptyUserdata() types.Test { ConfigShouldBeBad: true, } } + +// VerifyMergingOfMultipleBaseConfigs checks if multiple +// base configs and/or platform configs are merged in the +// right order. +func VerifyMergingOfMultipleBaseConfigs() types.Test { + name := "merge.multiple.base.configs" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + config := `{ + "ignition": {"version": "$version"} + }` + configMinVersion := "3.0.0" + var systemFiles []types.File + + systemFiles = append(systemFiles, types.File{ + Node: types.Node{ + Name: "40-base.ign", + Directory: "base.d", + }, + Contents: string(baseConfig), + }, types.File{ + Node: types.Node{ + Name: "50-base2.ign", + Directory: "base.d", + }, + Contents: string(baseConfig2), + }, types.File{ + Node: types.Node{ + Name: "10-plaform.ign", + Directory: "base.platform.d/file", + }, + Contents: string(platformConfig), + }) + out[0].Partitions.AddFiles("ROOT", []types.File{ + { + Node: types.Node{ + Name: "bar", + Directory: "foo", + }, + Contents: "base config\n", + }, + }) + out[0].Partitions.AddFiles("ROOT", []types.File{ + { + Node: types.Node{ + Name: "bar2", + Directory: "foo", + }, + Contents: "base config2\n", + }, + }) + out[0].Partitions.AddFiles("ROOT", []types.File{ + { + Node: types.Node{ + Name: "bar3", + Directory: "foo", + }, + Contents: "platform config\n", + }, + }) + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + SystemDirFiles: systemFiles, + ConfigMinVersion: configMinVersion, + } +}