...

Source file src/cuelabs.dev/go/oci/ociregistry/ociunify/iter_test.go

Documentation: cuelabs.dev/go/oci/ociregistry/ociunify

     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  	"testing"
    19  
    20  	"cuelabs.dev/go/oci/ociregistry"
    21  	"github.com/go-quicktest/qt"
    22  )
    23  
    24  var mergeIterTests = []struct {
    25  	testName string
    26  	it0, it1 ociregistry.Seq[int]
    27  	want     []int
    28  	wantErr  error
    29  }{{
    30  	testName: "IdenticalContents",
    31  	it0:      ociregistry.SliceIter([]int{1, 2, 3}),
    32  	it1:      ociregistry.SliceIter([]int{1, 2, 3}),
    33  	want:     []int{1, 2, 3},
    34  }, {
    35  	testName: "DifferentContents",
    36  	it0:      ociregistry.SliceIter([]int{0, 1, 2, 3}),
    37  	it1:      ociregistry.SliceIter([]int{1, 2, 3, 5}),
    38  	want:     []int{0, 1, 2, 3, 5},
    39  }, {
    40  	testName: "NoItems",
    41  	it0:      ociregistry.SliceIter[int](nil),
    42  	it1:      ociregistry.SliceIter[int](nil),
    43  	want:     []int{},
    44  }}
    45  
    46  func TestMergeIter(t *testing.T) {
    47  	for _, test := range mergeIterTests {
    48  		t.Run(test.testName, func(t *testing.T) {
    49  			it := mergeIter(test.it0, test.it1, cmpInt)
    50  			xs, err := ociregistry.All(it)
    51  			qt.Assert(t, qt.DeepEquals(xs, test.want))
    52  			qt.Assert(t, qt.Equals(err, test.wantErr))
    53  		})
    54  	}
    55  }
    56  
    57  func cmpInt(i, j int) int {
    58  	if i < j {
    59  		return -1
    60  	}
    61  	if i > j {
    62  		return 1
    63  	}
    64  	return 0
    65  }
    66  

View as plain text