Skip to content

Commit

Permalink
adding test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: keithfz <[email protected]>
  • Loading branch information
keithfz committed Dec 13, 2024
1 parent aee09ce commit aeead41
Showing 1 changed file with 140 additions and 3 deletions.
143 changes: 140 additions & 3 deletions api/v1alpha1/validation/envoyproxy_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func TestValidateEnvoyProxy(t *testing.T) {
expected: true,
},
{
name: "should be invalid when hpa patch type is empty",
name: "should be valid when pdb patch type and patch are empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Expand All @@ -461,7 +461,7 @@ func TestValidateEnvoyProxy(t *testing.T) {
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyHpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{
EnvoyPDB: &egv1a1.KubernetesPodDisruptionBudgetSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Value: apiextensionsv1.JSON{
Raw: []byte{},
Expand All @@ -475,7 +475,54 @@ func TestValidateEnvoyProxy(t *testing.T) {
expected: true,
},
{
name: "should be invalid when pdb patch type is empty",
name: "should be valid when pdb patch and type are set",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Name: "test",
},
Spec: egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyPDB: &egv1a1.KubernetesPodDisruptionBudgetSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Type: ptr.To(egv1a1.StrategicMerge),
Value: apiextensionsv1.JSON{
Raw: []byte("{}"),
},
},
},
},
},
},
},
expected: true,
},
{
name: "should be invalid when pdb patch not set",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Name: "test",
},
Spec: egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyPDB: &egv1a1.KubernetesPodDisruptionBudgetSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Type: ptr.To(egv1a1.StrategicMerge),
},
},
},
},
},
},
expected: false,
},
{
name: "should be invalid when pdb type not set",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Expand All @@ -486,6 +533,28 @@ func TestValidateEnvoyProxy(t *testing.T) {
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyPDB: &egv1a1.KubernetesPodDisruptionBudgetSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Type: ptr.To(egv1a1.StrategicMerge),
},
},
},
},
},
},
expected: false,
},
{
name: "should be valid when hpa patch and type are empty",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Name: "test",
},
Spec: egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyHpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Value: apiextensionsv1.JSON{
Raw: []byte{},
Expand All @@ -498,6 +567,74 @@ func TestValidateEnvoyProxy(t *testing.T) {
},
expected: true,
},
{
name: "should be valid when hpa patch and type are set",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Name: "test",
},
Spec: egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyHpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Type: ptr.To(egv1a1.StrategicMerge),
Value: apiextensionsv1.JSON{
Raw: []byte("{}"),
},
},
},
},
},
},
},
expected: true,
},
{
name: "should be invalid when hpa patch not set",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Name: "test",
},
Spec: egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyHpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Type: ptr.To(egv1a1.StrategicMerge)},
},
},
},
},
},
expected: false,
},
{
name: "should be invalid when hpa type not set",
proxy: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Name: "test",
},
Spec: egv1a1.EnvoyProxySpec{
Provider: &egv1a1.EnvoyProxyProvider{
Type: egv1a1.ProviderTypeKubernetes,
Kubernetes: &egv1a1.EnvoyProxyKubernetesProvider{
EnvoyHpa: &egv1a1.KubernetesHorizontalPodAutoscalerSpec{
Patch: &egv1a1.KubernetesPatchSpec{
Type: ptr.To(egv1a1.StrategicMerge),
},
},
},
},
},
},
expected: false,
},
{
name: "should invalid when patch object is empty",
proxy: &egv1a1.EnvoyProxy{
Expand Down

0 comments on commit aeead41

Please sign in to comment.