Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding test cases for TcpRouteMatch #720

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions pkg/virtualrouter/routes_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,72 @@ func Test_BuildSDKRouteSpec(t *testing.T) {
},
},
},
{
name: "TCP route with Match",
args: args{
vr: &appmesh.VirtualRouter{
ObjectMeta: v1.ObjectMeta{
Namespace: "my-ns",
},
},
route: appmesh.Route{
TCPRoute: &appmesh.TCPRoute{
Action: appmesh.TCPRouteAction{
WeightedTargets: []appmesh.WeightedTarget{
{
VirtualNodeRef: &appmesh.VirtualNodeReference{
Namespace: aws.String("ns-1"),
Name: "vn-1",
},
Weight: int64(100),
},
{
VirtualNodeRef: &appmesh.VirtualNodeReference{
Namespace: aws.String("ns-2"),
Name: "vn-2",
},
Weight: int64(90),
},
},
},
Match: &appmesh.TCPRouteMatch{
Port: aws.Int64(8080),
},
},
},
vnByKey: map[types.NamespacedName]*appmesh.VirtualNode{
types.NamespacedName{Namespace: "ns-1", Name: "vn-1"}: {
Spec: appmesh.VirtualNodeSpec{
AWSName: aws.String("vn-1_ns-1"),
},
},
types.NamespacedName{Namespace: "ns-2", Name: "vn-2"}: {
Spec: appmesh.VirtualNodeSpec{
AWSName: aws.String("vn-2_ns-2"),
},
},
},
},
want: &appmeshsdk.RouteSpec{
TcpRoute: &appmeshsdk.TcpRoute{
Action: &appmeshsdk.TcpRouteAction{
WeightedTargets: []*appmeshsdk.WeightedTarget{
{
VirtualNode: aws.String("vn-1_ns-1"),
Weight: aws.Int64(100),
},
{
VirtualNode: aws.String("vn-2_ns-2"),
Weight: aws.Int64(90),
},
},
},
Match: &appmeshsdk.TcpRouteMatch{
Port: aws.Int64(8080),
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
41 changes: 41 additions & 0 deletions test/framework/manifest/virtualrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ type RouteToWeightedVirtualNodes struct {
WeightedTargets []WeightedVirtualNode
}

type TcpRouteToWeightedVirtualNodes struct {
Match *TCPRouteMatch
WeightedTargets []WeightedVirtualNode
}
type TCPRouteMatch struct {
Port *int64
}
type WeightedVirtualNode struct {
VirtualNode types.NamespacedName
Weight int64
Expand Down Expand Up @@ -68,6 +75,34 @@ func (b *VRBuilder) BuildRoutes(routeCfgs []RouteToWeightedVirtualNodes) []appme
return routes

}
func (b *VRBuilder) TcpBuildRoutes(tcpRoutesCFgs []TcpRouteToWeightedVirtualNodes) []appmesh.Route {

var routes []appmesh.Route
for index, tcpRouteCfg := range tcpRoutesCFgs {
var targets []appmesh.WeightedTarget
for _, weightedTarget := range tcpRouteCfg.WeightedTargets {
targets = append(targets, appmesh.WeightedTarget{
VirtualNodeRef: &appmesh.VirtualNodeReference{
Namespace: aws.String(weightedTarget.VirtualNode.Namespace),
Name: weightedTarget.VirtualNode.Name,
},
Weight: weightedTarget.Weight,
})
}
//match:= if tcpRouteCfg.
routes = append(routes, appmesh.Route{
Name: fmt.Sprintf("route-%d", index),
TCPRoute: &appmesh.TCPRoute{
Match: (*appmesh.TCPRouteMatch)(tcpRouteCfg.Match),
Action: appmesh.TCPRouteAction{
WeightedTargets: targets,
},
Timeout: nil,
},
})
}
return routes
}

func (b *VRBuilder) BuildVirtualRouterListener(protocol appmesh.PortProtocol, port appmesh.PortNumber) appmesh.VirtualRouterListener {
return appmesh.VirtualRouterListener{
Expand All @@ -78,6 +113,12 @@ func (b *VRBuilder) BuildVirtualRouterListener(protocol appmesh.PortProtocol, po
}
}

func (b *VRBuilder) BuildTcpRouteMatch(port *int64) *TCPRouteMatch {
return &TCPRouteMatch{
Port: port,
}
}

func (b *VRBuilder) buildName(instanceName string) string {
return instanceName
}
Expand Down
114 changes: 114 additions & 0 deletions test/integration/virtualrouter/virtualrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,47 @@ var _ = Describe("VirtualRouter", func() {

})

tcpRouteCfgsWithMatch := []manifest.TcpRouteToWeightedVirtualNodes{{
WeightedTargets: weightedTargets,
Match: vrBuilder.BuildTcpRouteMatch(aws.Int64(8080)),
},
}
tcpRoutes := vrBuilder.TcpBuildRoutes(tcpRouteCfgsWithMatch)
vrBuilder.Listeners = []appmesh.VirtualRouterListener{vrBuilder.BuildVirtualRouterListener("tcp", 8080)}
vrName = fmt.Sprintf("vr-%s", utils.RandomDNS1123Label(8))
vr = vrBuilder.BuildVirtualRouter(vrName, tcpRoutes)

By("Creating a virtual router resource with TCP listener and Port Match in k8s", func() {
err := vrTest.Create(ctx, f, vr)
Expect(err).NotTo(HaveOccurred())
})

By("Validating the virtual router with TCP listener and Port Match in AWS", func() {
err := vrTest.CheckInAWS(ctx, f, mesh, vr)
Expect(err).NotTo(HaveOccurred())

})

tcpRouteCfgsWithoutMatch := []manifest.TcpRouteToWeightedVirtualNodes{{
WeightedTargets: weightedTargets,
},
}
tcpRoutes = vrBuilder.TcpBuildRoutes(tcpRouteCfgsWithoutMatch)
vrBuilder.Listeners = []appmesh.VirtualRouterListener{vrBuilder.BuildVirtualRouterListener("tcp", 8080)}
vrName = fmt.Sprintf("vr-%s", utils.RandomDNS1123Label(8))
vr = vrBuilder.BuildVirtualRouter(vrName, tcpRoutes)

By("Creating a virtual router resource with TCP listener and Port Match in k8s", func() {
err := vrTest.Create(ctx, f, vr)
Expect(err).NotTo(HaveOccurred())
})

By("Validating the virtual router with TCP listener and Port Match in AWS", func() {
err := vrTest.CheckInAWS(ctx, f, mesh, vr)
Expect(err).NotTo(HaveOccurred())

})

routes = vrBuilder.BuildRoutes(routeCfgs)
vrBuilder.Listeners = []appmesh.VirtualRouterListener{vrBuilder.BuildVirtualRouterListener("http", 8080)}
vrName = fmt.Sprintf("vr-%s", utils.RandomDNS1123Label(8))
Expand Down Expand Up @@ -364,6 +405,79 @@ var _ = Describe("VirtualRouter", func() {
Expect(err).NotTo(HaveOccurred())
})

tcpRouteCfgsWithMatch := []manifest.TcpRouteToWeightedVirtualNodes{{
WeightedTargets: weightedTargets,
Match: vrBuilder.BuildTcpRouteMatch(aws.Int64(8080)),
},
}
tcpRoutes := vrBuilder.TcpBuildRoutes(tcpRouteCfgsWithMatch)
vrBuilder.Listeners = []appmesh.VirtualRouterListener{vrBuilder.BuildVirtualRouterListener("tcp", 8080)}
vrName = fmt.Sprintf("vr-%s", utils.RandomDNS1123Label(8))
vr = vrBuilder.BuildVirtualRouter(vrName, tcpRoutes)

By("Creating a virtual router resource with TCP listener and Port Match in k8s", func() {
err := vrTest.Create(ctx, f, vr)
Expect(err).NotTo(HaveOccurred())
})

By("Validating the virtual router with TCP listener and Port Match in AWS", func() {
err := vrTest.CheckInAWS(ctx, f, mesh, vr)
Expect(err).NotTo(HaveOccurred())

})
By("Update the virtual router to not have Match and validating", func() {
oldVR := vrTest.VirtualRouters[vr.Name].DeepCopy()

tcpRouteCfgs := []manifest.TcpRouteToWeightedVirtualNodes{{
WeightedTargets: weightedTargets,
}}

routes := vrBuilder.TcpBuildRoutes(tcpRouteCfgs)
vrTest.VirtualRouters[vr.Name].Spec.Routes = routes

err := vrTest.Update(ctx, f, vrTest.VirtualRouters[vr.Name], oldVR)
Expect(err).NotTo(HaveOccurred())

err = vrTest.CheckInAWS(ctx, f, mesh, vrTest.VirtualRouters[vr.Name])
Expect(err).NotTo(HaveOccurred())
})
tcpRouteCfgsWithoutMatch := []manifest.TcpRouteToWeightedVirtualNodes{{
WeightedTargets: weightedTargets,
},
}
tcpRoutes = vrBuilder.TcpBuildRoutes(tcpRouteCfgsWithoutMatch)
vrBuilder.Listeners = []appmesh.VirtualRouterListener{vrBuilder.BuildVirtualRouterListener("tcp", 8080)}
vrName = fmt.Sprintf("vr-%s", utils.RandomDNS1123Label(8))
vr = vrBuilder.BuildVirtualRouter(vrName, tcpRoutes)

By("Creating a virtual router resource with TCP listener and Port Match in k8s", func() {
err := vrTest.Create(ctx, f, vr)
Expect(err).NotTo(HaveOccurred())
})

By("Validating the virtual router with TCP listener and Port Match in AWS", func() {
err := vrTest.CheckInAWS(ctx, f, mesh, vr)
Expect(err).NotTo(HaveOccurred())

})
By("Update the virtual router to have Match and validating", func() {
oldVR := vrTest.VirtualRouters[vr.Name].DeepCopy()

tcpRouteCfgs := []manifest.TcpRouteToWeightedVirtualNodes{{
WeightedTargets: weightedTargets,
Match: vrBuilder.BuildTcpRouteMatch(aws.Int64(8080)),
}}

routes := vrBuilder.TcpBuildRoutes(tcpRouteCfgs)
vrTest.VirtualRouters[vr.Name].Spec.Routes = routes

err := vrTest.Update(ctx, f, vrTest.VirtualRouters[vr.Name], oldVR)
Expect(err).NotTo(HaveOccurred())

err = vrTest.CheckInAWS(ctx, f, mesh, vrTest.VirtualRouters[vr.Name])
Expect(err).NotTo(HaveOccurred())
})

})

It("Delete virtual router scenarios", func() {
Expand Down
Loading