This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit d922c4a3d12a602772450bd836e2a60e65fee1a2
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Thu Apr 22 16:47:36 2021 +0200

    chore(controller): error handler unit test
---
 pkg/apis/camel/v1alpha1/error_handler_types.go     |  7 +-
 pkg/apis/camel/v1alpha1/kamelet_binding_types.go   |  4 --
 .../kameletbinding/error_handler_test.go           | 77 ++++++++++++++++++++++
 3 files changed, 83 insertions(+), 5 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/error_handler_types.go 
b/pkg/apis/camel/v1alpha1/error_handler_types.go
index a6b15b1..df46324 100644
--- a/pkg/apis/camel/v1alpha1/error_handler_types.go
+++ b/pkg/apis/camel/v1alpha1/error_handler_types.go
@@ -21,11 +21,16 @@ import (
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
 
-// ErrorHandler represent an unstructured object for an error handler
+// ErrorHandler represents an unstructured object for an error handler
 type ErrorHandler struct {
        v1.RawMessage `json:",omitempty"`
 }
 
+// ErrorHandlerProperties represent an unstructured object for error handler 
parameters
+type ErrorHandlerProperties struct {
+       v1.RawMessage `json:",inline"`
+}
+
 // AbstractErrorHandler is a generic interface that represent any type of 
error handler specification
 type AbstractErrorHandler interface {
        Type() ErrorHandlerType
diff --git a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go 
b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go
index 5a279e1..62e8079 100644
--- a/pkg/apis/camel/v1alpha1/kamelet_binding_types.go
+++ b/pkg/apis/camel/v1alpha1/kamelet_binding_types.go
@@ -59,10 +59,6 @@ const (
        EndpointTypeErrorHandler EndpointType = "errorHandler"
 )
 
-type ErrorHandlerProperties struct {
-       v1.RawMessage `json:",inline"`
-}
-
 // EndpointProperties is a key/value struct represented as JSON raw to allow 
numeric/boolean values
 type EndpointProperties struct {
        v1.RawMessage `json:",inline"`
diff --git a/pkg/controller/kameletbinding/error_handler_test.go 
b/pkg/controller/kameletbinding/error_handler_test.go
new file mode 100644
index 0000000..1600707
--- /dev/null
+++ b/pkg/controller/kameletbinding/error_handler_test.go
@@ -0,0 +1,77 @@
+/*
+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 kameletbinding
+
+import (
+       "testing"
+
+       "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+       "github.com/stretchr/testify/assert"
+)
+
+func TestParseErrorHandlerNoneDoesSucceed(t *testing.T) {
+       noErrorHandler, err := parseErrorHandler(
+               []byte(`{"none": null}`),
+       )
+       assert.Nil(t, err)
+       assert.Equal(t, v1alpha1.ErrorHandlerTypeNone, noErrorHandler.Type())
+}
+
+func TestParseErrorHandlerLogDoesSucceed(t *testing.T) {
+       logErrorHandler, err := parseErrorHandler(
+               []byte(`{"log": null}`),
+       )
+       assert.Nil(t, err)
+       assert.Equal(t, v1alpha1.ErrorHandlerTypeLog, logErrorHandler.Type())
+}
+
+func TestParseErrorHandlerLogWithParametersDoesSucceed(t *testing.T) {
+       logErrorHandler, err := parseErrorHandler(
+               []byte(`{"log": {"parameters": [{"param1": "value1"}, 
{"param2": "value2"}]}}`),
+       )
+       assert.Nil(t, err)
+       assert.Equal(t, v1alpha1.ErrorHandlerTypeLog, logErrorHandler.Type())
+       assert.NotNil(t, logErrorHandler.Params())
+}
+
+func TestParseErrorHandlerDLCDoesSucceed(t *testing.T) {
+       dlcErrorHandler, err := parseErrorHandler(
+               []byte(`{"dead-letter-channel": {"endpoint": {"uri": 
"someUri"}}}`),
+       )
+       assert.Nil(t, err)
+       assert.Equal(t, v1alpha1.ErrorHandlerTypeDeadLetterChannel, 
dlcErrorHandler.Type())
+       assert.Equal(t, "someUri", *dlcErrorHandler.Endpoint().URI)
+}
+
+func TestParseErrorHandlerDLCWithParametersDoesSucceed(t *testing.T) {
+       dlcErrorHandler, err := parseErrorHandler(
+               []byte(`{
+                       "dead-letter-channel": {
+                               "endpoint": {
+                                       "uri": "someUri"
+                                       }, 
+                               "parameters": 
+                                       [{"param1": "value1"}]
+                       }
+               }`),
+       )
+       assert.Nil(t, err)
+       assert.Equal(t, v1alpha1.ErrorHandlerTypeDeadLetterChannel, 
dlcErrorHandler.Type())
+       assert.Equal(t, "someUri", *dlcErrorHandler.Endpoint().URI)
+       assert.NotNil(t, dlcErrorHandler.Params())
+}

Reply via email to