mirror of
https://github.com/vee1e/gittuf.git
synced 2026-09-01 18:27:06 +00:00
This PR adds focused tests for error paths and edge cases across pkg/gitinterface, raising coverage from 69.4% to 76.2%. Files changed: - references_test.go: TestAbsoluteReference with branch/tag/custom/ref lookups - tag_test.go: TestEnsureIsTag, error paths for GetTagTarget and verifyTagSignature - commit_test.go: TestEnsureIsCommit, error paths for commit inspection helpers - object_test.go: Error paths for GetObjectType and GetObjectSize - blob_test.go: Error path for ReadBlob with non-blob object - status_test.go: Tests for Status errors and StatusCode helpers - sync_test.go: Tests for WithFetchDepth, CreateRemote, push/fetch errors - config_test.go: Error path for SetGitConfig - utils_test.go: TestResetDueToError Closes #1244 Signed-off-by: dawgdevv <nraj02415@gmail.com>
35 lines
952 B
Go
35 lines
952 B
Go
// Copyright The gittuf Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package gitinterface
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestResetDueToError(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
repo := CreateTestGitRepository(t, tmpDir, false)
|
|
|
|
treeBuilder := NewTreeBuilder(repo)
|
|
emptyTreeID, err := treeBuilder.WriteTreeFromEntries(nil)
|
|
require.Nil(t, err)
|
|
|
|
commitID, err := repo.Commit(emptyTreeID, "refs/heads/main", "Initial commit\n", false)
|
|
require.Nil(t, err)
|
|
|
|
t.Run("successful reset", func(t *testing.T) {
|
|
cause := assert.AnError
|
|
err := repo.ResetDueToError(cause, "refs/heads/main", commitID)
|
|
assert.ErrorIs(t, err, cause)
|
|
})
|
|
|
|
t.Run("invalid ref name", func(t *testing.T) {
|
|
cause := assert.AnError
|
|
err := repo.ResetDueToError(cause, "invalid ref with spaces", commitID)
|
|
assert.ErrorContains(t, err, "unable to reset")
|
|
assert.ErrorIs(t, err, cause)
|
|
})
|
|
}
|