mcc: add convertIgnition3to2() unit test
@@ -5,6 +5,7 @@ import (
ign2types "github.com/coreos/ignition/config/v2_2/types"
ign3types "github.com/coreos/ignition/v2/config/v3_0/types"
+ "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -51,3 +52,20 @@ func TestValidateIgnition(t *testing.T) {
isValid3 := ValidateIgnition(testInvalid)
require.NotNil(t, isValid3)
}
+
+func TestConvertIgnition3to2(t *testing.T) {
+
+ // Make a new Ign3 config
+ testIgn3Config := ign3types.Config{}
+ tempUser := ign3types.PasswdUser{Name: "core", SSHAuthorizedKeys: []ign3types.SSHAuthorizedKey{"5678", "abc"}}
+ testIgn3Config.Passwd.Users = []ign3types.PasswdUser{tempUser}
+ testIgn3Config.Ignition.Version = "3.0.0"
+ isValid := ValidateIgnition(testIgn3Config)
+ require.Nil(t, isValid)
+
+ convertedIgn, err := convertIgnition3to2(testIgn3Config)
+ require.Nil(t, err)
+ assert.IsType(t, ign2types.Config{}, convertedIgn)
+ isValid2 := ValidateIgnition(convertedIgn)
+ require.Nil(t, isValid2)
+}
