You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: commit_ordered_iterator_test.go
    path of file: ./repos/lakeFS/pkg/graveler/ref
    
    the code of the file until where you have to start completion: package ref_test

import (
	"context"
	"encoding/hex"
	"fmt"
	"sort"
	"testing"
	"time"

	"github.com/go-openapi/swag"
	"github.com/go-test/deep"
	"github.com/golang/mock/gomock"
	"github.com/treeverse/lakefs/pkg/graveler"
	"github.com/treeverse/lakefs/pkg/graveler/ref"
	"github.com/treeverse/lakefs/pkg/kv/mock"
	"github.com/treeverse/lakefs/pkg/testutil"
)

func newFakeAddressProvider(commits []*graveler.Commit) *fakeAddressProvider {
	identityToFakeIdentity := make(map[string]string)
	for _, c := range commits {
		identityToFakeIdentity[hex.EncodeToString(c.Identity())] = c.Message
	}
	return &fakeAddressProvider{identityToFakeIdentity: identityToFakeIdentity}
}

type testCommit struct {
	id      string
	parents []string
	version *int
}

func TestOrderedCommitIterator(t *testing.T) {
	ctx := context.Background()
	cases := []struct {
		Name                   string
		Commits                []*testCommit
		expectedCommits        []string
		expectedAncestryLeaves []string
	}{
		{
			Name: "two_ancestries",
			Commits: []*testCommit{
				{id: "e0", parents: []string{}},
				{id: "c1", parents: []string{"e0"}},
				{id: "b2", parents: []string{"e0"}},
				{id: "d3", parents: []string{"c1"}},
				{id: "e4", parents: []string{"b2"}},
				{id: "f5", parents: []string{"d3"}},
				{id: "a6", parents: []string{"e4"}},
				{id: "c7", parents: []string{"f5"}},
			},
			expectedCommits:        []string{"a6", "b2", "c1", "c7", "d3", "e0", "e4", "f5"},
			expectedAncestr
    
func TestOrderedCommitIterator(t *testing.T) {
	ctx := context.Background()
	cases := []struct {
		Name                   string
		Commits                []*testCommit
		expectedCommits        []string
		expectedAncestryLeaves []string
	}{
		{
			Name: "two_ancestries",
			Commits: []*testCommit{
				{id: "e0", parents: []string{}},
				{id: "c1", parents: []string{"e0"}},
				{id: "b2", parents: []string{"e0"}},
				{id: "d3", parents: []string{"c1"}},
				{id: "e4", parents: []string{"b2"}},
				{id: "f5", parents: []string{"d3"}},
				{id: "a6", parents: []string{"e4"}},
				{id: "c7", parents: []string{"f5"}},
			},
			expectedCommits:        []string{"a6", "b2", "c1", "c7", "d3", "e0", "e4", "f5"},
			expectedAncestryLeaves: []string{"a6", "c7"},
		},
		{
			Name: "with_merge",
			Commits: []*testCommit{
				{id: "e0", parents: []string{}},
				{id: "c1", parents: []string{"e0"}},
				{id: "b2", parents: []string{"e0"}},
				{id: "d3", parents: []string{"c1"}},
				{id: "e4", parents: []string{"b2"}},
				{id: "f5", parents: []string{"d3"}},
				{id: "a6", parents: []string{"e4"}},
				{id: "c7", parents: []string{"f5", "a6"}},
			},
			expectedCommits:        []string{"a6", "b2", "c1", "c7", "d3", "e0", "e4", "f5"},
			expectedAncestryLeaves: []string{"a6", "c7"},
		},
		{
			Name: "with_merge_old_version",
			Commits: []*testCommit{
				{id: "e0", parents: []string{}},
				{id: "c1", parents: []string{"e0"}},
				{id: "b2", parents: []string{"e0"}},
				{id: "d3", parents: []string{"c1"}},
				{id: "e4", parents: []string{"b2"}},
				{id: "f5", parents: []string{"d3"}},
				{id: "a6", parents: []string{"e4"}},
				{id: "c7", parents: []string{"f5", "a6"}, version: swag.Int(int(graveler.CommitVersionInitial))},
			},
			expectedCommits:        []string{"a6", "b2", "c1", "c7", "d3", "e0", "e4", "f5"},
			expectedAncestryLeaves: []string{"c7", "f5"},
		},
		{
			Name: "criss_cross_merge",
			Commits: []*testCommit{
				{id: "e0", parents: []string{}},
				{id: "c1", parents: []string{"e0"}},
				{id: "b2", parents: []string{"e0"}},
				{id: "d3", parents: []string{"c1", "b2"}},
				{id: "a4", parents: []string{"c1", "b2"}},
				{id: "c5", parents: []string{"d3"}},
				{id: "f6", parents: []string{"a4"}},
			},
			expectedCommits:        []string{"a4", "b2", "c1", "c5", "d3", "e0", "f6"},
			expectedAncestryLeaves: []string{"b2", "c5", "f6"},
		},
		{
			Name: "merges_in_history",
			// from git core tests:
			// E---D---C---B---A
			// \"-_         \   \
			//  \  `---------G   \
			//   \                \
			//    F----------------H
			Commits: []*testCommit{
				{id: "e", parents: []string{}},
				{id: "d", parents: []string{"e"}},
				{id: "f", parents: []string{"e"}},
				{id: "c", parents: []string{"d"}},
				{id: "b", parents: []string{"c"}},
				{id: "a", parents: []string{"b"}},
				{id: "g", parents: []string{"b", "e"}},
				{id: "h", parents: []string{"a", "f"}},
			},
			expectedCommits:        []string{"a", "b", "c", "d", "e", "f", "g", "h"},
			expectedAncestryLeaves: []string{"f", "g", "h"},
		},
		{
			Name: "merge_to_and_from_main",
			// E---D----C---B------A
			//  \      /     \    /
			//   F----G---H---I--J
			Commits: []*testCommit{
				{id: "e", parents: []string{}},
				{id: "d", parents: []string{"e"}},
				{id: "f", parents: []string{"e"}},
				{id: "g", parents: []string{"f"}},
				{id: "c", parents: []string{"d", "g"}},
				{id: "b", parents: []string{"c"}},
				{id: "h", parents: []string{"g"}},
				{id: "i", parents: []string{"h", "b"}},
				{id: "j", parents: []string{"i"}},
				{id: "a", parents: []string{"b", "j"}},
			},
			expectedCommits:        []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
			expectedAncestryLeaves: []string{"a", "j"},
		},
	}
	for _, tst := range cases {
		t.Run(tst.Name, func(t *testing.T) {
			var commits []*graveler.Commit
			for _, tstCommit := range tst.Commits {
				parents := make([]graveler.CommitID, 0, len(tstCommit.parents))
				for _, parent := range tstCommit.parents {
					parents = append(parents, graveler.CommitID(parent))
				}
				version := graveler.CurrentCommitVersion
				if tstCommit.version != nil {
					version = graveler.CommitVersion(*tstCommit.version)
				}
				commits = append(commits, &graveler.Commit{
					Message: tstCommit.id,
					Parents: parents,
					Version: version,
				})
			}
			r, store := testRefManagerWithAddressProvider(t, newFakeAddressProvider(commits))
			repository, err := r.CreateBareRepository(ctx, graveler.RepositoryID(tst.Name), graveler.Repository{
				StorageNamespace: "s3://foo",
				CreationDate:     time.Now(),
				DefaultBranchID:  "main",
			})
			testutil.Must(t, err)
			for _, c := range commits {
				_, err := r.AddCommit(ctx, repository, *c)
				testutil.Must(t, err)
			}

			iterator, err := ref.NewOrderedCommitIterator(ctx, store, repository, false)
			if err != nil {
				t.Fatal("create ordered commit iterator", err)
			}
			var actualOrderedCommits []string
			for iterator.Next() {
				c := iterator.Value()
				actualOrderedCommits = append(
					actualOrderedCommits,
					string(c.CommitID),
				)
			}
			testutil.Must(t, iterator.Err())
			if diff := deep.Equal(tst.expectedCommits, actualOrderedCommits); diff != nil {
				t.Errorf("Unexpected ordered commits from iterator. diff=%s", diff)
			}
			iterator.Close()
			iterator, err = ref.NewOrderedCommitIterator(ctx, store, repository, true)
			if err != nil {
				t.Fatal("create ordered commit iterator", err)
			}
			var actualAncestryLeaves []string
			for iterator.Next() {
				c := iterator.Value()
				actualAncestryLeaves = append(
					actualAncestryLeaves,
					string(c.CommitID),
				)
			}
			testutil.Must(t, iterator.Err())
			if diff := deep.Equal(tst.expectedAncestryLeaves, actualAncestryLeaves); diff != nil {
				t.Errorf("Unexpected ancestry leaves from iterator. diff=%s", diff)
			}
			iterator.Close()
		})
	}
}