test(pkg/envoy/eds): improve test coverage for clusterLoadAssignment
This pr improves test coverage for the method newClusterLoadAssignment
and converts the test to use go library
Fixes
@@ -2,17 +2,16 @@ 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() {
+func TestNewClusterLoadAssignment(t *testing.T) {
+ assert := tassert.New(t)
namespacedServices := []service.MeshService{
{Namespace: "osm", Name: "bookstore-1"},
@@ -30,18 +29,23 @@ var _ = Describe("Testing Cluster Load Assignment", func() {
}
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)))
+ 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]])
- 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)))
- })
- })
-})
+ 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)
+}
