@@ -17,11 +17,14 @@ limitations under the License.
1717package v1beta1
1818
1919import (
20+ "fmt"
2021 "testing"
2122
2223 "github.com/stretchr/testify/assert"
24+ "github.com/stretchr/testify/require"
2325 "k8s.io/apimachinery/pkg/selection"
2426 "k8s.io/apimachinery/pkg/util/validation/field"
27+ "k8s.io/utils/ptr"
2528)
2629
2730func TestValidateHetznerBareMetalMachineSpecCreate (t * testing.T ) {
@@ -429,3 +432,43 @@ func TestValidateHetznerBareMetalMachineSpecUpdate(t *testing.T) {
429432 })
430433 }
431434}
435+
436+ func TestValidateHetznerBareMetalMachineSpecUpdate_ProviderID (t * testing.T ) {
437+ got := validateHetznerBareMetalMachineSpecUpdate (
438+ HetznerBareMetalMachineSpec {
439+ ProviderID : ptr .To ("provider://foo" ),
440+ },
441+ HetznerBareMetalMachineSpec {})
442+ require .Equal (t , `[spec.providerID: Invalid value: "null": providerID immutable]` , fmt .Sprintf ("%+v" , got ))
443+
444+ got = validateHetznerBareMetalMachineSpecUpdate (
445+ HetznerBareMetalMachineSpec {
446+ ProviderID : ptr .To ("provider://foo" ),
447+ },
448+ HetznerBareMetalMachineSpec {
449+ ProviderID : ptr .To ("provider://bar" ),
450+ })
451+ require .Equal (t , `[spec.providerID: Invalid value: "provider://bar": providerID immutable]` , fmt .Sprintf ("%+v" , got ))
452+
453+ // Allowed Updates
454+ got = validateHetznerBareMetalMachineSpecUpdate (
455+ HetznerBareMetalMachineSpec {},
456+ HetznerBareMetalMachineSpec {})
457+ require .Equal (t , `[]` , fmt .Sprintf ("%+v" , got ))
458+
459+ got = validateHetznerBareMetalMachineSpecUpdate (
460+ HetznerBareMetalMachineSpec {},
461+ HetznerBareMetalMachineSpec {
462+ ProviderID : ptr .To ("provider://bar" ),
463+ })
464+ require .Equal (t , `[]` , fmt .Sprintf ("%+v" , got ))
465+
466+ got = validateHetznerBareMetalMachineSpecUpdate (
467+ HetznerBareMetalMachineSpec {
468+ ProviderID : ptr .To ("provider://bar" ),
469+ },
470+ HetznerBareMetalMachineSpec {
471+ ProviderID : ptr .To ("provider://bar" ),
472+ })
473+ require .Equal (t , `[]` , fmt .Sprintf ("%+v" , got ))
474+ }
0 commit comments