Skip to content

Commit

Permalink
clean test
Browse files Browse the repository at this point in the history
Signed-off-by: hejianpeng <[email protected]>
  • Loading branch information
zirain committed Apr 11, 2023
1 parent b0bff3d commit 141f1a6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
38 changes: 0 additions & 38 deletions internal/infrastructure/kubernetes/ratelimit_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,13 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"

egcfgv1a1 "github.com/envoyproxy/gateway/api/config/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes/ratelimit"
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes/utils"
"github.com/envoyproxy/gateway/internal/ir"
)

func TestDesiredRateLimitService(t *testing.T) {
cfg, err := config.New()
require.NoError(t, err)
cli := fakeclient.NewClientBuilder().WithScheme(envoygateway.GetScheme()).WithObjects().Build()
kube := NewInfra(cli, cfg)
rateLimitInfra := new(ir.RateLimitInfra)
rl := &egcfgv1a1.RateLimit{
Backend: egcfgv1a1.RateLimitDatabaseBackend{
Type: egcfgv1a1.RedisBackendType,
Redis: &egcfgv1a1.RateLimitRedisSettings{
URL: "redis.redis.svc:6379",
},
},
}

r := ratelimit.NewResourceRender(kube.Namespace, rateLimitInfra, rl, kube.EnvoyGateway.GetEnvoyGatewayProvider().GetEnvoyGatewayKubeProvider().RateLimitDeployment)
svc, err := r.Service()
require.NoError(t, err)

// Check the service name is as expected.
assert.Equal(t, svc.Name, ratelimit.InfraName)

checkServiceHasPort(t, svc, ratelimit.InfraGRPCPort)

// Ensure the Envoy RateLimit service has the expected labels.
lbls := map[string]string{
"app.gateway.envoyproxy.io/name": ratelimit.InfraName,
}
checkServiceHasLabels(t, svc, lbls)

checkServiceSpec(t, svc, utils.ExpectedServiceSpec(egcfgv1a1.DefaultKubernetesServiceType()))
}

func TestDeleteRateLimitService(t *testing.T) {
rl := &egcfgv1a1.RateLimit{
Backend: egcfgv1a1.RateLimitDatabaseBackend{
Expand Down
39 changes: 0 additions & 39 deletions internal/infrastructure/kubernetes/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ package kubernetes
import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/envoyproxy/gateway/api/config/v1alpha1"
egcfgv1a1 "github.com/envoyproxy/gateway/api/config/v1alpha1"
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes/utils"
)

func checkServiceHasPort(t *testing.T, svc *corev1.Service, port int32) {
Expand Down Expand Up @@ -83,37 +78,3 @@ func checkServiceSpec(t *testing.T, svc *corev1.Service, expected corev1.Service

t.Errorf("service has unexpected %q spec", &svc.Spec)
}

func TestExpectedServiceSpec(t *testing.T) {
type args struct {
serviceType *v1alpha1.ServiceType
}
tests := []struct {
name string
args args
want corev1.ServiceSpec
}{
{
name: "LoadBalancer",
args: args{serviceType: egcfgv1a1.GetKubernetesServiceType(egcfgv1a1.ServiceTypeLoadBalancer)},
want: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
SessionAffinity: corev1.ServiceAffinityNone,
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeLocal,
},
},
{
name: "ClusterIP",
args: args{serviceType: egcfgv1a1.GetKubernetesServiceType(egcfgv1a1.ServiceTypeClusterIP)},
want: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
SessionAffinity: corev1.ServiceAffinityNone,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, utils.ExpectedServiceSpec(tt.args.serviceType), "expectedServiceSpec(%v)", tt.args.serviceType)
})
}
}

0 comments on commit 141f1a6

Please sign in to comment.