From 6ac7ed1b01bcbd193562bd7ab342a14bbad3fe09 Mon Sep 17 00:00:00 2001 From: Maciej Wereski Date: Fri, 7 Jul 2017 12:55:43 +0200 Subject: [PATCH] Add common errors Some types of errors may occur in more than one component of Boruta. For now only one type is introduced, but there will be probably more in the future. Change-Id: Ie0a7eb8490fb2ec1c70d0e8e2fa27d8706d0040e Signed-off-by: Maciej Wereski Reviewed-on: https://mcdsrvbld02.digital.local/review/49277 Reviewed-by: Aleksander Mistewicz --- errors.go | 28 ++++++++++++++++++++++++++++ errors_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 errors.go create mode 100644 errors_test.go diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..43f553e --- /dev/null +++ b/errors.go @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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 + */ + +// File errors.go provides error types that may occur in more than one component. + +package boruta + +import "fmt" + +// NotFoundError is used whenever searched element is missing. +type NotFoundError string + +func (err NotFoundError) Error() string { + return fmt.Sprintf("%s not found", string(err)) +} diff --git a/errors_test.go b/errors_test.go new file mode 100644 index 0000000..d0b6cdc --- /dev/null +++ b/errors_test.go @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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 boruta + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNotFoundErrorString(t *testing.T) { + str := "request not found" + assert.Equal(t, str, NotFoundError("request").Error()) +} -- 2.7.4