Skip to content

Commit

Permalink
Add AppMesh routing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Mar 17, 2019
1 parent 0ef1d0b commit 337c943
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/router/appmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ func (ar *AppmeshRouter) GetRoutes(canary *flaggerv1.Canary) (
}

// SetRoutes updates the destinations weight for primary and canary
func (ar *AppmeshRouter)SetRoutes(
func (ar *AppmeshRouter) SetRoutes(
canary *flaggerv1.Canary,
primaryWeight int,
canaryWeight int,
) error {
) error {
targetName := canary.Spec.TargetRef.Name
vsName := fmt.Sprintf("%s.%s", targetName, canary.Namespace)
vs, err := ar.appmeshClient.AppmeshV1alpha1().VirtualServices(canary.Namespace).Get(vsName, metav1.GetOptions{})
Expand Down Expand Up @@ -314,4 +314,4 @@ func (ar *AppmeshRouter)SetRoutes(
}

return nil
}
}
45 changes: 39 additions & 6 deletions pkg/router/appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestAppmeshRouter_Sync(t *testing.T) {
router := &AppmeshRouter{
logger: mocks.logger,
flaggerClient: mocks.flaggerClient,
appMeshClient: mocks.meshClient,
appmeshClient: mocks.meshClient,
kubeClient: mocks.kubeClient,
}

Expand All @@ -22,7 +22,7 @@ func TestAppmeshRouter_Sync(t *testing.T) {

// check virtual service
vsName := fmt.Sprintf("%s.%s", mocks.appmeshCanary.Spec.TargetRef.Name, mocks.appmeshCanary.Namespace)
vs, err := router.appMeshClient.AppmeshV1alpha1().VirtualServices("default").Get(vsName, metav1.GetOptions{})
vs, err := router.appmeshClient.AppmeshV1alpha1().VirtualServices("default").Get(vsName, metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -39,7 +39,7 @@ func TestAppmeshRouter_Sync(t *testing.T) {

// check virtual node
vnName := fmt.Sprintf("%s-%s", mocks.appmeshCanary.Spec.TargetRef.Name, mocks.appmeshCanary.Namespace)
vn, err := router.appMeshClient.AppmeshV1alpha1().VirtualNodes("default").Get(vnName, metav1.GetOptions{})
vn, err := router.appmeshClient.AppmeshV1alpha1().VirtualNodes("default").Get(vnName, metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestAppmeshRouter_Sync(t *testing.T) {

// verify
vnCanaryName := fmt.Sprintf("%s-canary-%s", mocks.appmeshCanary.Spec.TargetRef.Name, mocks.appmeshCanary.Namespace)
vnCanary, err := router.appMeshClient.AppmeshV1alpha1().VirtualNodes("default").Get(vnCanaryName, metav1.GetOptions{})
vnCanary, err := router.appmeshClient.AppmeshV1alpha1().VirtualNodes("default").Get(vnCanaryName, metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -96,7 +96,7 @@ func TestAppmeshRouter_Sync(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
vs, err = router.appMeshClient.AppmeshV1alpha1().VirtualServices("default").Get(vsName, metav1.GetOptions{})
vs, err = router.appmeshClient.AppmeshV1alpha1().VirtualServices("default").Get(vsName, metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -119,7 +119,7 @@ func TestAppmeshRouter_Sync(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
vs, err = router.appMeshClient.AppmeshV1alpha1().VirtualServices("default").Get(vsName, metav1.GetOptions{})
vs, err = router.appmeshClient.AppmeshV1alpha1().VirtualServices("default").Get(vsName, metav1.GetOptions{})
if err != nil {
t.Fatal(err.Error())
}
Expand All @@ -129,3 +129,36 @@ func TestAppmeshRouter_Sync(t *testing.T) {
t.Errorf("Got prefix %v wanted %v", prefix, "/")
}
}

func TestAppmeshRouter_GetSetRoutes(t *testing.T) {
mocks := setupfakeClients()
router := &AppmeshRouter{
logger: mocks.logger,
flaggerClient: mocks.flaggerClient,
appmeshClient: mocks.meshClient,
kubeClient: mocks.kubeClient,
}

err := router.Sync(mocks.appmeshCanary)
if err != nil {
t.Fatal(err.Error())
}

err = router.SetRoutes(mocks.appmeshCanary, 60, 40)
if err != nil {
t.Fatal(err.Error())
}

p, c, err := router.GetRoutes(mocks.appmeshCanary)
if err != nil {
t.Fatal(err.Error())
}

if p != 60 {
t.Errorf("Got primary weight %v wanted %v", p, 60)
}

if c != 40 {
t.Errorf("Got canary weight %v wanted %v", c, 40)
}
}

0 comments on commit 337c943

Please sign in to comment.