Add common errors
authorMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 7 Jul 2017 10:55:43 +0000 (12:55 +0200)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Thu, 5 Oct 2017 10:39:23 +0000 (12:39 +0200)
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 <m.wereski@partner.samsung.com>
Reviewed-on: https://mcdsrvbld02.digital.local/review/49277
Reviewed-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
errors.go [new file with mode: 0644]
errors_test.go [new file with mode: 0644]

diff --git a/errors.go b/errors.go
new file mode 100644 (file)
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 (file)
index 0000000..d0b6cdc
--- /dev/null
@@ -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())
+}