mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Unit test for aws_lb security group filtering
kubernetes/kubernetes#60825
This commit is contained in:
parent
f052146a96
commit
996c37c72b
@ -17,9 +17,11 @@ limitations under the License.
|
|||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestElbProtocolsAreEqual(t *testing.T) {
|
func TestElbProtocolsAreEqual(t *testing.T) {
|
||||||
@ -160,3 +162,63 @@ func TestIsNLB(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSecurityGroupFiltering(t *testing.T) {
|
||||||
|
grid := []struct {
|
||||||
|
in []*ec2.SecurityGroup
|
||||||
|
name string
|
||||||
|
expected int
|
||||||
|
description string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
in: []*ec2.SecurityGroup{
|
||||||
|
{
|
||||||
|
IpPermissions: []*ec2.IpPermission{
|
||||||
|
{
|
||||||
|
IpRanges: []*ec2.IpRange{
|
||||||
|
{
|
||||||
|
Description: aws.String("an unmanaged"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "unmanaged",
|
||||||
|
expected: 0,
|
||||||
|
description: "An environment without managed LBs should have %d, but found %d SecurityGroups",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
in: []*ec2.SecurityGroup{
|
||||||
|
{
|
||||||
|
IpPermissions: []*ec2.IpPermission{
|
||||||
|
{
|
||||||
|
IpRanges: []*ec2.IpRange{
|
||||||
|
{
|
||||||
|
Description: aws.String("an unmanaged"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: aws.String(fmt.Sprintf("%s=%s", NLBClientRuleDescription, "managedlb")),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Description: aws.String(fmt.Sprintf("%s=%s", NLBHealthCheckRuleDescription, "managedlb")),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "managedlb",
|
||||||
|
expected: 1,
|
||||||
|
description: "Found %d, but should have %d Security Groups",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, g := range grid {
|
||||||
|
actual := len(filterForIPRangeDescription(g.in, g.name))
|
||||||
|
if actual != g.expected {
|
||||||
|
t.Errorf(g.description, actual, g.expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user