cuelabs.dev/go/oci/ociregistry@v0.0.0-20240906074133-82eb438dd565/ociunify/iter_test.go (about) 1 // Copyright 2023 CUE Labs AG 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ociunify 16 17 import ( 18 "cmp" 19 "testing" 20 21 "cuelabs.dev/go/oci/ociregistry" 22 "github.com/go-quicktest/qt" 23 ) 24 25 var mergeIterTests = []struct { 26 testName string 27 it0, it1 ociregistry.Seq[int] 28 want []int 29 wantErr error 30 }{{ 31 testName: "IdenticalContents", 32 it0: ociregistry.SliceSeq([]int{1, 2, 3}), 33 it1: ociregistry.SliceSeq([]int{1, 2, 3}), 34 want: []int{1, 2, 3}, 35 }, { 36 testName: "DifferentContents", 37 it0: ociregistry.SliceSeq([]int{0, 1, 2, 3}), 38 it1: ociregistry.SliceSeq([]int{1, 2, 3, 5}), 39 want: []int{0, 1, 2, 3, 5}, 40 }, { 41 testName: "NoItems", 42 it0: ociregistry.SliceSeq[int](nil), 43 it1: ociregistry.SliceSeq[int](nil), 44 want: []int{}, 45 }} 46 47 func TestMergeIter(t *testing.T) { 48 for _, test := range mergeIterTests { 49 t.Run(test.testName, func(t *testing.T) { 50 it := mergeIter(test.it0, test.it1, cmp.Compare) 51 xs, err := ociregistry.All(it) 52 qt.Assert(t, qt.DeepEquals(xs, test.want)) 53 qt.Assert(t, qt.Equals(err, test.wantErr)) 54 }) 55 } 56 }