summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/gomega/gstruct/elements_test.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-02-05 11:51:41 +0100
committerValentin Rothberg <rothberg@redhat.com>2019-02-06 11:14:06 +0100
commit9ac0ebb0791851aea81ecc847802db5a39bfb6e7 (patch)
tree30ad98bcc2c2dd1136f46a48cbc44d422adfa184 /vendor/github.com/onsi/gomega/gstruct/elements_test.go
parent51714d5da7aaa19014fd67b48b79dfbd5f69c1f0 (diff)
downloadpodman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.gz
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.bz2
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.zip
Cirrus: add vendor_check_task
* Make sure that all vendored dependencies are in sync with the code and the vendor.conf by running `make vendor` with a follow-up status check of the git tree. * Vendor ginkgo and gomega to include the test dependencies. Signed-off-by: Chris Evic <cevich@redhat.com> Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/onsi/gomega/gstruct/elements_test.go')
-rw-r--r--vendor/github.com/onsi/gomega/gstruct/elements_test.go144
1 files changed, 144 insertions, 0 deletions
diff --git a/vendor/github.com/onsi/gomega/gstruct/elements_test.go b/vendor/github.com/onsi/gomega/gstruct/elements_test.go
new file mode 100644
index 000000000..355d463eb
--- /dev/null
+++ b/vendor/github.com/onsi/gomega/gstruct/elements_test.go
@@ -0,0 +1,144 @@
+package gstruct_test
+
+import (
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gstruct"
+)
+
+var _ = Describe("Slice", func() {
+ allElements := []string{"a", "b"}
+ missingElements := []string{"a"}
+ extraElements := []string{"a", "b", "c"}
+ duplicateElements := []string{"a", "a", "b"}
+ empty := []string{}
+ var nils []string
+
+ It("should strictly match all elements", func() {
+ m := MatchAllElements(id, Elements{
+ "b": Equal("b"),
+ "a": Equal("a"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(missingElements).ShouldNot(m, "should fail with missing elements")
+ Expect(extraElements).ShouldNot(m, "should fail with extra elements")
+ Expect(duplicateElements).ShouldNot(m, "should fail with duplicate elements")
+ Expect(nils).ShouldNot(m, "should fail with an uninitialized slice")
+
+ m = MatchAllElements(id, Elements{
+ "a": Equal("a"),
+ "b": Equal("fail"),
+ })
+ Expect(allElements).ShouldNot(m, "should run nested matchers")
+
+ m = MatchAllElements(id, Elements{})
+ Expect(empty).Should(m, "should handle empty slices")
+ Expect(allElements).ShouldNot(m, "should handle only empty slices")
+ Expect(nils).Should(m, "should handle nil slices")
+ })
+
+ It("should ignore extra elements", func() {
+ m := MatchElements(id, IgnoreExtras, Elements{
+ "b": Equal("b"),
+ "a": Equal("a"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(missingElements).ShouldNot(m, "should fail with missing elements")
+ Expect(extraElements).Should(m, "should ignore extra elements")
+ Expect(duplicateElements).ShouldNot(m, "should fail with duplicate elements")
+ Expect(nils).ShouldNot(m, "should fail with an uninitialized slice")
+ })
+
+ It("should ignore missing elements", func() {
+ m := MatchElements(id, IgnoreMissing, Elements{
+ "a": Equal("a"),
+ "b": Equal("b"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(missingElements).Should(m, "should ignore missing elements")
+ Expect(extraElements).ShouldNot(m, "should fail with extra elements")
+ Expect(duplicateElements).ShouldNot(m, "should fail with duplicate elements")
+ Expect(nils).Should(m, "should ignore an uninitialized slice")
+ })
+
+ It("should ignore missing and extra elements", func() {
+ m := MatchElements(id, IgnoreMissing|IgnoreExtras, Elements{
+ "a": Equal("a"),
+ "b": Equal("b"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(missingElements).Should(m, "should ignore missing elements")
+ Expect(extraElements).Should(m, "should ignore extra elements")
+ Expect(duplicateElements).ShouldNot(m, "should fail with duplicate elements")
+ Expect(nils).Should(m, "should ignore an uninitialized slice")
+
+ m = MatchElements(id, IgnoreExtras|IgnoreMissing, Elements{
+ "a": Equal("a"),
+ "b": Equal("fail"),
+ })
+ Expect(allElements).ShouldNot(m, "should run nested matchers")
+ })
+
+ Context("with elements that share a key", func() {
+ nonUniqueID := func(element interface{}) string {
+ return element.(string)[0:1]
+ }
+
+ allElements := []string{"a123", "a213", "b321"}
+ includingBadElements := []string{"a123", "b123", "b5555"}
+ extraElements := []string{"a123", "b1234", "c345"}
+ missingElements := []string{"b123", "b1234", "b1345"}
+
+ It("should strictly allow multiple matches", func() {
+ m := MatchElements(nonUniqueID, AllowDuplicates, Elements{
+ "a": ContainSubstring("1"),
+ "b": ContainSubstring("1"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(includingBadElements).ShouldNot(m, "should reject if a member fails the matcher")
+ Expect(extraElements).ShouldNot(m, "should reject with extra keys")
+ Expect(missingElements).ShouldNot(m, "should reject with missing keys")
+ Expect(nils).ShouldNot(m, "should fail with an uninitialized slice")
+ })
+
+ It("should ignore missing", func() {
+ m := MatchElements(nonUniqueID, AllowDuplicates|IgnoreMissing, Elements{
+ "a": ContainSubstring("1"),
+ "b": ContainSubstring("1"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(includingBadElements).ShouldNot(m, "should reject if a member fails the matcher")
+ Expect(extraElements).ShouldNot(m, "should reject with extra keys")
+ Expect(missingElements).Should(m, "should allow missing keys")
+ Expect(nils).Should(m, "should allow an uninitialized slice")
+ })
+
+ It("should ignore extras", func() {
+ m := MatchElements(nonUniqueID, AllowDuplicates|IgnoreExtras, Elements{
+ "a": ContainSubstring("1"),
+ "b": ContainSubstring("1"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(includingBadElements).ShouldNot(m, "should reject if a member fails the matcher")
+ Expect(extraElements).Should(m, "should allow extra keys")
+ Expect(missingElements).ShouldNot(m, "should reject missing keys")
+ Expect(nils).ShouldNot(m, "should reject an uninitialized slice")
+ })
+
+ It("should ignore missing and extras", func() {
+ m := MatchElements(nonUniqueID, AllowDuplicates|IgnoreExtras|IgnoreMissing, Elements{
+ "a": ContainSubstring("1"),
+ "b": ContainSubstring("1"),
+ })
+ Expect(allElements).Should(m, "should match all elements")
+ Expect(includingBadElements).ShouldNot(m, "should reject if a member fails the matcher")
+ Expect(extraElements).Should(m, "should allow extra keys")
+ Expect(missingElements).Should(m, "should allow missing keys")
+ Expect(nils).Should(m, "should allow an uninitialized slice")
+ })
+ })
+})
+
+func id(element interface{}) string {
+ return element.(string)
+}