You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "afzal442 (via GitHub)" <gi...@apache.org> on 2023/05/02 04:37:53 UTC

[GitHub] [apisix-ingress-controller] afzal442 commented on a diff in pull request #1822: Create apisix_plugin_config_test.go

afzal442 commented on code in PR #1822:
URL: https://github.com/apache/apisix-ingress-controller/pull/1822#discussion_r1182074235


##########
pkg/api/validation/apisix_plugin_config_test.go:
##########
@@ -0,0 +1,92 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package validation
+
+import (
+	"testing"
+
+	v2 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2"
+)
+
+func TestValidateApisixRoutePlugins(t *testing.T) {
+	validPlugins := []v2.ApisixRoutePlugin{
+		{
+			Name: "plugin1",
+			Config: v2.ApisixRoutePluginConfig{
+				"param1": "value1",
+				"param2": 123,
+			},
+		},
+		{
+			Name: "plugin2",
+			Config: v2.ApisixRoutePluginConfig{
+				"param1": "value2",
+			},
+		},
+	}
+
+	invalidPlugins := []v2.ApisixRoutePlugin{
+		{
+			Name:   "",
+			Config: v2.ApisixRoutePluginConfig{},
+		},
+		{
+			Name: "plugin1",
+			Config: v2.ApisixRoutePluginConfig{
+				"param1": "value1",
+				"param2": "invalid",
+			},
+		},
+	}
+
+	tests := []struct {
+		name        string
+		plugins     []v2.ApisixRoutePlugin
+		expectValid bool
+		expectError bool
+	}{
+		{
+			name:        "Valid ApisixRoutePlugin objects",
+			plugins:     validPlugins,
+			expectValid: true,
+			expectError: false,
+		},
+		{
+			name: "Invalid ApisixRoutePlugin objects with empty name and config",
+			plugins: []v2.ApisixRoutePlugin{
+				{Name: "", Config: v2.ApisixRoutePluginConfig{}},
+			},
+			expectValid: false,
+			expectError: false,
+		},
+		{
+			name:        "Invalid ApisixRoutePlugin objects with invalid config value",
+			plugins:     invalidPlugins,
+			expectValid: false,
+			expectError: false,
+		},
+	}
+
+	for _, tc := range tests {
+		t.Run(tc.name, func(t *testing.T) {
+			_, err := ValidateApisixRoutePlugins(tc.plugins)

Review Comment:
   @khareyash05 you have to call `ValidateApisixPluginConfigV2` to verify as told by @Gallardot . You can do like below and compare it with your `expectValid`
   ```suggestion
   			gotValid, err := ValidateApisixRoutePlugins(tc.plugins)
   ```
   Also you can take a look at the ApisixPluginConfig definition and restructure your specs of it https://github.com/apache/apisix-ingress-controller/blob/2182a48cbca785373eca745a13d8cf2b7d9ab6c8/pkg/kube/apisix/apis/config/v2/types.go#L796.
   https://github.com/apache/apisix-ingress-controller/blob/2182a48cbca785373eca745a13d8cf2b7d9ab6c8/pkg/kube/apisix/apis/config/v2/types.go#L786



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org