Skip to content

Commit

Permalink
error matching in TestValidatePortMappings
Browse files Browse the repository at this point in the history
Signed-off-by: Daman Arora <[email protected]>
  • Loading branch information
aroradaman committed Jul 9, 2023
1 parent a7df778 commit 7620fc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/internal/apis/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net"
"regexp"
"strconv"
"strings"

"sigs.k8s.io/kind/pkg/errors"
Expand Down Expand Up @@ -171,7 +172,7 @@ func validatePortMappings(portMappings []PortMapping) error {
addrString := addr.String()

portProtocol := formatPortProtocol(portMapping.HostPort, portMapping.Protocol)
possibleErr := fmt.Errorf("%s: %s:%s", errMsg, addrString, portProtocol)
possibleErr := fmt.Errorf("%s: %s/%s", errMsg, net.JoinHostPort(addrString, strconv.Itoa(int(portMapping.HostPort))), portMapping.Protocol)

// in golang 0.0.0.0 and [::] are equivalent, convert [::] -> 0.0.0.0
// https://github.com/golang/go/issues/48723
Expand Down
12 changes: 10 additions & 2 deletions pkg/internal/apis/config/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package config

import (
"fmt"
"sigs.k8s.io/kind/pkg/internal/assert"
"testing"

"sigs.k8s.io/kind/pkg/errors"
Expand Down Expand Up @@ -563,7 +562,16 @@ func TestValidatePortMappings(t *testing.T) {
t.Parallel()

err := validatePortMappings(tc.portMappings)
assert.ExpectError(t, len(tc.expectErr) > 0, err)

// the error can be:
// - nil, in which case we should expect no errors or fail
if err == nil && len(tc.expectErr) > 0 {
t.Errorf("Test failed, unexpected error: %s", tc.expectErr)
}

if err != nil && err.Error() != tc.expectErr {
t.Errorf("Test failed, error: %s expected error: %s", err, tc.expectErr)
}
})
}
}

0 comments on commit 7620fc4

Please sign in to comment.