Some checks failed
Build and Release / Create Release (push) Has been skipped
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, macos) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, macos) (push) Has been skipped
Build and Release / Build Binary (linux/arm64) (push) Has been skipped
Build and Release / Integration Tests (PostgreSQL) (push) Has been cancelled
Build and Release / Lint (push) Has been cancelled
Build and Release / Unit Tests (push) Has been cancelled
The test was using rand.Shuffle and asserting the result was different from the original order. This is inherently flaky as there's a small chance the shuffle produces the same order. Changed to use a deterministic reversed order instead. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEntriesCustomSort(t *testing.T) {
|
|
expected := Entries{
|
|
&TreeEntry{name: "a-dir", entryMode: EntryModeTree},
|
|
&TreeEntry{name: "a-submodule", entryMode: EntryModeCommit},
|
|
&TreeEntry{name: "b-dir", entryMode: EntryModeTree},
|
|
&TreeEntry{name: "b-submodule", entryMode: EntryModeCommit},
|
|
&TreeEntry{name: "a-file", entryMode: EntryModeBlob},
|
|
&TreeEntry{name: "b-file", entryMode: EntryModeBlob},
|
|
}
|
|
// Start with entries in reverse order to ensure sorting is tested
|
|
entries := Entries{
|
|
&TreeEntry{name: "b-file", entryMode: EntryModeBlob},
|
|
&TreeEntry{name: "a-file", entryMode: EntryModeBlob},
|
|
&TreeEntry{name: "b-submodule", entryMode: EntryModeCommit},
|
|
&TreeEntry{name: "b-dir", entryMode: EntryModeTree},
|
|
&TreeEntry{name: "a-submodule", entryMode: EntryModeCommit},
|
|
&TreeEntry{name: "a-dir", entryMode: EntryModeTree},
|
|
}
|
|
entries.CustomSort(strings.Compare)
|
|
assert.Equal(t, expected, entries)
|
|
}
|