123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- /*
- Copyright 2014 The Kubernetes Authors.
- 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 framework
- import (
- "github.com/onsi/gomega"
- )
- // ExpectEqual expects the specified two are the same, otherwise an exception raises
- func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{}) {
- gomega.ExpectWithOffset(1, actual).To(gomega.Equal(extra), explain...)
- }
- // ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
- func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{}) {
- gomega.ExpectWithOffset(1, actual).NotTo(gomega.Equal(extra), explain...)
- }
- // ExpectError expects an error happens, otherwise an exception raises
- func ExpectError(err error, explain ...interface{}) {
- gomega.ExpectWithOffset(1, err).To(gomega.HaveOccurred(), explain...)
- }
- // ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
- func ExpectNoError(err error, explain ...interface{}) {
- ExpectNoErrorWithOffset(1, err, explain...)
- }
- // ExpectNoErrorWithOffset checks if "err" is set, and if so, fails assertion while logging the error at "offset" levels above its caller
- // (for example, for call chain f -> g -> ExpectNoErrorWithOffset(1, ...) error would be logged for "f").
- func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
- gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)
- }
- // ExpectConsistOf expects actual contains precisely the extra elements. The ordering of the elements does not matter.
- func ExpectConsistOf(actual interface{}, extra interface{}, explain ...interface{}) {
- gomega.ExpectWithOffset(1, actual).To(gomega.ConsistOf(extra), explain...)
- }
- // ExpectHaveKey expects the actual map has the key in the keyset
- func ExpectHaveKey(actual interface{}, key interface{}, explain ...interface{}) {
- gomega.ExpectWithOffset(1, actual).To(gomega.HaveKey(key), explain...)
- }
- // ExpectEmpty expects actual is empty
- func ExpectEmpty(actual interface{}, explain ...interface{}) {
- gomega.ExpectWithOffset(1, actual).To(gomega.BeEmpty(), explain...)
- }
|