You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/10/18 08:13:32 UTC
[shardingsphere-on-cloud] branch main updated: chore(reconcile): add unit test for UpdateService
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git
The following commit(s) were added to refs/heads/main by this push:
new 74d9401 chore(reconcile): add unit test for UpdateService
new a73412e Merge pull request #99 from amarps/reconcile_unit_test_update_service
74d9401 is described below
commit 74d9401ef11ce6b2aed56cad0020b55383d7c684
Author: senjaya <am...@gmail.com>
AuthorDate: Tue Oct 18 10:42:08 2022 +0700
chore(reconcile): add unit test for UpdateService
---
.../pkg/reconcile/reconcile_test.go | 62 ++++++++++++++++++++--
1 file changed, 59 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-operator/pkg/reconcile/reconcile_test.go b/shardingsphere-operator/pkg/reconcile/reconcile_test.go
index 2c97d31..0f066f9 100644
--- a/shardingsphere-operator/pkg/reconcile/reconcile_test.go
+++ b/shardingsphere-operator/pkg/reconcile/reconcile_test.go
@@ -19,13 +19,14 @@ package reconcile
import (
"fmt"
+ "strconv"
+ "testing"
+
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
- "k8s.io/api/core/v1"
+ v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "strconv"
- "testing"
)
func Test_IsRunning(t *testing.T) {
@@ -487,7 +488,62 @@ func Test_UpdateDeployment(t *testing.T) {
}
func Test_UpdateService(t *testing.T) {
+ cases := []struct {
+ proxy *v1alpha1.ShardingSphereProxy
+ service *v1.Service
+ message string
+ }{
+ {
+ proxy: &v1alpha1.ShardingSphereProxy{
+ Spec: v1alpha1.ProxySpec{
+ ServiceType: v1alpha1.ServiceType{
+ Type: "ServiceTypeNodePort",
+ NodePort: 3001,
+ },
+ Port: 3000,
+ },
+ },
+ service: &v1.Service{
+ Spec: v1.ServiceSpec{
+ Ports: []v1.ServicePort{{
+ Port: 3000,
+ NodePort: 3001,
+ }},
+ },
+ },
+ message: "Service should be updated",
+ },
+ {
+ proxy: &v1alpha1.ShardingSphereProxy{
+ Spec: v1alpha1.ProxySpec{
+ ServiceType: v1alpha1.ServiceType{
+ Type: "ServiceTypeNodePort",
+ NodePort: 0,
+ },
+ Port: 3000,
+ },
+ },
+ service: &v1.Service{
+ Spec: v1.ServiceSpec{
+ Ports: []v1.ServicePort{{
+ Port: 3000,
+ NodePort: 3001,
+ }},
+ },
+ },
+ message: "Service NodePort should not be updated if proxy nodeport is 0",
+ },
+ }
+ for _, c := range cases {
+ UpdateService(c.proxy, c.service)
+ assert.Equal(t, c.proxy.Spec.ServiceType.Type, c.service.Spec.Type, c.message)
+ assert.Equal(t, c.proxy.Spec.Port, c.service.Spec.Ports[0].Port, c.message)
+ assert.Equal(t, c.proxy.Spec.Port, c.service.Spec.Ports[0].TargetPort.IntVal, c.message)
+ if c.proxy.Spec.ServiceType.NodePort != 0 {
+ assert.Equal(t, c.proxy.Spec.ServiceType.NodePort, c.service.Spec.Ports[0].NodePort, c.message)
+ }
+ }
}
func Test_UpdateHPA(t *testing.T) {