ref(cds): getUpstreamServiceCluster test w/ go testing framework
* convert test from using ginkgo to using built in go
testing framework
package cds
import (
+ "testing"
+
xds_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ tassert "github.com/stretchr/testify/assert"
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/tests"
)
-var _ = Describe("Cluster configurations", func() {
- var (
- mockCtrl *gomock.Controller
- mockConfigurator *configurator.MockConfigurator
- )
-
- mockCtrl = gomock.NewController(GinkgoT())
- mockConfigurator = configurator.NewMockConfigurator(mockCtrl)
+func TestGetUpstreamServiceCluster(t *testing.T) {
+ assert := tassert.New(t)
+ mockCtrl := gomock.NewController(GinkgoT())
+ mockConfigurator := configurator.NewMockConfigurator(mockCtrl)
downstreamSvc := tests.BookbuyerService
upstreamSvc := tests.BookstoreV1Service
- Context("Test getUpstreamServiceCluster", func() {
- It("Returns an EDS based cluster when permissive mode is disabled", func() {
- mockConfigurator.EXPECT().IsPermissiveTrafficPolicyMode().Return(false).Times(1)
+ testCases := []struct {
+ name string
+ permissiveMode bool
+ expectedClusterType xds_cluster.Cluster_DiscoveryType
+ expectedLbPolicy xds_cluster.Cluster_LbPolicy
+ expectedProtocolSelection xds_cluster.Cluster_ClusterProtocolSelection
+ }{
+ {
+ name: "Returns an EDS based cluster when permissive mode is disabled",
+ permissiveMode: false,
+ expectedClusterType: xds_cluster.Cluster_EDS,
+ expectedLbPolicy: xds_cluster.Cluster_ROUND_ROBIN,
+ expectedProtocolSelection: xds_cluster.Cluster_USE_DOWNSTREAM_PROTOCOL,
+ },
+ {
+ name: "Returns an Original Destination based cluster when permissive mode is enabled",
+ permissiveMode: true,
+ expectedClusterType: xds_cluster.Cluster_ORIGINAL_DST,
+ expectedLbPolicy: xds_cluster.Cluster_CLUSTER_PROVIDED,
+ expectedProtocolSelection: xds_cluster.Cluster_USE_DOWNSTREAM_PROTOCOL,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ mockConfigurator.EXPECT().IsPermissiveTrafficPolicyMode().Return(tc.permissiveMode).Times(1)
remoteCluster, err := getUpstreamServiceCluster(upstreamSvc, downstreamSvc, mockConfigurator)
- Expect(err).ToNot(HaveOccurred())
- Expect(remoteCluster.GetType()).To(Equal(xds_cluster.Cluster_EDS))
- Expect(remoteCluster.LbPolicy).To(Equal(xds_cluster.Cluster_ROUND_ROBIN))
- Expect(remoteCluster.ProtocolSelection).To(Equal(xds_cluster.Cluster_USE_DOWNSTREAM_PROTOCOL))
- })
-
- It("Returns an Original Destination based cluster when permissive mode is enabled", func() {
- mockConfigurator.EXPECT().IsPermissiveTrafficPolicyMode().Return(true).Times(1)
-
- remoteCluster, err := getUpstreamServiceCluster(upstreamSvc, downstreamSvc, mockConfigurator)
- Expect(err).ToNot(HaveOccurred())
- Expect(remoteCluster.GetType()).To(Equal(xds_cluster.Cluster_ORIGINAL_DST))
- Expect(remoteCluster.LbPolicy).To(Equal(xds_cluster.Cluster_CLUSTER_PROVIDED))
- Expect(remoteCluster.ProtocolSelection).To(Equal(xds_cluster.Cluster_USE_DOWNSTREAM_PROTOCOL))
- })
- })
+ assert.Nil(err)
+ assert.Equal(tc.expectedClusterType, remoteCluster.GetType())
+ assert.Equal(tc.expectedLbPolicy, remoteCluster.LbPolicy)
+ assert.Equal(tc.expectedProtocolSelection, remoteCluster.ProtocolSelection)
})
+ }
+}
