Skip to content

Commit

Permalink
wrap errors and add a few more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hroyrh committed Jun 1, 2022
1 parent 2061aa4 commit 2a4e272
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion apis/metal3.io/v1alpha1/baremetalhost_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"

"github.com/google/uuid"
"github.com/pkg/errors"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/metal3-io/baremetal-operator/pkg/hardwareutils/bmc"
Expand Down Expand Up @@ -156,7 +157,7 @@ func validateDNSName(hostaddress string) error {

_, err := bmc.GetParsedURL(hostaddress)
if err != nil {
return fmt.Errorf("host DNS name is invalid")
return errors.Wrap(err, "BMO validation")
}

return nil
Expand Down
34 changes: 28 additions & 6 deletions apis/metal3.io/v1alpha1/baremetalhost_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,26 +383,48 @@ func TestValidateCreate(t *testing.T) {
wantedErr: "",
},
{
name: "invalidDNSNameinvalidcharacter",
name: "invalidDNSNameinvalidhyphenuse",
newBMH: &BareMetalHost{
TypeMeta: tm,
ObjectMeta: om,
Spec: BareMetalHostSpec{
BMC: BMCDetails{
Address: "ipmi://-host.example.com.org"}}},
oldBMH: nil,
wantedErr: "host DNS name is invalid",
wantedErr: "BMO validation: failed to parse BMC address information: BMC address hostname/IP : [-host.example.com.org] is invalid",
},
{
name: "invalidDNSNameinvalidcharacter",
newBMH: &BareMetalHost{
TypeMeta: tm,
ObjectMeta: om,
Spec: BareMetalHostSpec{
BMC: BMCDetails{
Address: "ipmi://host+1.example.com.org"}}},
oldBMH: nil,
wantedErr: "BMO validation: failed to parse BMC address information: BMC address hostname/IP : [host+1.example.com.org] is invalid",
},
{
name: "invalidDNSNameinvalidformat",
newBMH: &BareMetalHost{
TypeMeta: tm,
ObjectMeta: om,
Spec: BareMetalHostSpec{
BMC: BMCDetails{
Address: "[@]host.example.com"}}},
oldBMH: nil,
wantedErr: "BMO validation: failed to parse BMC address information: parse \"ipmi://[@]host.example.com\": net/url: invalid userinfo",
},
{
name: "invalidDNSNameinvalidcharacter2",
name: "invalidDNSNameinvalidbmc",
newBMH: &BareMetalHost{
TypeMeta: tm,
ObjectMeta: om,
Spec: BareMetalHostSpec{
BMC: BMCDetails{
Address: "ipmi://host-.example.com.org"}}},
Address: "ipm:host.example.com:6223"}}},
oldBMH: nil,
wantedErr: "host DNS name is invalid",
wantedErr: "Unknown BMC type 'ipm' for address ipm:host.example.com:6223",
},
{
name: "invalidDNSNameinvalidipv6",
Expand All @@ -413,7 +435,7 @@ func TestValidateCreate(t *testing.T) {
BMC: BMCDetails{
Address: "ipmi://[fe80::fc33:62ff:fe33:8xff]:6223"}}},
oldBMH: nil,
wantedErr: "host DNS name is invalid",
wantedErr: "BMO validation: failed to parse BMC address information: BMC address hostname/IP : [fe80::fc33:62ff:fe33:8xff] is invalid",
},
}

Expand Down

0 comments on commit 2a4e272

Please sign in to comment.