Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3472 from snehachhabria/claTest
Browse files Browse the repository at this point in the history
test(pkg/envoy/eds): improve test coverage for clusterLoadAssignment
  • Loading branch information
snehachhabria authored Jun 1, 2021
2 parents f1d72d8 + 6b449b1 commit 83c2a38
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions pkg/envoy/eds/cluster_load_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,50 @@ package eds

import (
"net"
"testing"

tassert "github.com/stretchr/testify/assert"

"github.com/openservicemesh/osm/pkg/endpoint"
"github.com/openservicemesh/osm/pkg/service"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Testing Cluster Load Assignment", func() {
Context("Testing NewClusterLoadAssignment", func() {
It("Returns cluster load assignment", func() {

namespacedServices := []service.MeshService{
{Namespace: "osm", Name: "bookstore-1"},
{Namespace: "osm", Name: "bookstore-2"},
}

allServiceEndpoints := map[service.MeshService][]endpoint.Endpoint{
namespacedServices[0]: {
{IP: net.IP("0.0.0.0")},
},
namespacedServices[1]: {
{IP: net.IP("0.0.0.1")},
{IP: net.IP("0.0.0.2")},
},
}

cla := newClusterLoadAssignment(namespacedServices[0], allServiceEndpoints[namespacedServices[0]])
Expect(cla).NotTo(Equal(nil))
Expect(cla.ClusterName).To(Equal("osm/bookstore-1"))
Expect(len(cla.Endpoints)).To(Equal(1))
Expect(len(cla.Endpoints[0].LbEndpoints)).To(Equal(1))
Expect(cla.Endpoints[0].LbEndpoints[0].GetLoadBalancingWeight().Value).To(Equal(uint32(100)))
cla2 := newClusterLoadAssignment(namespacedServices[1], allServiceEndpoints[namespacedServices[1]])
Expect(cla2).NotTo(Equal(nil))
Expect(cla2.ClusterName).To(Equal("osm/bookstore-2"))
Expect(len(cla2.Endpoints)).To(Equal(1))
Expect(len(cla2.Endpoints[0].LbEndpoints)).To(Equal(2))
Expect(cla2.Endpoints[0].LbEndpoints[0].GetLoadBalancingWeight().Value).To(Equal(uint32(50)))
Expect(cla2.Endpoints[0].LbEndpoints[1].GetLoadBalancingWeight().Value).To(Equal(uint32(50)))
})
})
})
func TestNewClusterLoadAssignment(t *testing.T) {
assert := tassert.New(t)

namespacedServices := []service.MeshService{
{Namespace: "osm", Name: "bookstore-1"},
{Namespace: "osm", Name: "bookstore-2"},
}

allServiceEndpoints := map[service.MeshService][]endpoint.Endpoint{
namespacedServices[0]: {
{IP: net.IP("0.0.0.0")},
},
namespacedServices[1]: {
{IP: net.IP("0.0.0.1")},
{IP: net.IP("0.0.0.2")},
},
}

cla := newClusterLoadAssignment(namespacedServices[0], allServiceEndpoints[namespacedServices[0]])
assert.NotNil(cla)
assert.Equal(cla.ClusterName, "osm/bookstore-1")
assert.Len(cla.Endpoints, 1)
assert.Len(cla.Endpoints[0].LbEndpoints, 1)
assert.Equal(cla.Endpoints[0].LbEndpoints[0].GetLoadBalancingWeight().Value, uint32(100))

cla2 := newClusterLoadAssignment(namespacedServices[1], allServiceEndpoints[namespacedServices[1]])
assert.NotNil(cla2)
assert.Equal(cla2.ClusterName, "osm/bookstore-2")
assert.Len(cla2.Endpoints, 1)
assert.Len(cla2.Endpoints[0].LbEndpoints, 2)
assert.Equal(cla2.Endpoints[0].LbEndpoints[0].GetLoadBalancingWeight().Value, uint32(50))
assert.Equal(cla2.Endpoints[0].LbEndpoints[1].GetLoadBalancingWeight().Value, uint32(50))

cla3 := newClusterLoadAssignment(namespacedServices[0], []endpoint.Endpoint{})
assert.NotNil(cla3)
assert.Equal(cla3.ClusterName, "osm/bookstore-1")
assert.Len(cla3.Endpoints, 1)
assert.Len(cla3.Endpoints[0].LbEndpoints, 0)
}

0 comments on commit 83c2a38

Please sign in to comment.