libvmi/cloudinit: allow using WithCloudInitNoCloudUserData twice
libvmi.NewCirros() provides a default non-empty cloud-init user data. To
allow the user override it with test-specific user data as in
libvmi.NewCirros(libvmi.WithCloudInitNoCloudUserData(userData, false))
we need to ensure the default data are not left behind.
@@ -34,9 +34,11 @@ func WithCloudInitNoCloudUserData(data string, b64Encoding bool) Option {
volume := getVolume(vmi, diskName)
if b64Encoding {
encodedData := base64.StdEncoding.EncodeToString([]byte(data))
+ volume.CloudInitNoCloud.UserData = ""
volume.CloudInitNoCloud.UserDataBase64 = encodedData
} else {
volume.CloudInitNoCloud.UserData = data
+ volume.CloudInitNoCloud.UserDataBase64 = ""
}
}
}
