From 4d0aa39a3dd2a89f2165fced95c5c5aae72771a9 Mon Sep 17 00:00:00 2001 From: Steven Presti Date: Wed, 1 Mar 2023 10:49:51 -0500 Subject: [PATCH 1/2] test_constants: move all tests to packages they are testing --- translate/v23tov30/v23tov30_test.go | 205 ++ translate/v24tov31/v24tov31_test.go | 201 ++ translate/v30tov22/v30tov22_test.go | 42 + translate/v31tov22/v31tov22_test.go | 43 + translate/v31tov24/v31tov24_test.go | 43 + translate/v32tov22/v32tov22_test.go | 43 + translate/v32tov24/v32tov24_test.go | 43 + translate/v32tov31/v32tov31_test.go | 105 + translate/v33tov32/v33tov32_test.go | 77 + translate/v34tov33/v34tov33_test.go | 165 ++ translate_test.go | 2753 --------------------------- util/test_constants.go | 1996 +++++++++++++++++++ 12 files changed, 2963 insertions(+), 2753 deletions(-) create mode 100644 translate/v23tov30/v23tov30_test.go create mode 100644 translate/v24tov31/v24tov31_test.go create mode 100644 translate/v30tov22/v30tov22_test.go create mode 100644 translate/v31tov22/v31tov22_test.go create mode 100644 translate/v31tov24/v31tov24_test.go create mode 100644 translate/v32tov22/v32tov22_test.go create mode 100644 translate/v32tov24/v32tov24_test.go create mode 100644 translate/v32tov31/v32tov31_test.go create mode 100644 translate/v33tov32/v33tov32_test.go create mode 100644 translate/v34tov33/v34tov33_test.go delete mode 100644 translate_test.go create mode 100644 util/test_constants.go diff --git a/translate/v23tov30/v23tov30_test.go b/translate/v23tov30/v23tov30_test.go new file mode 100644 index 0000000..2c287d4 --- /dev/null +++ b/translate/v23tov30/v23tov30_test.go @@ -0,0 +1,205 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v23tov30 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types2_3 "github.com/coreos/ignition/config/v2_3/types" + "github.com/stretchr/testify/assert" +) + +// Configs using _all_ the (undeprecated) fields +type input2_3 struct { + cfg types2_3.Config + fsMap map[string]string +} + +func TestCheck2_3(t *testing.T) { + goodConfigs := []input2_3{ + { + util.ExhaustiveConfig2_3, + util.ExhaustiveMap, + }, + } + badConfigs := []input2_3{ + {}, // empty config has no version, fails validation + { + // need a map for filesystems + util.ExhaustiveConfig2_3, + nil, + }, + } + for i, e := range goodConfigs { + if err := Check2_3(e.cfg, e.fsMap); err != nil { + t.Errorf("Good config test %d: got %v, expected nil", i, err) + } + } + for i, e := range badConfigs { + if err := Check2_3(e.cfg, e.fsMap); err == nil { + t.Errorf("Bad config test %d: got ok, expected: %v", i, err) + } + } +} + +func TestTranslate2_3to3_0(t *testing.T) { + res, err := Translate(util.ExhaustiveConfig2_3, util.ExhaustiveMap) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.ExhaustiveConfig3_0, res) +} + +func TestRemoveDuplicateFilesUnitsUsers2_3(t *testing.T) { + mode := 420 + testDataOld := "data:,old" + testDataNew := "data:,new" + testIgn2Config := types2_3.Config{} + + // file test, add a duplicate file and see if the newest one is preserved + fileOld := types2_3.File{ + Node: types2_3.Node{ + Filesystem: "root", Path: "/etc/testfileconfig", + }, + FileEmbedded1: types2_3.FileEmbedded1{ + Contents: types2_3.FileContents{ + Source: testDataOld, + }, + Mode: &mode, + }, + } + testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileOld) + + fileNew := types2_3.File{ + Node: types2_3.Node{ + Filesystem: "root", Path: "/etc/testfileconfig", + }, + FileEmbedded1: types2_3.FileEmbedded1{ + Contents: types2_3.FileContents{ + Source: testDataNew, + }, + Mode: &mode, + }, + } + testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileNew) + + // unit test, add three units and three dropins with the same name as follows: + // unitOne: + // contents: old + // dropin: + // name: one + // contents: old + // unitTwo: + // dropin: + // name: one + // contents: new + // unitThree: + // contents: new + // dropin: + // name: two + // contents: new + // Which should result in: + // unitFinal: + // contents: new + // dropin: + // - name: one + // contents: new + // - name: two + // contents: new + // + unitName := "testUnit" + dropinNameOne := "one" + dropinNameTwo := "two" + dropinOne := types2_3.SystemdDropin{ + Contents: testDataOld, + Name: dropinNameOne, + } + dropinTwo := types2_3.SystemdDropin{ + Contents: testDataNew, + Name: dropinNameOne, + } + dropinThree := types2_3.SystemdDropin{ + Contents: testDataNew, + Name: dropinNameTwo, + } + + unitOne := types2_3.Unit{ + Contents: testDataOld, + Name: unitName, + } + unitOne.Dropins = append(unitOne.Dropins, dropinOne) + testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitOne) + + unitTwo := types2_3.Unit{ + Name: unitName, + } + unitTwo.Dropins = append(unitTwo.Dropins, dropinTwo) + testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitTwo) + + unitThree := types2_3.Unit{ + Contents: testDataNew, + Name: unitName, + } + unitThree.Dropins = append(unitThree.Dropins, dropinThree) + testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitThree) + + // user test, add a duplicate user and see if it is deduplicated but ssh keys from both are preserved + userName := "testUser" + userOne := types2_3.PasswdUser{ + Name: userName, + SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ + "one", + "two", + }, + } + userTwo := types2_3.PasswdUser{ + Name: userName, + SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ + "three", + }, + } + userThree := types2_3.PasswdUser{ + Name: "userThree", + SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ + "four", + }, + } + testIgn2Config.Passwd.Users = append(testIgn2Config.Passwd.Users, userOne, userTwo, userThree) + + convertedIgn2Config, err := RemoveDuplicateFilesUnitsUsers(testIgn2Config) + assert.NoError(t, err) + + expectedIgn2Config := types2_3.Config{} + expectedIgn2Config.Storage.Files = append(expectedIgn2Config.Storage.Files, fileNew) + unitExpected := types2_3.Unit{ + Contents: testDataNew, + Name: unitName, + } + unitExpected.Dropins = append(unitExpected.Dropins, dropinThree) + unitExpected.Dropins = append(unitExpected.Dropins, dropinTwo) + expectedIgn2Config.Systemd.Units = append(expectedIgn2Config.Systemd.Units, unitExpected) + expectedMergedUser := types2_3.PasswdUser{ + Name: userName, + SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ + "three", + "one", + "two", + }, + } + expectedIgn2Config.Passwd.Users = append(expectedIgn2Config.Passwd.Users, userThree, expectedMergedUser) + + assert.Equal(t, expectedIgn2Config, convertedIgn2Config) +} diff --git a/translate/v24tov31/v24tov31_test.go b/translate/v24tov31/v24tov31_test.go new file mode 100644 index 0000000..c38978c --- /dev/null +++ b/translate/v24tov31/v24tov31_test.go @@ -0,0 +1,201 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v24tov31 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types2_4 "github.com/coreos/ignition/config/v2_4/types" + "github.com/stretchr/testify/assert" +) + +type input2_4 struct { + cfg types2_4.Config + fsMap map[string]string +} + +func TestCheck2_4(t *testing.T) { + goodConfigs := []input2_4{ + { + util.ExhaustiveConfig2_4, + util.ExhaustiveMap, + }, + } + badConfigs := []input2_4{ + {}, // empty config has no version, fails validation + { + // need a map for filesystems + util.ExhaustiveConfig2_4, + nil, + }, + } + for i, e := range goodConfigs { + if err := Check2_4(e.cfg, e.fsMap); err != nil { + t.Errorf("Good config test %d: got %v, expected nil", i, err) + } + } + for i, e := range badConfigs { + if err := Check2_4(e.cfg, e.fsMap); err == nil { + t.Errorf("Bad config test %d: got ok, expected: %v", i, err) + } + } +} +func TestTranslate2_4to3_1(t *testing.T) { + res, err := Translate(util.ExhaustiveConfig2_4, util.ExhaustiveMap) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.NonexhaustiveConfig3_1, res) +} +func TestRemoveDuplicateFilesUnitsUsers2_4(t *testing.T) { + mode := 420 + testDataOld := "data:,old" + testDataNew := "data:,new" + testIgn2Config := types2_4.Config{} + + // file test, add a duplicate file and see if the newest one is preserved + fileOld := types2_4.File{ + Node: types2_4.Node{ + Filesystem: "root", Path: "/etc/testfileconfig", + }, + FileEmbedded1: types2_4.FileEmbedded1{ + Contents: types2_4.FileContents{ + Source: testDataOld, + }, + Mode: &mode, + }, + } + testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileOld) + + fileNew := types2_4.File{ + Node: types2_4.Node{ + Filesystem: "root", Path: "/etc/testfileconfig", + }, + FileEmbedded1: types2_4.FileEmbedded1{ + Contents: types2_4.FileContents{ + Source: testDataNew, + }, + Mode: &mode, + }, + } + testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileNew) + + // unit test, add three units and three dropins with the same name as follows: + // unitOne: + // contents: old + // dropin: + // name: one + // contents: old + // unitTwo: + // dropin: + // name: one + // contents: new + // unitThree: + // contents: new + // dropin: + // name: two + // contents: new + // Which should result in: + // unitFinal: + // contents: new + // dropin: + // - name: one + // contents: new + // - name: two + // contents: new + // + unitName := "testUnit" + dropinNameOne := "one" + dropinNameTwo := "two" + dropinOne := types2_4.SystemdDropin{ + Contents: testDataOld, + Name: dropinNameOne, + } + dropinTwo := types2_4.SystemdDropin{ + Contents: testDataNew, + Name: dropinNameOne, + } + dropinThree := types2_4.SystemdDropin{ + Contents: testDataNew, + Name: dropinNameTwo, + } + + unitOne := types2_4.Unit{ + Contents: testDataOld, + Name: unitName, + } + unitOne.Dropins = append(unitOne.Dropins, dropinOne) + testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitOne) + + unitTwo := types2_4.Unit{ + Name: unitName, + } + unitTwo.Dropins = append(unitTwo.Dropins, dropinTwo) + testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitTwo) + + unitThree := types2_4.Unit{ + Contents: testDataNew, + Name: unitName, + } + unitThree.Dropins = append(unitThree.Dropins, dropinThree) + testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitThree) + + // user test, add a duplicate user and see if it is deduplicated but ssh keys from both are preserved + userName := "testUser" + userOne := types2_4.PasswdUser{ + Name: userName, + SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ + "one", + "two", + }, + } + userTwo := types2_4.PasswdUser{ + Name: userName, + SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ + "three", + }, + } + userThree := types2_4.PasswdUser{ + Name: "userThree", + SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ + "four", + }, + } + testIgn2Config.Passwd.Users = append(testIgn2Config.Passwd.Users, userOne, userTwo, userThree) + + convertedIgn2Config, err := RemoveDuplicateFilesUnitsUsers(testIgn2Config) + assert.NoError(t, err) + + expectedIgn2Config := types2_4.Config{} + expectedIgn2Config.Storage.Files = append(expectedIgn2Config.Storage.Files, fileNew) + unitExpected := types2_4.Unit{ + Contents: testDataNew, + Name: unitName, + } + unitExpected.Dropins = append(unitExpected.Dropins, dropinThree) + unitExpected.Dropins = append(unitExpected.Dropins, dropinTwo) + expectedIgn2Config.Systemd.Units = append(expectedIgn2Config.Systemd.Units, unitExpected) + expectedMergedUser := types2_4.PasswdUser{ + Name: userName, + SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ + "three", + "one", + "two", + }, + } + expectedIgn2Config.Passwd.Users = append(expectedIgn2Config.Passwd.Users, userThree, expectedMergedUser) + assert.Equal(t, expectedIgn2Config, convertedIgn2Config) +} diff --git a/translate/v30tov22/v30tov22_test.go b/translate/v30tov22/v30tov22_test.go new file mode 100644 index 0000000..486e52b --- /dev/null +++ b/translate/v30tov22/v30tov22_test.go @@ -0,0 +1,42 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v30tov22 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_0 "github.com/coreos/ignition/v2/config/v3_0/types" + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_0to2_2(t *testing.T) { + emptyConfig := types3_0.Config{ + Ignition: types3_0.Ignition{ + Version: "3.0.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.DowntranslateConfig3_0) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.ExhaustiveConfig2_2, res) +} diff --git a/translate/v31tov22/v31tov22_test.go b/translate/v31tov22/v31tov22_test.go new file mode 100644 index 0000000..aaca966 --- /dev/null +++ b/translate/v31tov22/v31tov22_test.go @@ -0,0 +1,43 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v31tov22 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_1 "github.com/coreos/ignition/v2/config/v3_1/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_1to2_2(t *testing.T) { + emptyConfig := types3_1.Config{ + Ignition: types3_1.Ignition{ + Version: "3.1.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.DowntranslateConfig3_1) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.ExhaustiveConfig2_2, res) +} diff --git a/translate/v31tov24/v31tov24_test.go b/translate/v31tov24/v31tov24_test.go new file mode 100644 index 0000000..5db1ee6 --- /dev/null +++ b/translate/v31tov24/v31tov24_test.go @@ -0,0 +1,43 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v31tov24 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_1 "github.com/coreos/ignition/v2/config/v3_1/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_1to2_4(t *testing.T) { + emptyConfig := types3_1.Config{ + Ignition: types3_1.Ignition{ + Version: "3.1.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.NonexhaustiveConfig3_1) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.ExhaustiveConfig2_4, res) +} diff --git a/translate/v32tov22/v32tov22_test.go b/translate/v32tov22/v32tov22_test.go new file mode 100644 index 0000000..e741c47 --- /dev/null +++ b/translate/v32tov22/v32tov22_test.go @@ -0,0 +1,43 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v32tov22 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_2to2_2(t *testing.T) { + emptyConfig := types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.DowntranslateConfig3_2) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.ExhaustiveConfig2_2, res) +} diff --git a/translate/v32tov24/v32tov24_test.go b/translate/v32tov24/v32tov24_test.go new file mode 100644 index 0000000..74ff9ef --- /dev/null +++ b/translate/v32tov24/v32tov24_test.go @@ -0,0 +1,43 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v32tov24 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_2to2_4(t *testing.T) { + emptyConfig := types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.NonexhaustiveConfig3_2) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.ExhaustiveConfig2_4, res) +} diff --git a/translate/v32tov31/v32tov31_test.go b/translate/v32tov31/v32tov31_test.go new file mode 100644 index 0000000..cecca7c --- /dev/null +++ b/translate/v32tov31/v32tov31_test.go @@ -0,0 +1,105 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v32tov31 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_2to3_1(t *testing.T) { + emptyConfig := types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.NonexhaustiveConfig3_2) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.NonexhaustiveConfig3_1, res) + + _, err = Translate(types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + Storage: types3_2.Storage{ + Luks: []types3_2.Luks{ + { + Name: "z", + Device: util.StrP("/dev/z"), + }, + }, + }, + }) + assert.Error(t, err) + _, err = Translate(types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + Storage: types3_2.Storage{ + Disks: []types3_2.Disk{ + { + Device: "/dev/a", + Partitions: []types3_2.Partition{ + { + Label: util.StrP("z"), + Resize: util.BoolP(true), + }, + }, + }, + }, + }, + }) + assert.Error(t, err) + _, err = Translate(types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + Passwd: types3_2.Passwd{ + Users: []types3_2.PasswdUser{ + { + Name: "z", + ShouldExist: util.BoolPStrict(false), + }, + }, + }, + }) + assert.Error(t, err) + _, err = Translate(types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + Passwd: types3_2.Passwd{ + Groups: []types3_2.PasswdGroup{ + { + Name: "z", + ShouldExist: util.BoolPStrict(false), + }, + }, + }, + }) + assert.Error(t, err) +} diff --git a/translate/v33tov32/v33tov32_test.go b/translate/v33tov32/v33tov32_test.go new file mode 100644 index 0000000..353f6a9 --- /dev/null +++ b/translate/v33tov32/v33tov32_test.go @@ -0,0 +1,77 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v33tov32 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + + types3_3 "github.com/coreos/ignition/v2/config/v3_3/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_3to3_2(t *testing.T) { + emptyConfig := types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.NonexhaustiveConfig3_3) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.NonexhaustiveConfig3_2, res) + + _, err = Translate(types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + KernelArguments: types3_3.KernelArguments{ + ShouldExist: []types3_3.KernelArgument{"foo"}, + }, + }) + assert.Error(t, err) + _, err = Translate(types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + KernelArguments: types3_3.KernelArguments{ + ShouldNotExist: []types3_3.KernelArgument{"foo"}, + }, + }) + assert.Error(t, err) + _, err = Translate(types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + Storage: types3_3.Storage{ + Filesystems: []types3_3.Filesystem{ + { + Device: "/dev/foo", + Format: util.StrP("util.None"), + }, + }, + }, + }) + assert.Error(t, err) +} diff --git a/translate/v34tov33/v34tov33_test.go b/translate/v34tov33/v34tov33_test.go new file mode 100644 index 0000000..266e9c0 --- /dev/null +++ b/translate/v34tov33/v34tov33_test.go @@ -0,0 +1,165 @@ +// Copyright 2020 Red Hat, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v34tov33 + +import ( + "testing" + + "github.com/coreos/ign-converter/util" + types3_4 "github.com/coreos/ignition/v2/config/v3_4/types" + + "github.com/stretchr/testify/assert" +) + +func TestTranslate3_4to3_3(t *testing.T) { + emptyConfig := types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + } + + _, err := Translate(emptyConfig) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + + res, err := Translate(util.NonexhaustiveConfig3_4) + if err != nil { + t.Fatalf("Failed translation: %v", err) + } + assert.Equal(t, util.DowntranslateConfig3_3, res) + + _, err = Translate(types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Luks: []types3_4.Luks{ + { + Device: util.StrP("/dev/sda"), + Clevis: types3_4.Clevis{ + Tang: []types3_4.Tang{ + { + URL: "http://example.com", + Thumbprint: util.StrP("z"), + Advertisement: util.StrP("{\"payload\": \"eyJrZXlzIjogW3siYWxnIjogIkVTNTEyIiwgImt0eSI6ICJFQyIsICJjcnYiOiAiUC01MjEiLCAieCI6ICJBRGFNajJmazNob21CWTF5WElSQ21uRk92cmUzOFZjdHMwTnNHeDZ6RWNxdEVXcjh5ekhUMkhfa2hjNGpSa19FQWFLdjNrd2RjZ05sOTBLcGhfMGYyQ190IiwgInkiOiAiQUZ2d1UyeGJ5T1RydWo0V1NtcVlqN2wtcUVTZmhWakdCNTI1Q2d6d0NoZUZRRTBvb1o3STYyamt3NkRKQ05yS3VPUDRsSEhicm8tYXhoUk9MSXNJVExvNCIsICJrZXlfb3BzIjogWyJ2ZXJpZnkiXX0sIHsiYWxnIjogIkVDTVIiLCAia3R5IjogIkVDIiwgImNydiI6ICJQLTUyMSIsICJ4IjogIkFOZDVYcTFvZklUbTdNWG16OUY0VVRSYmRNZFNIMl9XNXczTDVWZ0w3b3hwdmpyM0hkLXNLNUVqd3A1V2swMnJMb3NXVUJjYkZyZEhjZFJTTVJoZlVFTFIiLCAieSI6ICJBRVVaVlVZWkFBY2hVcmdoX3poaTV3SUUzeTEycGwzeWhqUk5LcGpSdW9tUFhKaDhRaFhXRmRWZEtMUlEwX1lwUjNOMjNSUk1pU1lvWlg0Qm42QnlrQVBMIiwgImtleV9vcHMiOiBbImRlcml2ZUtleSJdfV19\", \"protected\": \"eyJhbGciOiJFUzUxMiIsImN0eSI6Imp3ay1zZXQranNvbiJ9\", \"signature\": \"APHfSyVzLwELwG0pMJyIP74gWvhHUvDtv0SESBxA2uOdSXq76IdWHW2xvCZDdlNan8pnqUvEedPZjf_vdKBw9MTXAPMkRxVnu64HepKwlrzzm_zG2R4CHpoCOsGgjH9-acYxg-Vha63oMojv3_bV0VHg-NbzNLaxietgYplstvcNIwkv\"}"), + }, + }, + }, + }, + }, + }, + }) + assert.Error(t, err) + + _, err = Translate(types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Luks: []types3_4.Luks{ + { + Device: util.StrP("/dev/sda"), + Discard: util.BoolP(true), + }, + }, + }, + }) + assert.Error(t, err) + + _, err = Translate(types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Luks: []types3_4.Luks{ + { + Device: util.StrP("/dev/sda"), + OpenOptions: []types3_4.OpenOption{"foo"}, + }, + }, + }, + }) + assert.Error(t, err) + + _, err = Translate(types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Files: []types3_4.File{ + { + Node: types3_4.Node{ + Path: "/root/file.txt", + }, + + FileEmbedded1: types3_4.FileEmbedded1{ + Mode: util.IntP(01777), + }, + }, + }, + }, + }) + + assert.Error(t, err) + + _, err = Translate(types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Directories: []types3_4.Directory{ + { + Node: types3_4.Node{ + Path: "/rootdir", + Overwrite: util.BoolP(true), + User: types3_4.NodeUser{ + ID: util.IntP(1000), + }, + Group: types3_4.NodeGroup{ + Name: util.StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_4.DirectoryEmbedded1{ + Mode: util.IntP(01777), + }, + }, + }, + }, + }) + + assert.Error(t, err) + + _, err = Translate(types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Files: []types3_4.File{ + { + Node: types3_4.Node{ + Path: "/path", + }, + FileEmbedded1: types3_4.FileEmbedded1{ + Contents: types3_4.Resource{ + Source: util.StrP("arn:aws:s3:us-west-1:123456789012:accesspoint/test/object/some/path"), + }, + }, + }, + }, + }, + }) + assert.Error(t, err) +} diff --git a/translate_test.go b/translate_test.go deleted file mode 100644 index f4a9c82..0000000 --- a/translate_test.go +++ /dev/null @@ -1,2753 +0,0 @@ -// Copyright 2020 Red Hat, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ignconverter - -import ( - "testing" - - types2_2 "github.com/coreos/ignition/config/v2_2/types" - types2_3 "github.com/coreos/ignition/config/v2_3/types" - types2_4 "github.com/coreos/ignition/config/v2_4/types" - types3_0 "github.com/coreos/ignition/v2/config/v3_0/types" - types3_1 "github.com/coreos/ignition/v2/config/v3_1/types" - types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" - types3_3 "github.com/coreos/ignition/v2/config/v3_3/types" - types3_4 "github.com/coreos/ignition/v2/config/v3_4/types" - - "github.com/stretchr/testify/assert" - - "github.com/coreos/ign-converter/translate/v23tov30" - "github.com/coreos/ign-converter/translate/v24tov31" - "github.com/coreos/ign-converter/translate/v30tov22" - "github.com/coreos/ign-converter/translate/v31tov22" - "github.com/coreos/ign-converter/translate/v31tov24" - "github.com/coreos/ign-converter/translate/v32tov22" - "github.com/coreos/ign-converter/translate/v32tov24" - "github.com/coreos/ign-converter/translate/v32tov31" - "github.com/coreos/ign-converter/translate/v33tov32" - "github.com/coreos/ign-converter/translate/v34tov33" - "github.com/coreos/ign-converter/util" -) - -// Configs using _all_ the (undeprecated) fields -var ( - aSha512Hash = "sha512-c6100de5624cfb3c109909948ecb8d703bbddcd3725b8bd43dcf2cee6d2f5dc990a757575e0306a8e8eea354bcd7cfac354da911719766225668fe5430477fa8" - aUUID = "9d6e42cd-dcef-4177-b4c6-2a0c979e3d82" - exhaustiveMap = map[string]string{ - "var": "/var", - "/var": "/var", - } - - exhaustiveConfig2_3 = types2_3.Config{ - Ignition: types2_3.Ignition{ - Version: "2.3.0", - Config: types2_3.IgnitionConfig{ - Append: []types2_3.ConfigReference{ - { - Source: "https://example.com", - Verification: types2_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: &types2_3.ConfigReference{ - Source: "https://example.com", - Verification: types2_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types2_3.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types2_3.Security{ - TLS: types2_3.TLS{ - CertificateAuthorities: []types2_3.CaReference{ - { - Source: "https://example.com", - Verification: types2_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - // Proxy is unsupported - }, - Storage: types2_3.Storage{ - Disks: []types2_3.Disk{ - { - Device: "/dev/sda", - WipeTable: true, - Partitions: []types2_3.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: aUUID, - GUID: aUUID, - WipePartitionEntry: true, - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types2_3.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types2_3.Device{"/dev/sdb", "/dev/sdc"}, - Spares: 1, - Options: []types2_3.RaidOption{"foobar"}, - }, - }, - Filesystems: []types2_3.Filesystem{ - { - Name: "/var", - Mount: &types2_3.Mount{ - Device: "/dev/disk/by-partlabel/var", - Format: "xfs", - WipeFilesystem: true, - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types2_3.MountOption{"rw"}, - }, - }, - }, - Files: []types2_3.File{ - { - Node: types2_3.Node{ - Filesystem: "/var", - Path: "/varfile", - Overwrite: util.BoolPStrict(false), - User: &types2_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_3.NodeGroup{ - Name: "groupname", - }, - }, - FileEmbedded1: types2_3.FileEmbedded1{ - Append: true, - Mode: util.IntP(420), - Contents: types2_3.FileContents{ - Compression: "gzip", - Source: "https://example.com", - Verification: types2_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - { - Node: types2_3.Node{ - Filesystem: "root", - Path: "/empty", - }, - FileEmbedded1: types2_3.FileEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Directories: []types2_3.Directory{ - { - Node: types2_3.Node{ - Filesystem: "root", - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: &types2_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_3.NodeGroup{ - Name: "groupname", - }, - }, - DirectoryEmbedded1: types2_3.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types2_3.Link{ - { - Node: types2_3.Node{ - Filesystem: "root", - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: &types2_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_3.NodeGroup{ - Name: "groupname", - }, - }, - LinkEmbedded1: types2_3.LinkEmbedded1{ - Hard: false, - Target: "/foobar", - }, - }, - }, - }, - } - - exhaustiveConfig2_4 = types2_4.Config{ - Ignition: types2_4.Ignition{ - Version: "2.4.0", - Config: types2_4.IgnitionConfig{ - Append: []types2_4.ConfigReference{ - { - Source: "https://example.com", - Verification: types2_4.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: &types2_4.ConfigReference{ - Source: "https://example.com", - Verification: types2_4.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types2_4.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types2_4.Security{ - TLS: types2_4.TLS{ - CertificateAuthorities: []types2_4.CaReference{ - { - Source: "https://example.com", - Verification: types2_4.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - Proxy: types2_4.Proxy{ - HTTPProxy: "https://proxy.example.net/", - HTTPSProxy: "https://secure.proxy.example.net/", - NoProxy: []types2_4.NoProxyItem{ - "www.example.net", - "www.example2.net", - }, - }, - }, - Storage: types2_4.Storage{ - Disks: []types2_4.Disk{ - { - Device: "/dev/sda", - WipeTable: true, - Partitions: []types2_4.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: aUUID, - GUID: aUUID, - WipePartitionEntry: true, - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types2_4.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types2_4.Device{"/dev/sdb", "/dev/sdc"}, - Spares: 1, - Options: []types2_4.RaidOption{"foobar"}, - }, - }, - Filesystems: []types2_4.Filesystem{ - { - Name: "/var", - Mount: &types2_4.Mount{ - Device: "/dev/disk/by-partlabel/var", - Format: "xfs", - WipeFilesystem: true, - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types2_4.MountOption{"rw"}, - }, - }, - }, - Files: []types2_4.File{ - { - Node: types2_4.Node{ - Filesystem: "/var", - Path: "/varfile", - Overwrite: util.BoolPStrict(false), - User: &types2_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_4.NodeGroup{ - Name: "groupname", - }, - }, - FileEmbedded1: types2_4.FileEmbedded1{ - Append: true, - Mode: util.IntP(420), - Contents: types2_4.FileContents{ - Compression: "gzip", - Source: "https://example.com", - Verification: types2_4.Verification{ - Hash: &aSha512Hash, - }, - HTTPHeaders: types2_4.HTTPHeaders{ - types2_4.HTTPHeader{ - Name: "Authorization", - Value: "Basic YWxhZGRpbjpvcGVuc2VzYW1l", - }, - types2_4.HTTPHeader{ - Name: "User-Agent", - Value: "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)", - }, - }, - }, - }, - }, - { - Node: types2_4.Node{ - Filesystem: "root", - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types2_4.FileEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Directories: []types2_4.Directory{ - { - Node: types2_4.Node{ - Filesystem: "root", - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: &types2_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_4.NodeGroup{ - Name: "groupname", - }, - }, - DirectoryEmbedded1: types2_4.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types2_4.Link{ - { - Node: types2_4.Node{ - Filesystem: "root", - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: &types2_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_4.NodeGroup{ - Name: "groupname", - }, - }, - LinkEmbedded1: types2_4.LinkEmbedded1{ - Hard: false, - Target: "/foobar", - }, - }, - }, - }, - } - - exhaustiveConfig3_0 = types3_0.Config{ - Ignition: types3_0.Ignition{ - Version: "3.0.0", - Config: types3_0.IgnitionConfig{ - Merge: []types3_0.ConfigReference{ - { - Source: util.StrP("https://example.com"), - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_0.ConfigReference{ - Source: util.StrP("https://example.com"), - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_0.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_0.Security{ - TLS: types3_0.TLS{ - CertificateAuthorities: []types3_0.CaReference{ - { - Source: "https://example.com", - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - // Proxy is unsupported - }, - Storage: types3_0.Storage{ - Disks: []types3_0.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_0.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_0.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types3_0.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_0.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_0.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_0.FilesystemOption{"rw"}, - }, - }, - Files: []types3_0.File{ - { - Node: types3_0.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_0.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_0.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_0.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_0.FileContents{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - { - Node: types3_0.Node{ - Path: "/empty", - Overwrite: util.BoolPStrict(true), - }, - FileEmbedded1: types3_0.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_0.FileContents{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_0.Directory{ - { - Node: types3_0.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_0.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_0.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_0.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_0.Link{ - { - Node: types3_0.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_0.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_0.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_0.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: "/foobar", - }, - }, - }, - }, - } - - exhaustiveConfig2_2 = types2_2.Config{ - Ignition: types2_2.Ignition{ - Version: "2.2.0", - Config: types2_2.IgnitionConfig{ - Append: []types2_2.ConfigReference{ - { - Source: "https://example.com", - Verification: types2_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: &types2_2.ConfigReference{ - Source: "https://example.com", - Verification: types2_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types2_2.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types2_2.Security{ - TLS: types2_2.TLS{ - CertificateAuthorities: []types2_2.CaReference{ - { - Source: "https://example.com", - Verification: types2_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - // Proxy is unsupported - }, - Storage: types2_2.Storage{ - Disks: []types2_2.Disk{ - { - Device: "/dev/sda", - WipeTable: true, - Partitions: []types2_2.Partition{ - { - Label: "var", - Number: 1, - TypeGUID: aUUID, - GUID: aUUID, - }, - }, - }, - }, - Raid: []types2_2.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types2_2.Device{"/dev/sdb", "/dev/sdc"}, - Spares: 1, - Options: []types2_2.RaidOption{"foobar"}, - }, - }, - Filesystems: []types2_2.Filesystem{ - { - Name: "/var", - Mount: &types2_2.Mount{ - Device: "/dev/disk/by-partlabel/var", - Format: "xfs", - WipeFilesystem: true, - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types2_2.MountOption{"rw"}, - }, - }, - }, - Files: []types2_2.File{ - { - Node: types2_2.Node{ - Filesystem: "/var", - Path: "/varfile", - Overwrite: util.BoolPStrict(false), - User: &types2_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_2.NodeGroup{ - Name: "groupname", - }, - }, - FileEmbedded1: types2_2.FileEmbedded1{ - Append: true, - Mode: util.IntP(420), - Contents: types2_2.FileContents{ - Compression: "gzip", - Source: "https://example.com", - Verification: types2_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - { - Node: types2_2.Node{ - Filesystem: "root", - Path: "/etc/motd", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types2_2.FileEmbedded1{ - Append: true, - Mode: util.IntP(420), - Contents: types2_2.FileContents{ - Source: "data:text/plain;base64,Zm9vCg==", - }, - }, - }, - { - Node: types2_2.Node{ - Filesystem: "root", - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types2_2.FileEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Directories: []types2_2.Directory{ - { - Node: types2_2.Node{ - Filesystem: "root", - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: &types2_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_2.NodeGroup{ - Name: "groupname", - }, - }, - DirectoryEmbedded1: types2_2.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types2_2.Link{ - { - Node: types2_2.Node{ - Filesystem: "root", - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: &types2_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: &types2_2.NodeGroup{ - Name: "groupname", - }, - }, - LinkEmbedded1: types2_2.LinkEmbedded1{ - Hard: false, - Target: "/foobar", - }, - }, - }, - }, - } - - downtranslateConfig3_0 = types3_0.Config{ - Ignition: types3_0.Ignition{ - Version: "3.0.0", - Config: types3_0.IgnitionConfig{ - Merge: []types3_0.ConfigReference{ - { - Source: util.StrP("https://example.com"), - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_0.ConfigReference{ - Source: util.StrP("https://example.com"), - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_0.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_0.Security{ - TLS: types3_0.TLS{ - CertificateAuthorities: []types3_0.CaReference{ - { - Source: "https://example.com", - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - // Proxy is unsupported - }, - Storage: types3_0.Storage{ - Disks: []types3_0.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_0.Partition{ - { - Label: util.StrP("var"), - Number: 1, - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_0.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types3_0.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_0.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_0.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_0.FilesystemOption{"rw"}, - }, - }, - Files: []types3_0.File{ - { - Node: types3_0.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_0.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_0.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_0.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_0.FileContents{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_0.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - { - Node: types3_0.Node{ - Path: "/etc/motd", - // Test default append with overwrite unset - }, - FileEmbedded1: types3_0.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_0.FileContents{ - { - Source: util.StrP("data:text/plain;base64,Zm9vCg=="), - }, - }, - }, - }, - { - Node: types3_0.Node{ - Path: "/empty", - }, - FileEmbedded1: types3_0.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_0.FileContents{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_0.Directory{ - { - Node: types3_0.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_0.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_0.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_0.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_0.Link{ - { - Node: types3_0.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_0.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_0.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_0.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: "/foobar", - }, - }, - }, - }, - } - - nonexhaustiveConfig3_1 = types3_1.Config{ - Ignition: types3_1.Ignition{ - Version: "3.1.0", - Config: types3_1.IgnitionConfig{ - Merge: []types3_1.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_1.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_1.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_1.Security{ - TLS: types3_1.TLS{ - CertificateAuthorities: []types3_1.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - Proxy: types3_1.Proxy{ - HTTPProxy: util.StrP("https://proxy.example.net/"), - HTTPSProxy: util.StrP("https://secure.proxy.example.net/"), - NoProxy: []types3_1.NoProxyItem{ - "www.example.net", - "www.example2.net", - }, - }, - }, - Storage: types3_1.Storage{ - Disks: []types3_1.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_1.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_1.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types3_1.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_1.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_1.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_1.FilesystemOption{"rw"}, - }, - }, - Files: []types3_1.File{ - { - Node: types3_1.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_1.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_1.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_1.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_1.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - HTTPHeaders: types3_1.HTTPHeaders{ - types3_1.HTTPHeader{ - Name: "Authorization", - Value: util.StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), - }, - types3_1.HTTPHeader{ - Name: "User-Agent", - Value: util.StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), - }, - }, - }, - }, - }, - }, - { - Node: types3_1.Node{ - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types3_1.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_1.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_1.Directory{ - { - Node: types3_1.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_1.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_1.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_1.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_1.Link{ - { - Node: types3_1.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_1.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_1.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_1.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: "/foobar", - }, - }, - }, - }, - } - - downtranslateConfig3_1 = types3_1.Config{ - Ignition: types3_1.Ignition{ - Version: "3.1.0", - Config: types3_1.IgnitionConfig{ - Merge: []types3_1.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_1.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_1.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_1.Security{ - TLS: types3_1.TLS{ - CertificateAuthorities: []types3_1.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - // Proxy is unsupported - }, - Storage: types3_1.Storage{ - Disks: []types3_1.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_1.Partition{ - { - Label: util.StrP("var"), - Number: 1, - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_1.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types3_1.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_1.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_1.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_1.FilesystemOption{"rw"}, - }, - }, - Files: []types3_1.File{ - { - Node: types3_1.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_1.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_1.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_1.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_1.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_1.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - { - Node: types3_1.Node{ - Path: "/etc/motd", - // Test default append with overwrite unset - }, - FileEmbedded1: types3_1.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_1.Resource{ - { - Source: util.StrP("data:text/plain;base64,Zm9vCg=="), - }, - }, - }, - }, - { - Node: types3_1.Node{ - Path: "/empty", - }, - FileEmbedded1: types3_1.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_1.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_1.Directory{ - { - Node: types3_1.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_1.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_1.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_1.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_1.Link{ - { - Node: types3_1.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_1.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_1.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_1.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: "/foobar", - }, - }, - }, - }, - } - - nonexhaustiveConfig3_2 = types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - Config: types3_2.IgnitionConfig{ - Merge: []types3_2.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_2.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_2.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_2.Security{ - TLS: types3_2.TLS{ - CertificateAuthorities: []types3_2.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - Proxy: types3_2.Proxy{ - HTTPProxy: util.StrP("https://proxy.example.net/"), - HTTPSProxy: util.StrP("https://secure.proxy.example.net/"), - NoProxy: []types3_2.NoProxyItem{ - "www.example.net", - "www.example2.net", - }, - }, - }, - Storage: types3_2.Storage{ - Disks: []types3_2.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_2.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_2.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types3_2.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_2.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_2.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_2.FilesystemOption{"rw"}, - }, - }, - Files: []types3_2.File{ - { - Node: types3_2.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_2.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_2.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_2.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - HTTPHeaders: types3_2.HTTPHeaders{ - types3_2.HTTPHeader{ - Name: "Authorization", - Value: util.StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), - }, - types3_2.HTTPHeader{ - Name: "User-Agent", - Value: util.StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), - }, - }, - }, - }, - }, - }, - { - Node: types3_2.Node{ - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types3_2.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_2.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_2.Directory{ - { - Node: types3_2.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_2.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_2.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_2.Link{ - { - Node: types3_2.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_2.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_2.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: "/foobar", - }, - }, - }, - }, - } - - nonexhaustiveConfig3_3 = types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - Config: types3_3.IgnitionConfig{ - Merge: []types3_3.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_3.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_3.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_3.Security{ - TLS: types3_3.TLS{ - CertificateAuthorities: []types3_3.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - Proxy: types3_3.Proxy{ - HTTPProxy: util.StrP("https://proxy.example.net/"), - HTTPSProxy: util.StrP("https://secure.proxy.example.net/"), - NoProxy: []types3_3.NoProxyItem{ - "www.example.net", - "www.example2.net", - }, - }, - }, - Storage: types3_3.Storage{ - Disks: []types3_3.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_3.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_3.Raid{ - { - Name: "array", - Level: util.StrP("raid10"), - Devices: []types3_3.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_3.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_3.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_3.FilesystemOption{"rw"}, - }, - }, - Files: []types3_3.File{ - { - Node: types3_3.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_3.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_3.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_3.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - HTTPHeaders: types3_3.HTTPHeaders{ - types3_3.HTTPHeader{ - Name: "Authorization", - Value: util.StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), - }, - types3_3.HTTPHeader{ - Name: "User-Agent", - Value: util.StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), - }, - }, - }, - }, - }, - }, - { - Node: types3_3.Node{ - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types3_3.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_3.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_3.Directory{ - { - Node: types3_3.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_3.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_3.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_3.Link{ - { - Node: types3_3.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_3.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_3.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: util.StrP("/foobar"), - }, - }, - }, - }, - } - - downtranslateConfig3_2 = types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - Config: types3_2.IgnitionConfig{ - Merge: []types3_2.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_2.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_2.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_2.Security{ - TLS: types3_2.TLS{ - CertificateAuthorities: []types3_2.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - // Proxy is unsupported - }, - Storage: types3_2.Storage{ - Disks: []types3_2.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_2.Partition{ - { - Label: util.StrP("var"), - Number: 1, - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_2.Raid{ - { - Name: "array", - Level: "raid10", - Devices: []types3_2.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_2.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_2.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_2.FilesystemOption{"rw"}, - }, - }, - Files: []types3_2.File{ - { - Node: types3_2.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_2.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_2.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_2.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_2.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - { - Node: types3_2.Node{ - Path: "/etc/motd", - // Test default append with overwrite unset - }, - FileEmbedded1: types3_2.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_2.Resource{ - { - Source: util.StrP("data:text/plain;base64,Zm9vCg=="), - }, - }, - }, - }, - { - Node: types3_2.Node{ - Path: "/empty", - }, - FileEmbedded1: types3_2.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_2.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_2.Directory{ - { - Node: types3_2.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_2.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_2.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_2.Link{ - { - Node: types3_2.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_2.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_2.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_2.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: "/foobar", - }, - }, - }, - }, - } - - nonexhaustiveConfig3_4 = types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - Config: types3_4.IgnitionConfig{ - Merge: []types3_4.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_4.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_4.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_4.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_4.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_4.Security{ - TLS: types3_4.TLS{ - CertificateAuthorities: []types3_4.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_4.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - Proxy: types3_4.Proxy{ - HTTPProxy: util.StrP("https://proxy.example.net/"), - HTTPSProxy: util.StrP("https://secure.proxy.example.net/"), - NoProxy: []types3_4.NoProxyItem{ - "www.example.net", - "www.example2.net", - }, - }, - }, - Storage: types3_4.Storage{ - Disks: []types3_4.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_4.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_4.Raid{ - { - Name: "array", - Level: util.StrP("raid10"), - Devices: []types3_4.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_4.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_4.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_4.FilesystemOption{"rw"}, - }, - }, - Files: []types3_4.File{ - { - Node: types3_4.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_4.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_4.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_4.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_4.Verification{ - Hash: &aSha512Hash, - }, - HTTPHeaders: types3_4.HTTPHeaders{ - types3_4.HTTPHeader{ - Name: "Authorization", - Value: util.StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), - }, - types3_4.HTTPHeader{ - Name: "User-Agent", - Value: util.StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), - }, - }, - }, - }, - }, - }, - { - Node: types3_4.Node{ - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types3_4.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_4.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_4.Directory{ - { - Node: types3_4.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_4.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_4.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_4.Link{ - { - Node: types3_4.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_4.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_4.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: util.StrP("/foobar"), - }, - }, - }, - }, - } - - downtranslateConfig3_3 = types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - Config: types3_3.IgnitionConfig{ - Merge: []types3_3.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Replace: types3_3.Resource{ - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - Timeouts: types3_3.Timeouts{ - HTTPResponseHeaders: util.IntP(5), - HTTPTotal: util.IntP(10), - }, - Security: types3_3.Security{ - TLS: types3_3.TLS{ - CertificateAuthorities: []types3_3.Resource{ - { - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - }, - }, - }, - }, - Proxy: types3_3.Proxy{ - HTTPProxy: util.StrP("https://proxy.example.net/"), - HTTPSProxy: util.StrP("https://secure.proxy.example.net/"), - NoProxy: []types3_3.NoProxyItem{ - "www.example.net", - "www.example2.net", - }, - }, - }, - Storage: types3_3.Storage{ - Disks: []types3_3.Disk{ - { - Device: "/dev/sda", - WipeTable: util.BoolP(true), - Partitions: []types3_3.Partition{ - { - Label: util.StrP("var"), - Number: 1, - SizeMiB: util.IntP(5000), - StartMiB: util.IntP(2048), - TypeGUID: &aUUID, - GUID: &aUUID, - WipePartitionEntry: util.BoolP(true), - ShouldExist: util.BoolP(true), - }, - }, - }, - }, - Raid: []types3_3.Raid{ - { - Name: "array", - Level: util.StrP("raid10"), - Devices: []types3_3.Device{"/dev/sdb", "/dev/sdc"}, - Spares: util.IntP(1), - Options: []types3_3.RaidOption{"foobar"}, - }, - }, - Filesystems: []types3_3.Filesystem{ - { - Path: util.StrP("/var"), - Device: "/dev/disk/by-partlabel/var", - Format: util.StrP("xfs"), - WipeFilesystem: util.BoolP(true), - Label: util.StrP("var"), - UUID: &aUUID, - Options: []types3_3.FilesystemOption{"rw"}, - }, - }, - Files: []types3_3.File{ - { - Node: types3_3.Node{ - Path: "/var/varfile", - Overwrite: util.BoolPStrict(false), - User: types3_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_3.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - FileEmbedded1: types3_3.FileEmbedded1{ - Mode: util.IntP(420), - Append: []types3_3.Resource{ - { - Compression: util.StrP("gzip"), - Source: util.StrP("https://example.com"), - Verification: types3_3.Verification{ - Hash: &aSha512Hash, - }, - HTTPHeaders: types3_3.HTTPHeaders{ - types3_3.HTTPHeader{ - Name: "Authorization", - Value: util.StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), - }, - types3_3.HTTPHeader{ - Name: "User-Agent", - Value: util.StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), - }, - }, - }, - }, - }, - }, - { - Node: types3_3.Node{ - Path: "/empty", - Overwrite: util.BoolPStrict(false), - }, - FileEmbedded1: types3_3.FileEmbedded1{ - Mode: util.IntP(420), - Contents: types3_3.Resource{ - Source: util.StrPStrict(""), - }, - }, - }, - }, - Directories: []types3_3.Directory{ - { - Node: types3_3.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_3.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_3.DirectoryEmbedded1{ - Mode: util.IntP(420), - }, - }, - }, - Links: []types3_3.Link{ - { - Node: types3_3.Node{ - Path: "/rootlink", - Overwrite: util.BoolP(true), - User: types3_3.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_3.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - LinkEmbedded1: types3_3.LinkEmbedded1{ - Hard: util.BoolP(false), - Target: util.StrP("/foobar"), - }, - }, - }, - }, - } -) - -type input2_3 struct { - cfg types2_3.Config - fsMap map[string]string -} - -func TestCheck2_3(t *testing.T) { - goodConfigs := []input2_3{ - { - exhaustiveConfig2_3, - exhaustiveMap, - }, - } - badConfigs := []input2_3{ - {}, // empty config has no version, fails validation - { - // need a map for filesystems - exhaustiveConfig2_3, - nil, - }, - } - for i, e := range goodConfigs { - if err := v23tov30.Check2_3(e.cfg, e.fsMap); err != nil { - t.Errorf("Good config test %d: got %v, expected nil", i, err) - } - } - for i, e := range badConfigs { - if err := v23tov30.Check2_3(e.cfg, e.fsMap); err == nil { - t.Errorf("Bad config test %d: got ok, expected: %v", i, err) - } - } -} - -type input2_4 struct { - cfg types2_4.Config - fsMap map[string]string -} - -func TestCheck2_4(t *testing.T) { - goodConfigs := []input2_4{ - { - exhaustiveConfig2_4, - exhaustiveMap, - }, - } - badConfigs := []input2_4{ - {}, // empty config has no version, fails validation - { - // need a map for filesystems - exhaustiveConfig2_4, - nil, - }, - } - for i, e := range goodConfigs { - if err := v24tov31.Check2_4(e.cfg, e.fsMap); err != nil { - t.Errorf("Good config test %d: got %v, expected nil", i, err) - } - } - for i, e := range badConfigs { - if err := v24tov31.Check2_4(e.cfg, e.fsMap); err == nil { - t.Errorf("Bad config test %d: got ok, expected: %v", i, err) - } - } -} - -func TestTranslate2_3to3_0(t *testing.T) { - res, err := v23tov30.Translate(exhaustiveConfig2_3, exhaustiveMap) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, exhaustiveConfig3_0, res) -} - -func TestTranslate2_4to3_1(t *testing.T) { - res, err := v24tov31.Translate(exhaustiveConfig2_4, exhaustiveMap) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, nonexhaustiveConfig3_1, res) -} - -func TestTranslate3_0to2_2(t *testing.T) { - emptyConfig := types3_0.Config{ - Ignition: types3_0.Ignition{ - Version: "3.0.0", - }, - } - - _, err := v30tov22.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v30tov22.Translate(downtranslateConfig3_0) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, exhaustiveConfig2_2, res) -} - -func TestTranslate3_1to2_2(t *testing.T) { - emptyConfig := types3_1.Config{ - Ignition: types3_1.Ignition{ - Version: "3.1.0", - }, - } - - _, err := v31tov22.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v31tov22.Translate(downtranslateConfig3_1) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, exhaustiveConfig2_2, res) -} - -func TestTranslate3_1to2_4(t *testing.T) { - emptyConfig := types3_1.Config{ - Ignition: types3_1.Ignition{ - Version: "3.1.0", - }, - } - - _, err := v31tov24.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v31tov24.Translate(nonexhaustiveConfig3_1) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, exhaustiveConfig2_4, res) -} - -func TestTranslate3_2to2_2(t *testing.T) { - emptyConfig := types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - } - - _, err := v32tov22.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v32tov22.Translate(downtranslateConfig3_2) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, exhaustiveConfig2_2, res) -} - -func TestTranslate3_2to2_4(t *testing.T) { - emptyConfig := types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - } - - _, err := v32tov24.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v32tov24.Translate(nonexhaustiveConfig3_2) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, exhaustiveConfig2_4, res) -} - -func TestTranslate3_2to3_1(t *testing.T) { - emptyConfig := types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - } - - _, err := v32tov31.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v32tov31.Translate(nonexhaustiveConfig3_2) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, nonexhaustiveConfig3_1, res) - - _, err = v32tov31.Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - Storage: types3_2.Storage{ - Luks: []types3_2.Luks{ - { - Name: "z", - Device: util.StrP("/dev/z"), - }, - }, - }, - }) - assert.Error(t, err) - _, err = v32tov31.Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - Storage: types3_2.Storage{ - Disks: []types3_2.Disk{ - { - Device: "/dev/a", - Partitions: []types3_2.Partition{ - { - Label: util.StrP("z"), - Resize: util.BoolP(true), - }, - }, - }, - }, - }, - }) - assert.Error(t, err) - _, err = v32tov31.Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - Passwd: types3_2.Passwd{ - Users: []types3_2.PasswdUser{ - { - Name: "z", - ShouldExist: util.BoolPStrict(false), - }, - }, - }, - }) - assert.Error(t, err) - _, err = v32tov31.Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - Passwd: types3_2.Passwd{ - Groups: []types3_2.PasswdGroup{ - { - Name: "z", - ShouldExist: util.BoolPStrict(false), - }, - }, - }, - }) - assert.Error(t, err) -} - -func TestTranslate3_3to3_2(t *testing.T) { - emptyConfig := types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - }, - } - - _, err := v33tov32.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v33tov32.Translate(nonexhaustiveConfig3_3) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, nonexhaustiveConfig3_2, res) - - _, err = v33tov32.Translate(types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - }, - KernelArguments: types3_3.KernelArguments{ - ShouldExist: []types3_3.KernelArgument{"foo"}, - }, - }) - assert.Error(t, err) - _, err = v33tov32.Translate(types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - }, - KernelArguments: types3_3.KernelArguments{ - ShouldNotExist: []types3_3.KernelArgument{"foo"}, - }, - }) - assert.Error(t, err) - _, err = v33tov32.Translate(types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - }, - Storage: types3_3.Storage{ - Filesystems: []types3_3.Filesystem{ - { - Device: "/dev/foo", - Format: util.StrP("none"), - }, - }, - }, - }) - assert.Error(t, err) -} - -func TestTranslate3_4to3_3(t *testing.T) { - emptyConfig := types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - } - - _, err := v34tov33.Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - - res, err := v34tov33.Translate(nonexhaustiveConfig3_4) - if err != nil { - t.Fatalf("Failed translation: %v", err) - } - assert.Equal(t, downtranslateConfig3_3, res) - - _, err = v34tov33.Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Luks: []types3_4.Luks{ - { - Device: util.StrP("/dev/sda"), - Clevis: types3_4.Clevis{ - Tang: []types3_4.Tang{ - { - URL: "http://example.com", - Thumbprint: util.StrP("z"), - Advertisement: util.StrP("{\"payload\": \"eyJrZXlzIjogW3siYWxnIjogIkVTNTEyIiwgImt0eSI6ICJFQyIsICJjcnYiOiAiUC01MjEiLCAieCI6ICJBRGFNajJmazNob21CWTF5WElSQ21uRk92cmUzOFZjdHMwTnNHeDZ6RWNxdEVXcjh5ekhUMkhfa2hjNGpSa19FQWFLdjNrd2RjZ05sOTBLcGhfMGYyQ190IiwgInkiOiAiQUZ2d1UyeGJ5T1RydWo0V1NtcVlqN2wtcUVTZmhWakdCNTI1Q2d6d0NoZUZRRTBvb1o3STYyamt3NkRKQ05yS3VPUDRsSEhicm8tYXhoUk9MSXNJVExvNCIsICJrZXlfb3BzIjogWyJ2ZXJpZnkiXX0sIHsiYWxnIjogIkVDTVIiLCAia3R5IjogIkVDIiwgImNydiI6ICJQLTUyMSIsICJ4IjogIkFOZDVYcTFvZklUbTdNWG16OUY0VVRSYmRNZFNIMl9XNXczTDVWZ0w3b3hwdmpyM0hkLXNLNUVqd3A1V2swMnJMb3NXVUJjYkZyZEhjZFJTTVJoZlVFTFIiLCAieSI6ICJBRVVaVlVZWkFBY2hVcmdoX3poaTV3SUUzeTEycGwzeWhqUk5LcGpSdW9tUFhKaDhRaFhXRmRWZEtMUlEwX1lwUjNOMjNSUk1pU1lvWlg0Qm42QnlrQVBMIiwgImtleV9vcHMiOiBbImRlcml2ZUtleSJdfV19\", \"protected\": \"eyJhbGciOiJFUzUxMiIsImN0eSI6Imp3ay1zZXQranNvbiJ9\", \"signature\": \"APHfSyVzLwELwG0pMJyIP74gWvhHUvDtv0SESBxA2uOdSXq76IdWHW2xvCZDdlNan8pnqUvEedPZjf_vdKBw9MTXAPMkRxVnu64HepKwlrzzm_zG2R4CHpoCOsGgjH9-acYxg-Vha63oMojv3_bV0VHg-NbzNLaxietgYplstvcNIwkv\"}"), - }, - }, - }, - }, - }, - }, - }) - assert.Error(t, err) - - _, err = v34tov33.Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Luks: []types3_4.Luks{ - { - Device: util.StrP("/dev/sda"), - Discard: util.BoolP(true), - }, - }, - }, - }) - assert.Error(t, err) - - _, err = v34tov33.Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Luks: []types3_4.Luks{ - { - Device: util.StrP("/dev/sda"), - OpenOptions: []types3_4.OpenOption{"foo"}, - }, - }, - }, - }) - assert.Error(t, err) - - _, err = v34tov33.Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Files: []types3_4.File{ - { - Node: types3_4.Node{ - Path: "/root/file.txt", - }, - FileEmbedded1: types3_4.FileEmbedded1{ - Mode: util.IntP(01777), - }, - }, - }, - }, - }) - assert.Error(t, err) - - _, err = v34tov33.Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Directories: []types3_4.Directory{ - { - Node: types3_4.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_4.NodeGroup{ - Name: util.StrP("groupname"), - }, - }, - DirectoryEmbedded1: types3_4.DirectoryEmbedded1{ - Mode: util.IntP(01777), - }, - }, - }, - }, - }) - assert.Error(t, err) - - _, err = v34tov33.Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Files: []types3_4.File{ - { - Node: types3_4.Node{ - Path: "/path", - }, - FileEmbedded1: types3_4.FileEmbedded1{ - Contents: types3_4.Resource{ - Source: util.StrP("arn:aws:s3:us-west-1:123456789012:accesspoint/test/object/some/path"), - }, - }, - }, - }, - }, - }) - assert.Error(t, err) -} - -func TestRemoveDuplicateFilesUnitsUsers2_3(t *testing.T) { - mode := 420 - testDataOld := "data:,old" - testDataNew := "data:,new" - testIgn2Config := types2_3.Config{} - - // file test, add a duplicate file and see if the newest one is preserved - fileOld := types2_3.File{ - Node: types2_3.Node{ - Filesystem: "root", Path: "/etc/testfileconfig", - }, - FileEmbedded1: types2_3.FileEmbedded1{ - Contents: types2_3.FileContents{ - Source: testDataOld, - }, - Mode: &mode, - }, - } - testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileOld) - - fileNew := types2_3.File{ - Node: types2_3.Node{ - Filesystem: "root", Path: "/etc/testfileconfig", - }, - FileEmbedded1: types2_3.FileEmbedded1{ - Contents: types2_3.FileContents{ - Source: testDataNew, - }, - Mode: &mode, - }, - } - testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileNew) - - // unit test, add three units and three dropins with the same name as follows: - // unitOne: - // contents: old - // dropin: - // name: one - // contents: old - // unitTwo: - // dropin: - // name: one - // contents: new - // unitThree: - // contents: new - // dropin: - // name: two - // contents: new - // Which should result in: - // unitFinal: - // contents: new - // dropin: - // - name: one - // contents: new - // - name: two - // contents: new - // - unitName := "testUnit" - dropinNameOne := "one" - dropinNameTwo := "two" - dropinOne := types2_3.SystemdDropin{ - Contents: testDataOld, - Name: dropinNameOne, - } - dropinTwo := types2_3.SystemdDropin{ - Contents: testDataNew, - Name: dropinNameOne, - } - dropinThree := types2_3.SystemdDropin{ - Contents: testDataNew, - Name: dropinNameTwo, - } - - unitOne := types2_3.Unit{ - Contents: testDataOld, - Name: unitName, - } - unitOne.Dropins = append(unitOne.Dropins, dropinOne) - testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitOne) - - unitTwo := types2_3.Unit{ - Name: unitName, - } - unitTwo.Dropins = append(unitTwo.Dropins, dropinTwo) - testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitTwo) - - unitThree := types2_3.Unit{ - Contents: testDataNew, - Name: unitName, - } - unitThree.Dropins = append(unitThree.Dropins, dropinThree) - testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitThree) - - // user test, add a duplicate user and see if it is deduplicated but ssh keys from both are preserved - userName := "testUser" - userOne := types2_3.PasswdUser{ - Name: userName, - SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ - "one", - "two", - }, - } - userTwo := types2_3.PasswdUser{ - Name: userName, - SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ - "three", - }, - } - userThree := types2_3.PasswdUser{ - Name: "userThree", - SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ - "four", - }, - } - testIgn2Config.Passwd.Users = append(testIgn2Config.Passwd.Users, userOne, userTwo, userThree) - - convertedIgn2Config, err := v23tov30.RemoveDuplicateFilesUnitsUsers(testIgn2Config) - assert.NoError(t, err) - - expectedIgn2Config := types2_3.Config{} - expectedIgn2Config.Storage.Files = append(expectedIgn2Config.Storage.Files, fileNew) - unitExpected := types2_3.Unit{ - Contents: testDataNew, - Name: unitName, - } - unitExpected.Dropins = append(unitExpected.Dropins, dropinThree) - unitExpected.Dropins = append(unitExpected.Dropins, dropinTwo) - expectedIgn2Config.Systemd.Units = append(expectedIgn2Config.Systemd.Units, unitExpected) - expectedMergedUser := types2_3.PasswdUser{ - Name: userName, - SSHAuthorizedKeys: []types2_3.SSHAuthorizedKey{ - "three", - "one", - "two", - }, - } - expectedIgn2Config.Passwd.Users = append(expectedIgn2Config.Passwd.Users, userThree, expectedMergedUser) - - assert.Equal(t, expectedIgn2Config, convertedIgn2Config) -} - -func TestRemoveDuplicateFilesUnitsUsers2_4(t *testing.T) { - mode := 420 - testDataOld := "data:,old" - testDataNew := "data:,new" - testIgn2Config := types2_4.Config{} - - // file test, add a duplicate file and see if the newest one is preserved - fileOld := types2_4.File{ - Node: types2_4.Node{ - Filesystem: "root", Path: "/etc/testfileconfig", - }, - FileEmbedded1: types2_4.FileEmbedded1{ - Contents: types2_4.FileContents{ - Source: testDataOld, - }, - Mode: &mode, - }, - } - testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileOld) - - fileNew := types2_4.File{ - Node: types2_4.Node{ - Filesystem: "root", Path: "/etc/testfileconfig", - }, - FileEmbedded1: types2_4.FileEmbedded1{ - Contents: types2_4.FileContents{ - Source: testDataNew, - }, - Mode: &mode, - }, - } - testIgn2Config.Storage.Files = append(testIgn2Config.Storage.Files, fileNew) - - // unit test, add three units and three dropins with the same name as follows: - // unitOne: - // contents: old - // dropin: - // name: one - // contents: old - // unitTwo: - // dropin: - // name: one - // contents: new - // unitThree: - // contents: new - // dropin: - // name: two - // contents: new - // Which should result in: - // unitFinal: - // contents: new - // dropin: - // - name: one - // contents: new - // - name: two - // contents: new - // - unitName := "testUnit" - dropinNameOne := "one" - dropinNameTwo := "two" - dropinOne := types2_4.SystemdDropin{ - Contents: testDataOld, - Name: dropinNameOne, - } - dropinTwo := types2_4.SystemdDropin{ - Contents: testDataNew, - Name: dropinNameOne, - } - dropinThree := types2_4.SystemdDropin{ - Contents: testDataNew, - Name: dropinNameTwo, - } - - unitOne := types2_4.Unit{ - Contents: testDataOld, - Name: unitName, - } - unitOne.Dropins = append(unitOne.Dropins, dropinOne) - testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitOne) - - unitTwo := types2_4.Unit{ - Name: unitName, - } - unitTwo.Dropins = append(unitTwo.Dropins, dropinTwo) - testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitTwo) - - unitThree := types2_4.Unit{ - Contents: testDataNew, - Name: unitName, - } - unitThree.Dropins = append(unitThree.Dropins, dropinThree) - testIgn2Config.Systemd.Units = append(testIgn2Config.Systemd.Units, unitThree) - - // user test, add a duplicate user and see if it is deduplicated but ssh keys from both are preserved - userName := "testUser" - userOne := types2_4.PasswdUser{ - Name: userName, - SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ - "one", - "two", - }, - } - userTwo := types2_4.PasswdUser{ - Name: userName, - SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ - "three", - }, - } - userThree := types2_4.PasswdUser{ - Name: "userThree", - SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ - "four", - }, - } - testIgn2Config.Passwd.Users = append(testIgn2Config.Passwd.Users, userOne, userTwo, userThree) - - convertedIgn2Config, err := v24tov31.RemoveDuplicateFilesUnitsUsers(testIgn2Config) - assert.NoError(t, err) - - expectedIgn2Config := types2_4.Config{} - expectedIgn2Config.Storage.Files = append(expectedIgn2Config.Storage.Files, fileNew) - unitExpected := types2_4.Unit{ - Contents: testDataNew, - Name: unitName, - } - unitExpected.Dropins = append(unitExpected.Dropins, dropinThree) - unitExpected.Dropins = append(unitExpected.Dropins, dropinTwo) - expectedIgn2Config.Systemd.Units = append(expectedIgn2Config.Systemd.Units, unitExpected) - expectedMergedUser := types2_4.PasswdUser{ - Name: userName, - SSHAuthorizedKeys: []types2_4.SSHAuthorizedKey{ - "three", - "one", - "two", - }, - } - expectedIgn2Config.Passwd.Users = append(expectedIgn2Config.Passwd.Users, userThree, expectedMergedUser) - assert.Equal(t, expectedIgn2Config, convertedIgn2Config) -} diff --git a/util/test_constants.go b/util/test_constants.go new file mode 100644 index 0000000..1a5d3f5 --- /dev/null +++ b/util/test_constants.go @@ -0,0 +1,1996 @@ +package util + +import ( + types2_2 "github.com/coreos/ignition/config/v2_2/types" + types2_3 "github.com/coreos/ignition/config/v2_3/types" + types2_4 "github.com/coreos/ignition/config/v2_4/types" + types3_0 "github.com/coreos/ignition/v2/config/v3_0/types" + types3_1 "github.com/coreos/ignition/v2/config/v3_1/types" + types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" + types3_3 "github.com/coreos/ignition/v2/config/v3_3/types" + types3_4 "github.com/coreos/ignition/v2/config/v3_4/types" +) + +// Configs using _all_ the (undeprecated) fields +var ( + aSha512Hash = "sha512-c6100de5624cfb3c109909948ecb8d703bbddcd3725b8bd43dcf2cee6d2f5dc990a757575e0306a8e8eea354bcd7cfac354da911719766225668fe5430477fa8" + aUUID = "9d6e42cd-dcef-4177-b4c6-2a0c979e3d82" + ExhaustiveMap = map[string]string{ + "var": "/var", + "/var": "/var", + } + + ExhaustiveConfig2_3 = types2_3.Config{ + Ignition: types2_3.Ignition{ + Version: "2.3.0", + Config: types2_3.IgnitionConfig{ + Append: []types2_3.ConfigReference{ + { + Source: "https://example.com", + Verification: types2_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: &types2_3.ConfigReference{ + Source: "https://example.com", + Verification: types2_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types2_3.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types2_3.Security{ + TLS: types2_3.TLS{ + CertificateAuthorities: []types2_3.CaReference{ + { + Source: "https://example.com", + Verification: types2_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + // Proxy is unsupported + }, + Storage: types2_3.Storage{ + Disks: []types2_3.Disk{ + { + Device: "/dev/sda", + WipeTable: true, + Partitions: []types2_3.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: aUUID, + GUID: aUUID, + WipePartitionEntry: true, + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types2_3.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types2_3.Device{"/dev/sdb", "/dev/sdc"}, + Spares: 1, + Options: []types2_3.RaidOption{"foobar"}, + }, + }, + Filesystems: []types2_3.Filesystem{ + { + Name: "/var", + Mount: &types2_3.Mount{ + Device: "/dev/disk/by-partlabel/var", + Format: "xfs", + WipeFilesystem: true, + Label: StrP("var"), + UUID: &aUUID, + Options: []types2_3.MountOption{"rw"}, + }, + }, + }, + Files: []types2_3.File{ + { + Node: types2_3.Node{ + Filesystem: "/var", + Path: "/varfile", + Overwrite: BoolPStrict(false), + User: &types2_3.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_3.NodeGroup{ + Name: "groupname", + }, + }, + FileEmbedded1: types2_3.FileEmbedded1{ + Append: true, + Mode: IntP(420), + Contents: types2_3.FileContents{ + Compression: "gzip", + Source: "https://example.com", + Verification: types2_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + { + Node: types2_3.Node{ + Filesystem: "root", + Path: "/empty", + }, + FileEmbedded1: types2_3.FileEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Directories: []types2_3.Directory{ + { + Node: types2_3.Node{ + Filesystem: "root", + Path: "/rootdir", + Overwrite: BoolP(true), + User: &types2_3.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_3.NodeGroup{ + Name: "groupname", + }, + }, + DirectoryEmbedded1: types2_3.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types2_3.Link{ + { + Node: types2_3.Node{ + Filesystem: "root", + Path: "/rootlink", + Overwrite: BoolP(true), + User: &types2_3.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_3.NodeGroup{ + Name: "groupname", + }, + }, + LinkEmbedded1: types2_3.LinkEmbedded1{ + Hard: false, + Target: "/foobar", + }, + }, + }, + }, + } + + ExhaustiveConfig2_4 = types2_4.Config{ + Ignition: types2_4.Ignition{ + Version: "2.4.0", + Config: types2_4.IgnitionConfig{ + Append: []types2_4.ConfigReference{ + { + Source: "https://example.com", + Verification: types2_4.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: &types2_4.ConfigReference{ + Source: "https://example.com", + Verification: types2_4.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types2_4.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types2_4.Security{ + TLS: types2_4.TLS{ + CertificateAuthorities: []types2_4.CaReference{ + { + Source: "https://example.com", + Verification: types2_4.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + Proxy: types2_4.Proxy{ + HTTPProxy: "https://proxy.example.net/", + HTTPSProxy: "https://secure.proxy.example.net/", + NoProxy: []types2_4.NoProxyItem{ + "www.example.net", + "www.example2.net", + }, + }, + }, + Storage: types2_4.Storage{ + Disks: []types2_4.Disk{ + { + Device: "/dev/sda", + WipeTable: true, + Partitions: []types2_4.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: aUUID, + GUID: aUUID, + WipePartitionEntry: true, + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types2_4.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types2_4.Device{"/dev/sdb", "/dev/sdc"}, + Spares: 1, + Options: []types2_4.RaidOption{"foobar"}, + }, + }, + Filesystems: []types2_4.Filesystem{ + { + Name: "/var", + Mount: &types2_4.Mount{ + Device: "/dev/disk/by-partlabel/var", + Format: "xfs", + WipeFilesystem: true, + Label: StrP("var"), + UUID: &aUUID, + Options: []types2_4.MountOption{"rw"}, + }, + }, + }, + Files: []types2_4.File{ + { + Node: types2_4.Node{ + Filesystem: "/var", + Path: "/varfile", + Overwrite: BoolPStrict(false), + User: &types2_4.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_4.NodeGroup{ + Name: "groupname", + }, + }, + FileEmbedded1: types2_4.FileEmbedded1{ + Append: true, + Mode: IntP(420), + Contents: types2_4.FileContents{ + Compression: "gzip", + Source: "https://example.com", + Verification: types2_4.Verification{ + Hash: &aSha512Hash, + }, + HTTPHeaders: types2_4.HTTPHeaders{ + types2_4.HTTPHeader{ + Name: "Authorization", + Value: "Basic YWxhZGRpbjpvcGVuc2VzYW1l", + }, + types2_4.HTTPHeader{ + Name: "User-Agent", + Value: "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)", + }, + }, + }, + }, + }, + { + Node: types2_4.Node{ + Filesystem: "root", + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types2_4.FileEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Directories: []types2_4.Directory{ + { + Node: types2_4.Node{ + Filesystem: "root", + Path: "/rootdir", + Overwrite: BoolP(true), + User: &types2_4.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_4.NodeGroup{ + Name: "groupname", + }, + }, + DirectoryEmbedded1: types2_4.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types2_4.Link{ + { + Node: types2_4.Node{ + Filesystem: "root", + Path: "/rootlink", + Overwrite: BoolP(true), + User: &types2_4.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_4.NodeGroup{ + Name: "groupname", + }, + }, + LinkEmbedded1: types2_4.LinkEmbedded1{ + Hard: false, + Target: "/foobar", + }, + }, + }, + }, + } + + ExhaustiveConfig3_0 = types3_0.Config{ + Ignition: types3_0.Ignition{ + Version: "3.0.0", + Config: types3_0.IgnitionConfig{ + Merge: []types3_0.ConfigReference{ + { + Source: StrP("https://example.com"), + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_0.ConfigReference{ + Source: StrP("https://example.com"), + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_0.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_0.Security{ + TLS: types3_0.TLS{ + CertificateAuthorities: []types3_0.CaReference{ + { + Source: "https://example.com", + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + // Proxy is unsupported + }, + Storage: types3_0.Storage{ + Disks: []types3_0.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_0.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_0.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types3_0.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_0.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_0.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_0.FilesystemOption{"rw"}, + }, + }, + Files: []types3_0.File{ + { + Node: types3_0.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_0.NodeUser{ + ID: IntP(1000), + }, + Group: types3_0.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_0.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_0.FileContents{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + { + Node: types3_0.Node{ + Path: "/empty", + Overwrite: BoolPStrict(true), + }, + FileEmbedded1: types3_0.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_0.FileContents{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_0.Directory{ + { + Node: types3_0.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_0.NodeUser{ + ID: IntP(1000), + }, + Group: types3_0.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_0.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_0.Link{ + { + Node: types3_0.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_0.NodeUser{ + ID: IntP(1000), + }, + Group: types3_0.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_0.LinkEmbedded1{ + Hard: BoolP(false), + Target: "/foobar", + }, + }, + }, + }, + } + + ExhaustiveConfig2_2 = types2_2.Config{ + Ignition: types2_2.Ignition{ + Version: "2.2.0", + Config: types2_2.IgnitionConfig{ + Append: []types2_2.ConfigReference{ + { + Source: "https://example.com", + Verification: types2_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: &types2_2.ConfigReference{ + Source: "https://example.com", + Verification: types2_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types2_2.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types2_2.Security{ + TLS: types2_2.TLS{ + CertificateAuthorities: []types2_2.CaReference{ + { + Source: "https://example.com", + Verification: types2_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + // Proxy is unsupported + }, + Storage: types2_2.Storage{ + Disks: []types2_2.Disk{ + { + Device: "/dev/sda", + WipeTable: true, + Partitions: []types2_2.Partition{ + { + Label: "var", + Number: 1, + TypeGUID: aUUID, + GUID: aUUID, + }, + }, + }, + }, + Raid: []types2_2.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types2_2.Device{"/dev/sdb", "/dev/sdc"}, + Spares: 1, + Options: []types2_2.RaidOption{"foobar"}, + }, + }, + Filesystems: []types2_2.Filesystem{ + { + Name: "/var", + Mount: &types2_2.Mount{ + Device: "/dev/disk/by-partlabel/var", + Format: "xfs", + WipeFilesystem: true, + Label: StrP("var"), + UUID: &aUUID, + Options: []types2_2.MountOption{"rw"}, + }, + }, + }, + Files: []types2_2.File{ + { + Node: types2_2.Node{ + Filesystem: "/var", + Path: "/varfile", + Overwrite: BoolPStrict(false), + User: &types2_2.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_2.NodeGroup{ + Name: "groupname", + }, + }, + FileEmbedded1: types2_2.FileEmbedded1{ + Append: true, + Mode: IntP(420), + Contents: types2_2.FileContents{ + Compression: "gzip", + Source: "https://example.com", + Verification: types2_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + { + Node: types2_2.Node{ + Filesystem: "root", + Path: "/etc/motd", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types2_2.FileEmbedded1{ + Append: true, + Mode: IntP(420), + Contents: types2_2.FileContents{ + Source: "data:text/plain;base64,Zm9vCg==", + }, + }, + }, + { + Node: types2_2.Node{ + Filesystem: "root", + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types2_2.FileEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Directories: []types2_2.Directory{ + { + Node: types2_2.Node{ + Filesystem: "root", + Path: "/rootdir", + Overwrite: BoolP(true), + User: &types2_2.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_2.NodeGroup{ + Name: "groupname", + }, + }, + DirectoryEmbedded1: types2_2.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types2_2.Link{ + { + Node: types2_2.Node{ + Filesystem: "root", + Path: "/rootlink", + Overwrite: BoolP(true), + User: &types2_2.NodeUser{ + ID: IntP(1000), + }, + Group: &types2_2.NodeGroup{ + Name: "groupname", + }, + }, + LinkEmbedded1: types2_2.LinkEmbedded1{ + Hard: false, + Target: "/foobar", + }, + }, + }, + }, + } + + DowntranslateConfig3_0 = types3_0.Config{ + Ignition: types3_0.Ignition{ + Version: "3.0.0", + Config: types3_0.IgnitionConfig{ + Merge: []types3_0.ConfigReference{ + { + Source: StrP("https://example.com"), + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_0.ConfigReference{ + Source: StrP("https://example.com"), + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_0.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_0.Security{ + TLS: types3_0.TLS{ + CertificateAuthorities: []types3_0.CaReference{ + { + Source: "https://example.com", + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + // Proxy is unsupported + }, + Storage: types3_0.Storage{ + Disks: []types3_0.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_0.Partition{ + { + Label: StrP("var"), + Number: 1, + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_0.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types3_0.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_0.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_0.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_0.FilesystemOption{"rw"}, + }, + }, + Files: []types3_0.File{ + { + Node: types3_0.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_0.NodeUser{ + ID: IntP(1000), + }, + Group: types3_0.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_0.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_0.FileContents{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_0.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + { + Node: types3_0.Node{ + Path: "/etc/motd", + // Test default append with overwrite unset + }, + FileEmbedded1: types3_0.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_0.FileContents{ + { + Source: StrP("data:text/plain;base64,Zm9vCg=="), + }, + }, + }, + }, + { + Node: types3_0.Node{ + Path: "/empty", + }, + FileEmbedded1: types3_0.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_0.FileContents{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_0.Directory{ + { + Node: types3_0.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_0.NodeUser{ + ID: IntP(1000), + }, + Group: types3_0.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_0.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_0.Link{ + { + Node: types3_0.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_0.NodeUser{ + ID: IntP(1000), + }, + Group: types3_0.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_0.LinkEmbedded1{ + Hard: BoolP(false), + Target: "/foobar", + }, + }, + }, + }, + } + + NonexhaustiveConfig3_1 = types3_1.Config{ + Ignition: types3_1.Ignition{ + Version: "3.1.0", + Config: types3_1.IgnitionConfig{ + Merge: []types3_1.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_1.Resource{ + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_1.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_1.Security{ + TLS: types3_1.TLS{ + CertificateAuthorities: []types3_1.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + Proxy: types3_1.Proxy{ + HTTPProxy: StrP("https://proxy.example.net/"), + HTTPSProxy: StrP("https://secure.proxy.example.net/"), + NoProxy: []types3_1.NoProxyItem{ + "www.example.net", + "www.example2.net", + }, + }, + }, + Storage: types3_1.Storage{ + Disks: []types3_1.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_1.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_1.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types3_1.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_1.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_1.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_1.FilesystemOption{"rw"}, + }, + }, + Files: []types3_1.File{ + { + Node: types3_1.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_1.NodeUser{ + ID: IntP(1000), + }, + Group: types3_1.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_1.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_1.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + HTTPHeaders: types3_1.HTTPHeaders{ + types3_1.HTTPHeader{ + Name: "Authorization", + Value: StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), + }, + types3_1.HTTPHeader{ + Name: "User-Agent", + Value: StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), + }, + }, + }, + }, + }, + }, + { + Node: types3_1.Node{ + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types3_1.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_1.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_1.Directory{ + { + Node: types3_1.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_1.NodeUser{ + ID: IntP(1000), + }, + Group: types3_1.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_1.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_1.Link{ + { + Node: types3_1.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_1.NodeUser{ + ID: IntP(1000), + }, + Group: types3_1.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_1.LinkEmbedded1{ + Hard: BoolP(false), + Target: "/foobar", + }, + }, + }, + }, + } + + DowntranslateConfig3_1 = types3_1.Config{ + Ignition: types3_1.Ignition{ + Version: "3.1.0", + Config: types3_1.IgnitionConfig{ + Merge: []types3_1.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_1.Resource{ + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_1.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_1.Security{ + TLS: types3_1.TLS{ + CertificateAuthorities: []types3_1.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + // Proxy is unsupported + }, + Storage: types3_1.Storage{ + Disks: []types3_1.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_1.Partition{ + { + Label: StrP("var"), + Number: 1, + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_1.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types3_1.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_1.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_1.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_1.FilesystemOption{"rw"}, + }, + }, + Files: []types3_1.File{ + { + Node: types3_1.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_1.NodeUser{ + ID: IntP(1000), + }, + Group: types3_1.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_1.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_1.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_1.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + { + Node: types3_1.Node{ + Path: "/etc/motd", + // Test default append with overwrite unset + }, + FileEmbedded1: types3_1.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_1.Resource{ + { + Source: StrP("data:text/plain;base64,Zm9vCg=="), + }, + }, + }, + }, + { + Node: types3_1.Node{ + Path: "/empty", + }, + FileEmbedded1: types3_1.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_1.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_1.Directory{ + { + Node: types3_1.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_1.NodeUser{ + ID: IntP(1000), + }, + Group: types3_1.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_1.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_1.Link{ + { + Node: types3_1.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_1.NodeUser{ + ID: IntP(1000), + }, + Group: types3_1.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_1.LinkEmbedded1{ + Hard: BoolP(false), + Target: "/foobar", + }, + }, + }, + }, + } + + NonexhaustiveConfig3_2 = types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + Config: types3_2.IgnitionConfig{ + Merge: []types3_2.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_2.Resource{ + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_2.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_2.Security{ + TLS: types3_2.TLS{ + CertificateAuthorities: []types3_2.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + Proxy: types3_2.Proxy{ + HTTPProxy: StrP("https://proxy.example.net/"), + HTTPSProxy: StrP("https://secure.proxy.example.net/"), + NoProxy: []types3_2.NoProxyItem{ + "www.example.net", + "www.example2.net", + }, + }, + }, + Storage: types3_2.Storage{ + Disks: []types3_2.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_2.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_2.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types3_2.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_2.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_2.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_2.FilesystemOption{"rw"}, + }, + }, + Files: []types3_2.File{ + { + Node: types3_2.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_2.NodeUser{ + ID: IntP(1000), + }, + Group: types3_2.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_2.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_2.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + HTTPHeaders: types3_2.HTTPHeaders{ + types3_2.HTTPHeader{ + Name: "Authorization", + Value: StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), + }, + types3_2.HTTPHeader{ + Name: "User-Agent", + Value: StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), + }, + }, + }, + }, + }, + }, + { + Node: types3_2.Node{ + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types3_2.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_2.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_2.Directory{ + { + Node: types3_2.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_2.NodeUser{ + ID: IntP(1000), + }, + Group: types3_2.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_2.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_2.Link{ + { + Node: types3_2.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_2.NodeUser{ + ID: IntP(1000), + }, + Group: types3_2.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_2.LinkEmbedded1{ + Hard: BoolP(false), + Target: "/foobar", + }, + }, + }, + }, + } + + NonexhaustiveConfig3_3 = types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + Config: types3_3.IgnitionConfig{ + Merge: []types3_3.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_3.Resource{ + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_3.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_3.Security{ + TLS: types3_3.TLS{ + CertificateAuthorities: []types3_3.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + Proxy: types3_3.Proxy{ + HTTPProxy: StrP("https://proxy.example.net/"), + HTTPSProxy: StrP("https://secure.proxy.example.net/"), + NoProxy: []types3_3.NoProxyItem{ + "www.example.net", + "www.example2.net", + }, + }, + }, + Storage: types3_3.Storage{ + Disks: []types3_3.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_3.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_3.Raid{ + { + Name: "array", + Level: StrP("raid10"), + Devices: []types3_3.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_3.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_3.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_3.FilesystemOption{"rw"}, + }, + }, + Files: []types3_3.File{ + { + Node: types3_3.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_3.NodeUser{ + ID: IntP(1000), + }, + Group: types3_3.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_3.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_3.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + HTTPHeaders: types3_3.HTTPHeaders{ + types3_3.HTTPHeader{ + Name: "Authorization", + Value: StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), + }, + types3_3.HTTPHeader{ + Name: "User-Agent", + Value: StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), + }, + }, + }, + }, + }, + }, + { + Node: types3_3.Node{ + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types3_3.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_3.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_3.Directory{ + { + Node: types3_3.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_3.NodeUser{ + ID: IntP(1000), + }, + Group: types3_3.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_3.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_3.Link{ + { + Node: types3_3.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_3.NodeUser{ + ID: IntP(1000), + }, + Group: types3_3.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_3.LinkEmbedded1{ + Hard: BoolP(false), + Target: StrP("/foobar"), + }, + }, + }, + }, + } + + DowntranslateConfig3_2 = types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + Config: types3_2.IgnitionConfig{ + Merge: []types3_2.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_2.Resource{ + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_2.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_2.Security{ + TLS: types3_2.TLS{ + CertificateAuthorities: []types3_2.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + // Proxy is unsupported + }, + Storage: types3_2.Storage{ + Disks: []types3_2.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_2.Partition{ + { + Label: StrP("var"), + Number: 1, + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_2.Raid{ + { + Name: "array", + Level: "raid10", + Devices: []types3_2.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_2.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_2.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_2.FilesystemOption{"rw"}, + }, + }, + Files: []types3_2.File{ + { + Node: types3_2.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_2.NodeUser{ + ID: IntP(1000), + }, + Group: types3_2.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_2.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_2.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_2.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + { + Node: types3_2.Node{ + Path: "/etc/motd", + // Test default append with overwrite unset + }, + FileEmbedded1: types3_2.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_2.Resource{ + { + Source: StrP("data:text/plain;base64,Zm9vCg=="), + }, + }, + }, + }, + { + Node: types3_2.Node{ + Path: "/empty", + }, + FileEmbedded1: types3_2.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_2.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_2.Directory{ + { + Node: types3_2.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_2.NodeUser{ + ID: IntP(1000), + }, + Group: types3_2.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_2.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_2.Link{ + { + Node: types3_2.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_2.NodeUser{ + ID: IntP(1000), + }, + Group: types3_2.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_2.LinkEmbedded1{ + Hard: BoolP(false), + Target: "/foobar", + }, + }, + }, + }, + } + + NonexhaustiveConfig3_4 = types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + Config: types3_4.IgnitionConfig{ + Merge: []types3_4.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_4.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_4.Resource{ + Source: StrP("https://example.com"), + Verification: types3_4.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_4.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_4.Security{ + TLS: types3_4.TLS{ + CertificateAuthorities: []types3_4.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_4.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + Proxy: types3_4.Proxy{ + HTTPProxy: StrP("https://proxy.example.net/"), + HTTPSProxy: StrP("https://secure.proxy.example.net/"), + NoProxy: []types3_4.NoProxyItem{ + "www.example.net", + "www.example2.net", + }, + }, + }, + Storage: types3_4.Storage{ + Disks: []types3_4.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_4.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_4.Raid{ + { + Name: "array", + Level: StrP("raid10"), + Devices: []types3_4.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_4.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_4.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_4.FilesystemOption{"rw"}, + }, + }, + Files: []types3_4.File{ + { + Node: types3_4.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_4.NodeUser{ + ID: IntP(1000), + }, + Group: types3_4.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_4.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_4.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_4.Verification{ + Hash: &aSha512Hash, + }, + HTTPHeaders: types3_4.HTTPHeaders{ + types3_4.HTTPHeader{ + Name: "Authorization", + Value: StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), + }, + types3_4.HTTPHeader{ + Name: "User-Agent", + Value: StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), + }, + }, + }, + }, + }, + }, + { + Node: types3_4.Node{ + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types3_4.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_4.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_4.Directory{ + { + Node: types3_4.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_4.NodeUser{ + ID: IntP(1000), + }, + Group: types3_4.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_4.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_4.Link{ + { + Node: types3_4.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_4.NodeUser{ + ID: IntP(1000), + }, + Group: types3_4.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_4.LinkEmbedded1{ + Hard: BoolP(false), + Target: StrP("/foobar"), + }, + }, + }, + }, + } + + DowntranslateConfig3_3 = types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + Config: types3_3.IgnitionConfig{ + Merge: []types3_3.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Replace: types3_3.Resource{ + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + Timeouts: types3_3.Timeouts{ + HTTPResponseHeaders: IntP(5), + HTTPTotal: IntP(10), + }, + Security: types3_3.Security{ + TLS: types3_3.TLS{ + CertificateAuthorities: []types3_3.Resource{ + { + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + }, + }, + }, + }, + Proxy: types3_3.Proxy{ + HTTPProxy: StrP("https://proxy.example.net/"), + HTTPSProxy: StrP("https://secure.proxy.example.net/"), + NoProxy: []types3_3.NoProxyItem{ + "www.example.net", + "www.example2.net", + }, + }, + }, + Storage: types3_3.Storage{ + Disks: []types3_3.Disk{ + { + Device: "/dev/sda", + WipeTable: BoolP(true), + Partitions: []types3_3.Partition{ + { + Label: StrP("var"), + Number: 1, + SizeMiB: IntP(5000), + StartMiB: IntP(2048), + TypeGUID: &aUUID, + GUID: &aUUID, + WipePartitionEntry: BoolP(true), + ShouldExist: BoolP(true), + }, + }, + }, + }, + Raid: []types3_3.Raid{ + { + Name: "array", + Level: StrP("raid10"), + Devices: []types3_3.Device{"/dev/sdb", "/dev/sdc"}, + Spares: IntP(1), + Options: []types3_3.RaidOption{"foobar"}, + }, + }, + Filesystems: []types3_3.Filesystem{ + { + Path: StrP("/var"), + Device: "/dev/disk/by-partlabel/var", + Format: StrP("xfs"), + WipeFilesystem: BoolP(true), + Label: StrP("var"), + UUID: &aUUID, + Options: []types3_3.FilesystemOption{"rw"}, + }, + }, + Files: []types3_3.File{ + { + Node: types3_3.Node{ + Path: "/var/varfile", + Overwrite: BoolPStrict(false), + User: types3_3.NodeUser{ + ID: IntP(1000), + }, + Group: types3_3.NodeGroup{ + Name: StrP("groupname"), + }, + }, + FileEmbedded1: types3_3.FileEmbedded1{ + Mode: IntP(420), + Append: []types3_3.Resource{ + { + Compression: StrP("gzip"), + Source: StrP("https://example.com"), + Verification: types3_3.Verification{ + Hash: &aSha512Hash, + }, + HTTPHeaders: types3_3.HTTPHeaders{ + types3_3.HTTPHeader{ + Name: "Authorization", + Value: StrP("Basic YWxhZGRpbjpvcGVuc2VzYW1l"), + }, + types3_3.HTTPHeader{ + Name: "User-Agent", + Value: StrP("Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)"), + }, + }, + }, + }, + }, + }, + { + Node: types3_3.Node{ + Path: "/empty", + Overwrite: BoolPStrict(false), + }, + FileEmbedded1: types3_3.FileEmbedded1{ + Mode: IntP(420), + Contents: types3_3.Resource{ + Source: StrPStrict(""), + }, + }, + }, + }, + Directories: []types3_3.Directory{ + { + Node: types3_3.Node{ + Path: "/rootdir", + Overwrite: BoolP(true), + User: types3_3.NodeUser{ + ID: IntP(1000), + }, + Group: types3_3.NodeGroup{ + Name: StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_3.DirectoryEmbedded1{ + Mode: IntP(420), + }, + }, + }, + Links: []types3_3.Link{ + { + Node: types3_3.Node{ + Path: "/rootlink", + Overwrite: BoolP(true), + User: types3_3.NodeUser{ + ID: IntP(1000), + }, + Group: types3_3.NodeGroup{ + Name: StrP("groupname"), + }, + }, + LinkEmbedded1: types3_3.LinkEmbedded1{ + Hard: BoolP(false), + Target: StrP("/foobar"), + }, + }, + }, + }, + } +) From 9665892e02e5afae6b7891cc1b7055ee5683863a Mon Sep 17 00:00:00 2001 From: Steven Presti Date: Wed, 1 Mar 2023 13:06:49 -0500 Subject: [PATCH 2/2] *test.go: refactor existing tests --- translate/v32tov31/v32tov31_test.go | 154 ++++++++++------- translate/v33tov32/v33tov32_test.go | 114 ++++++++----- translate/v34tov33/v34tov33_test.go | 251 +++++++++++++++------------- 3 files changed, 305 insertions(+), 214 deletions(-) diff --git a/translate/v32tov31/v32tov31_test.go b/translate/v32tov31/v32tov31_test.go index cecca7c..21fea54 100644 --- a/translate/v32tov31/v32tov31_test.go +++ b/translate/v32tov31/v32tov31_test.go @@ -15,91 +15,127 @@ package v32tov31 import ( + "fmt" "testing" "github.com/coreos/ign-converter/util" + types3_1 "github.com/coreos/ignition/v2/config/v3_1/types" types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" - "github.com/stretchr/testify/assert" ) func TestTranslate3_2to3_1(t *testing.T) { - emptyConfig := types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - } - - _, err := Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) + type in struct { + data types3_2.Config } - res, err := Translate(util.NonexhaustiveConfig3_2) - if err != nil { - t.Fatalf("Failed translation: %v", err) + type out struct { + data types3_1.Config } - assert.Equal(t, util.NonexhaustiveConfig3_1, res) - _, err = Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - Storage: types3_2.Storage{ - Luks: []types3_2.Luks{ - { - Name: "z", - Device: util.StrP("/dev/z"), + tests := []struct { + in in + out out + err error + }{ + { + in: in{data: types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", }, - }, + }}, + out: out{data: types3_1.Config{ + Ignition: types3_1.Ignition{ + Version: "3.1.0", + }, + }}, }, - }) - assert.Error(t, err) - _, err = Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", + { + in: in{data: util.NonexhaustiveConfig3_2}, + out: out{data: util.NonexhaustiveConfig3_1}, }, - Storage: types3_2.Storage{ - Disks: []types3_2.Disk{ - { - Device: "/dev/a", - Partitions: []types3_2.Partition{ + { + in: in{data: types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + Storage: types3_2.Storage{ + Luks: []types3_2.Luks{ { - Label: util.StrP("z"), - Resize: util.BoolP(true), + Name: "z", + Device: util.StrP("/dev/z"), }, }, }, }, + }, + out: out{data: types3_1.Config{}}, + err: fmt.Errorf("LUKS is not supported on 3.1"), }, - }) - assert.Error(t, err) - _, err = Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", - }, - Passwd: types3_2.Passwd{ - Users: []types3_2.PasswdUser{ - { - Name: "z", - ShouldExist: util.BoolPStrict(false), + { + in: in{data: types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", }, + Storage: types3_2.Storage{ + Disks: []types3_2.Disk{ + { + Device: "/dev/a", + Partitions: []types3_2.Partition{ + { + Label: util.StrP("z"), + Resize: util.BoolP(true), + }, + }, + }, + }, + }, + }, }, + out: out{data: types3_1.Config{}}, + err: fmt.Errorf("Resize in Storage.Disks.Partitions is not supported on 3.1"), }, - }) - assert.Error(t, err) - _, err = Translate(types3_2.Config{ - Ignition: types3_2.Ignition{ - Version: "3.2.0", + { + in: in{data: types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + Passwd: types3_2.Passwd{ + Users: []types3_2.PasswdUser{ + { + Name: "z", + ShouldExist: util.BoolPStrict(false), + }, + }, + }, + }, + }, + out: out{data: types3_1.Config{}}, + err: fmt.Errorf("ShouldExist in Passwd.Users is not supported on 3.1"), }, - Passwd: types3_2.Passwd{ - Groups: []types3_2.PasswdGroup{ - { - Name: "z", - ShouldExist: util.BoolPStrict(false), + { + in: in{data: types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", }, + Passwd: types3_2.Passwd{ + Groups: []types3_2.PasswdGroup{ + { + Name: "z", + ShouldExist: util.BoolPStrict(false), + }, + }, + }, + }, }, + out: out{data: types3_1.Config{}}, + err: fmt.Errorf("ShouldExist in Passwd.Groups is not supported on 3.1"), }, - }) - assert.Error(t, err) + } + + for i, test := range tests { + result, err := Translate(test.in.data) + assert.Equal(t, test.err, err, "#%d: bad error: want %v, got %v", i, test.err, err) + assert.Equal(t, test.out.data, result, "#%d: bad result, want %v, got %v", i, test.out.data, result) + } } diff --git a/translate/v33tov32/v33tov32_test.go b/translate/v33tov32/v33tov32_test.go index 353f6a9..08d3118 100644 --- a/translate/v33tov32/v33tov32_test.go +++ b/translate/v33tov32/v33tov32_test.go @@ -15,63 +15,93 @@ package v33tov32 import ( + "fmt" "testing" "github.com/coreos/ign-converter/util" - + types3_2 "github.com/coreos/ignition/v2/config/v3_2/types" types3_3 "github.com/coreos/ignition/v2/config/v3_3/types" - "github.com/stretchr/testify/assert" ) -func TestTranslate3_3to3_2(t *testing.T) { - emptyConfig := types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - }, - } - - _, err := Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) +func TestTranslate3_3to3_23(t *testing.T) { + type in struct { + data types3_3.Config } - res, err := Translate(util.NonexhaustiveConfig3_3) - if err != nil { - t.Fatalf("Failed translation: %v", err) + type out struct { + data types3_2.Config } - assert.Equal(t, util.NonexhaustiveConfig3_2, res) - _, err = Translate(types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", - }, - KernelArguments: types3_3.KernelArguments{ - ShouldExist: []types3_3.KernelArgument{"foo"}, + tests := []struct { + in in + out out + err error + }{ + { + in: in{data: types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + }}, + out: out{data: types3_2.Config{ + Ignition: types3_2.Ignition{ + Version: "3.2.0", + }, + }}, }, - }) - assert.Error(t, err) - _, err = Translate(types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", + { + in: in{data: util.NonexhaustiveConfig3_3}, + out: out{data: util.NonexhaustiveConfig3_2}, }, - KernelArguments: types3_3.KernelArguments{ - ShouldNotExist: []types3_3.KernelArgument{"foo"}, + { + in: in{data: types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + KernelArguments: types3_3.KernelArguments{ + ShouldExist: []types3_3.KernelArgument{"foo"}, + }, + }}, + out: out{data: types3_2.Config{}}, + err: fmt.Errorf("KernelArguments is not supported on 3.2"), }, - }) - assert.Error(t, err) - _, err = Translate(types3_3.Config{ - Ignition: types3_3.Ignition{ - Version: "3.3.0", + { + + in: in{data: types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + KernelArguments: types3_3.KernelArguments{ + ShouldNotExist: []types3_3.KernelArgument{"foo"}, + }, + }}, + out: out{data: types3_2.Config{}}, + err: fmt.Errorf("KernelArguments is not supported on 3.2"), }, - Storage: types3_3.Storage{ - Filesystems: []types3_3.Filesystem{ - { - Device: "/dev/foo", - Format: util.StrP("util.None"), + { + + in: in{data: types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", }, - }, + Storage: types3_3.Storage{ + Filesystems: []types3_3.Filesystem{ + { + Device: "/dev/foo", + Format: util.StrP("util.None"), + }, + }, + }, + }}, + out: out{data: types3_2.Config{}}, + err: fmt.Errorf("Invalid input config:\nerror at $.storage.filesystems.0.format: invalid filesystem format\n"), }, - }) - assert.Error(t, err) + } + for i, test := range tests { + result, err := Translate(test.in.data) + assert.Equal(t, test.err, err, "#%d: bad error: want %v, got %v", i, test.err, err) + assert.Equal(t, test.out.data, result, "#%d: bad result, want %v, got %v", i, test.out.data, result) + } + } diff --git a/translate/v34tov33/v34tov33_test.go b/translate/v34tov33/v34tov33_test.go index 266e9c0..8d726c0 100644 --- a/translate/v34tov33/v34tov33_test.go +++ b/translate/v34tov33/v34tov33_test.go @@ -15,151 +15,176 @@ package v34tov33 import ( + "fmt" "testing" "github.com/coreos/ign-converter/util" + types3_3 "github.com/coreos/ignition/v2/config/v3_3/types" types3_4 "github.com/coreos/ignition/v2/config/v3_4/types" - "github.com/stretchr/testify/assert" ) func TestTranslate3_4to3_3(t *testing.T) { - emptyConfig := types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - } - - _, err := Translate(emptyConfig) - if err != nil { - t.Fatalf("Failed translation: %v", err) + type in struct { + data types3_4.Config } - res, err := Translate(util.NonexhaustiveConfig3_4) - if err != nil { - t.Fatalf("Failed translation: %v", err) + type out struct { + data types3_3.Config } - assert.Equal(t, util.DowntranslateConfig3_3, res) - _, err = Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", + tests := []struct { + in in + out out + err error + }{ + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + }}, + out: out{data: types3_3.Config{ + Ignition: types3_3.Ignition{ + Version: "3.3.0", + }, + }}, }, - Storage: types3_4.Storage{ - Luks: []types3_4.Luks{ - { - Device: util.StrP("/dev/sda"), - Clevis: types3_4.Clevis{ - Tang: []types3_4.Tang{ - { - URL: "http://example.com", - Thumbprint: util.StrP("z"), - Advertisement: util.StrP("{\"payload\": \"eyJrZXlzIjogW3siYWxnIjogIkVTNTEyIiwgImt0eSI6ICJFQyIsICJjcnYiOiAiUC01MjEiLCAieCI6ICJBRGFNajJmazNob21CWTF5WElSQ21uRk92cmUzOFZjdHMwTnNHeDZ6RWNxdEVXcjh5ekhUMkhfa2hjNGpSa19FQWFLdjNrd2RjZ05sOTBLcGhfMGYyQ190IiwgInkiOiAiQUZ2d1UyeGJ5T1RydWo0V1NtcVlqN2wtcUVTZmhWakdCNTI1Q2d6d0NoZUZRRTBvb1o3STYyamt3NkRKQ05yS3VPUDRsSEhicm8tYXhoUk9MSXNJVExvNCIsICJrZXlfb3BzIjogWyJ2ZXJpZnkiXX0sIHsiYWxnIjogIkVDTVIiLCAia3R5IjogIkVDIiwgImNydiI6ICJQLTUyMSIsICJ4IjogIkFOZDVYcTFvZklUbTdNWG16OUY0VVRSYmRNZFNIMl9XNXczTDVWZ0w3b3hwdmpyM0hkLXNLNUVqd3A1V2swMnJMb3NXVUJjYkZyZEhjZFJTTVJoZlVFTFIiLCAieSI6ICJBRVVaVlVZWkFBY2hVcmdoX3poaTV3SUUzeTEycGwzeWhqUk5LcGpSdW9tUFhKaDhRaFhXRmRWZEtMUlEwX1lwUjNOMjNSUk1pU1lvWlg0Qm42QnlrQVBMIiwgImtleV9vcHMiOiBbImRlcml2ZUtleSJdfV19\", \"protected\": \"eyJhbGciOiJFUzUxMiIsImN0eSI6Imp3ay1zZXQranNvbiJ9\", \"signature\": \"APHfSyVzLwELwG0pMJyIP74gWvhHUvDtv0SESBxA2uOdSXq76IdWHW2xvCZDdlNan8pnqUvEedPZjf_vdKBw9MTXAPMkRxVnu64HepKwlrzzm_zG2R4CHpoCOsGgjH9-acYxg-Vha63oMojv3_bV0VHg-NbzNLaxietgYplstvcNIwkv\"}"), + { + in: in{data: util.NonexhaustiveConfig3_4}, + out: out{data: util.DowntranslateConfig3_3}, + }, + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Luks: []types3_4.Luks{ + { + Device: util.StrP("/dev/sda"), + Clevis: types3_4.Clevis{ + Tang: []types3_4.Tang{ + { + URL: "http://example.com", + Thumbprint: util.StrP("z"), + Advertisement: util.StrP("{\"payload\": \"eyJrZXlzIjogW3siYWxnIjogIkVTNTEyIiwgImt0eSI6ICJFQyIsICJjcnYiOiAiUC01MjEiLCAieCI6ICJBRGFNajJmazNob21CWTF5WElSQ21uRk92cmUzOFZjdHMwTnNHeDZ6RWNxdEVXcjh5ekhUMkhfa2hjNGpSa19FQWFLdjNrd2RjZ05sOTBLcGhfMGYyQ190IiwgInkiOiAiQUZ2d1UyeGJ5T1RydWo0V1NtcVlqN2wtcUVTZmhWakdCNTI1Q2d6d0NoZUZRRTBvb1o3STYyamt3NkRKQ05yS3VPUDRsSEhicm8tYXhoUk9MSXNJVExvNCIsICJrZXlfb3BzIjogWyJ2ZXJpZnkiXX0sIHsiYWxnIjogIkVDTVIiLCAia3R5IjogIkVDIiwgImNydiI6ICJQLTUyMSIsICJ4IjogIkFOZDVYcTFvZklUbTdNWG16OUY0VVRSYmRNZFNIMl9XNXczTDVWZ0w3b3hwdmpyM0hkLXNLNUVqd3A1V2swMnJMb3NXVUJjYkZyZEhjZFJTTVJoZlVFTFIiLCAieSI6ICJBRVVaVlVZWkFBY2hVcmdoX3poaTV3SUUzeTEycGwzeWhqUk5LcGpSdW9tUFhKaDhRaFhXRmRWZEtMUlEwX1lwUjNOMjNSUk1pU1lvWlg0Qm42QnlrQVBMIiwgImtleV9vcHMiOiBbImRlcml2ZUtleSJdfV19\", \"protected\": \"eyJhbGciOiJFUzUxMiIsImN0eSI6Imp3ay1zZXQranNvbiJ9\", \"signature\": \"APHfSyVzLwELwG0pMJyIP74gWvhHUvDtv0SESBxA2uOdSXq76IdWHW2xvCZDdlNan8pnqUvEedPZjf_vdKBw9MTXAPMkRxVnu64HepKwlrzzm_zG2R4CHpoCOsGgjH9-acYxg-Vha63oMojv3_bV0VHg-NbzNLaxietgYplstvcNIwkv\"}"), + }, + }, }, }, }, }, - }, + }}, + err: fmt.Errorf("Invalid input config: tang offline provisioning is not supported in spec v3.3"), }, - }) - assert.Error(t, err) - - _, err = Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Luks: []types3_4.Luks{ - { - Device: util.StrP("/dev/sda"), - Discard: util.BoolP(true), + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", }, - }, - }, - }) - assert.Error(t, err) - - _, err = Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Luks: []types3_4.Luks{ - { - Device: util.StrP("/dev/sda"), - OpenOptions: []types3_4.OpenOption{"foo"}, + Storage: types3_4.Storage{ + Luks: []types3_4.Luks{ + { + Device: util.StrP("/dev/sda"), + Discard: util.BoolP(true), + }, + }, }, - }, - }, - }) - assert.Error(t, err) - - _, err = Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", + }}, + err: fmt.Errorf("Invalid input config: luks discard is not supported in spec v3.3"), }, - Storage: types3_4.Storage{ - Files: []types3_4.File{ - { - Node: types3_4.Node{ - Path: "/root/file.txt", - }, - - FileEmbedded1: types3_4.FileEmbedded1{ - Mode: util.IntP(01777), + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Luks: []types3_4.Luks{ + { + Device: util.StrP("/dev/sda"), + OpenOptions: []types3_4.OpenOption{"foo"}, + }, }, }, - }, + }}, + err: fmt.Errorf("Invalid input config: luks openOptions is not supported in spec v3.3"), }, - }) - - assert.Error(t, err) + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Files: []types3_4.File{ + { + Node: types3_4.Node{ + Path: "/root/file.txt", + }, - _, err = Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Directories: []types3_4.Directory{ - { - Node: types3_4.Node{ - Path: "/rootdir", - Overwrite: util.BoolP(true), - User: types3_4.NodeUser{ - ID: util.IntP(1000), - }, - Group: types3_4.NodeGroup{ - Name: util.StrP("groupname"), + FileEmbedded1: types3_4.FileEmbedded1{ + Mode: util.IntP(01777), + }, }, }, - DirectoryEmbedded1: types3_4.DirectoryEmbedded1{ - Mode: util.IntP(01777), - }, }, - }, + }}, + err: fmt.Errorf("Invalid input config: special mode bits are not supported in spec v3.3"), }, - }) - - assert.Error(t, err) - - _, err = Translate(types3_4.Config{ - Ignition: types3_4.Ignition{ - Version: "3.4.0", - }, - Storage: types3_4.Storage{ - Files: []types3_4.File{ - { - Node: types3_4.Node{ - Path: "/path", + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Directories: []types3_4.Directory{ + { + Node: types3_4.Node{ + Path: "/rootdir", + Overwrite: util.BoolP(true), + User: types3_4.NodeUser{ + ID: util.IntP(1000), + }, + Group: types3_4.NodeGroup{ + Name: util.StrP("groupname"), + }, + }, + DirectoryEmbedded1: types3_4.DirectoryEmbedded1{ + Mode: util.IntP(01777), + }, + }, }, - FileEmbedded1: types3_4.FileEmbedded1{ - Contents: types3_4.Resource{ - Source: util.StrP("arn:aws:s3:us-west-1:123456789012:accesspoint/test/object/some/path"), + }, + }}, + err: fmt.Errorf("Invalid input config: special mode bits are not supported in spec v3.3"), + }, + { + in: in{data: types3_4.Config{ + Ignition: types3_4.Ignition{ + Version: "3.4.0", + }, + Storage: types3_4.Storage{ + Files: []types3_4.File{ + { + Node: types3_4.Node{ + Path: "/path", + }, + FileEmbedded1: types3_4.FileEmbedded1{ + Contents: types3_4.Resource{ + Source: util.StrP("arn:aws:s3:us-west-1:123456789012:accesspoint/test/object/some/path"), + }, + }, }, }, }, - }, + }}, + err: fmt.Errorf("Invalid input config: arn: scheme for s3 is not supported in spec v3.3"), }, - }) - assert.Error(t, err) + } + + for i, test := range tests { + result, err := Translate(test.in.data) + assert.Equal(t, test.err, err, "#%d: bad error: want %v, got %v", i, test.err, err) + assert.Equal(t, test.out.data, result, "#%d: bad result, want %v, got %v", i, test.out.data, result) + } }