2020-05-11 17:55:49 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-06-18 16:13:24 +02:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
package api
|
2020-05-11 17:55:49 +02:00
|
|
|
|
|
|
|
import (
|
2023-09-26 00:57:12 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2020-05-11 17:55:49 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-08-04 13:45:39 +02:00
|
|
|
"gotest.tools/v3/assert"
|
2020-05-11 17:55:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsNotFound(t *testing.T) {
|
2023-09-26 00:57:12 +02:00
|
|
|
err := fmt.Errorf(`object "name": %w`, ErrNotFound)
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, IsNotFoundError(err))
|
2020-05-11 17:55:49 +02:00
|
|
|
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, !IsNotFoundError(errors.New("another error")))
|
2020-05-11 17:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsAlreadyExists(t *testing.T) {
|
2023-09-26 00:57:12 +02:00
|
|
|
err := fmt.Errorf(`object "name": %w`, ErrAlreadyExists)
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, IsAlreadyExistsError(err))
|
2020-05-11 17:55:49 +02:00
|
|
|
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(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) {
|
2023-09-26 00:57:12 +02:00
|
|
|
err := fmt.Errorf(`object "name": %w`, ErrForbidden)
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, IsForbiddenError(err))
|
2020-05-14 09:53:49 +02:00
|
|
|
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, !IsForbiddenError(errors.New("another error")))
|
2020-05-14 09:53:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsUnknown(t *testing.T) {
|
2023-09-26 00:57:12 +02:00
|
|
|
err := fmt.Errorf(`object "name": %w`, ErrUnknown)
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, IsUnknownError(err))
|
2020-05-14 09:53:49 +02:00
|
|
|
|
2020-08-04 13:45:39 +02:00
|
|
|
assert.Assert(t, !IsUnknownError(errors.New("another error")))
|
2020-05-14 09:53:49 +02:00
|
|
|
}
|