func (*simplestreamsSuite) TestFilterRemovesNonMatches(c *gc.C) { array := simplestreams.IndexMetadataSlice{&simplestreams.IndexMetadata{}} c.Check( simplestreams.Filter(array, func(*simplestreams.IndexMetadata) bool { return false }), gc.HasLen, 0) }
func (*simplestreamsSuite) TestFilterReturnsNothingForEmptyArray(c *gc.C) { empty := simplestreams.IndexMetadataSlice{} c.Check( simplestreams.Filter(empty, func(*simplestreams.IndexMetadata) bool { return true }), gc.HasLen, 0) }
func (*simplestreamsSuite) TestFilterIncludesMatches(c *gc.C) { metadata := simplestreams.IndexMetadata{} array := simplestreams.IndexMetadataSlice{&metadata} c.Check( simplestreams.Filter(array, func(*simplestreams.IndexMetadata) bool { return true }), gc.DeepEquals, simplestreams.IndexMetadataSlice{&metadata}) }
func (*simplestreamsSuite) TestFilterPreservesOrder(c *gc.C) { array := simplestreams.IndexMetadataSlice{ &simplestreams.IndexMetadata{CloudName: "aws"}, &simplestreams.IndexMetadata{CloudName: "maas"}, &simplestreams.IndexMetadata{CloudName: "openstack"}, } c.Check( simplestreams.Filter(array, func(metadata *simplestreams.IndexMetadata) bool { return true }), gc.DeepEquals, array) }
func (*simplestreamsSuite) TestFilterCombinesMatchesAndNonMatches(c *gc.C) { array := simplestreams.IndexMetadataSlice{ &simplestreams.IndexMetadata{Format: "1.0"}, &simplestreams.IndexMetadata{Format: "1.1"}, &simplestreams.IndexMetadata{Format: "2.0"}, &simplestreams.IndexMetadata{Format: "2.1"}, } dotOFormats := simplestreams.Filter(array, func(metadata *simplestreams.IndexMetadata) bool { return strings.HasSuffix(metadata.Format, ".0") }) c.Check(dotOFormats, gc.DeepEquals, simplestreams.IndexMetadataSlice{array[0], array[2]}) }
func (*simplestreamsSuite) TestFilterLeavesOriginalUnchanged(c *gc.C) { item1 := simplestreams.IndexMetadata{CloudName: "aws"} item2 := simplestreams.IndexMetadata{CloudName: "openstack"} array := simplestreams.IndexMetadataSlice{&item1, &item2} result := simplestreams.Filter(array, func(metadata *simplestreams.IndexMetadata) bool { return metadata.CloudName == "aws" }) // This exercises both the "leave out" and the "include" code paths. c.Assert(result, gc.HasLen, 1) // The original, however, has not changed. c.Assert(array, gc.HasLen, 2) c.Check(array, gc.DeepEquals, simplestreams.IndexMetadataSlice{&item1, &item2}) }