mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
bugfix for ProviderID parsing & corresponding unit test
This commit is contained in:
parent
bc9d2e8832
commit
c261f98a60
@ -3583,7 +3583,7 @@ var providerIDRegexp = regexp.MustCompile(`^aws://([^/]+)$`)
|
||||
|
||||
func instanceIDFromProviderID(providerID string) (instanceID string, err error) {
|
||||
matches := providerIDRegexp.FindStringSubmatch(providerID)
|
||||
if len(matches) != 1 {
|
||||
if len(matches) != 2 {
|
||||
return "", fmt.Errorf("ProviderID \"%s\" didn't match expected format \"aws://InstanceID\"", providerID)
|
||||
}
|
||||
|
||||
|
@ -322,6 +322,12 @@ func (self *FakeEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*
|
||||
return matches, nil
|
||||
}
|
||||
|
||||
func (self *FakeEC2) DescribeAddresses(request *ec2.DescribeAddressesInput) ([]*ec2.Address, error) {
|
||||
addresses := []*ec2.Address{}
|
||||
|
||||
return addresses, nil
|
||||
}
|
||||
|
||||
type FakeMetadata struct {
|
||||
aws *FakeAWSServices
|
||||
}
|
||||
@ -1350,3 +1356,37 @@ func TestGetLoadBalancerAdditionalTags(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstanceIDFromProviderID(t *testing.T) {
|
||||
testCases := []struct {
|
||||
providerID string
|
||||
instanceID string
|
||||
fail bool
|
||||
}{
|
||||
{
|
||||
providerID: "aws://i-0194bbdb81a49b169",
|
||||
instanceID: "i-0194bbdb81a49b169",
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
providerID: "i-0194bbdb81a49b169",
|
||||
instanceID: "",
|
||||
fail: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
instanceID, err := instanceIDFromProviderID(test.providerID)
|
||||
if (err != nil) != test.fail {
|
||||
t.Errorf("%s yielded `err != nil` as %t. expected %t", test.providerID, (err != nil), test.fail)
|
||||
}
|
||||
|
||||
if test.fail {
|
||||
continue
|
||||
}
|
||||
|
||||
if instanceID != test.instanceID {
|
||||
t.Errorf("%s yielded %s. expected %s", test.providerID, instanceID, test.instanceID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user