2020-05-11 17:55:49 +02:00
|
|
|
/*
|
2020-06-18 16:13:24 +02:00
|
|
|
Copyright 2020 Docker, Inc.
|
|
|
|
|
|
|
|
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.
|
2020-05-11 17:55:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package errdefs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2020-05-14 19:18:33 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-05-11 17:55:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsNotFound(t *testing.T) {
|
|
|
|
err := errors.Wrap(ErrNotFound, `object "name"`)
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.True(t, IsNotFoundError(err))
|
2020-05-11 17:55:49 +02:00
|
|
|
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.False(t, IsNotFoundError(errors.New("another error")))
|
2020-05-11 17:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsAlreadyExists(t *testing.T) {
|
|
|
|
err := errors.Wrap(ErrAlreadyExists, `object "name"`)
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.True(t, IsAlreadyExistsError(err))
|
2020-05-11 17:55:49 +02:00
|
|
|
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.False(t, IsAlreadyExistsError(errors.New("another error")))
|
2020-05-11 17:55:49 +02:00
|
|
|
}
|
2020-05-14 09:53:49 +02:00
|
|
|
|
|
|
|
func TestIsForbidden(t *testing.T) {
|
|
|
|
err := errors.Wrap(ErrForbidden, `object "name"`)
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.True(t, IsForbiddenError(err))
|
2020-05-14 09:53:49 +02:00
|
|
|
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.False(t, IsForbiddenError(errors.New("another error")))
|
2020-05-14 09:53:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsUnknown(t *testing.T) {
|
|
|
|
err := errors.Wrap(ErrUnknown, `object "name"`)
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.True(t, IsUnknownError(err))
|
2020-05-14 09:53:49 +02:00
|
|
|
|
2020-05-14 19:18:33 +02:00
|
|
|
assert.False(t, IsUnknownError(errors.New("another error")))
|
2020-05-14 09:53:49 +02:00
|
|
|
}
|