mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
104 lines
4.1 KiB
Go
104 lines
4.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package lfs
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStringContent(t *testing.T) {
|
|
p := Pointer{Oid: "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", Size: 1234}
|
|
expected := "version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n"
|
|
assert.Equal(t, expected, p.StringContent())
|
|
}
|
|
|
|
func TestRelativePath(t *testing.T) {
|
|
p := Pointer{Oid: "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393"}
|
|
expected := path.Join("4d", "7a", "214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393")
|
|
assert.Equal(t, expected, p.RelativePath())
|
|
|
|
p2 := Pointer{Oid: "4d7a"}
|
|
assert.Equal(t, "4d7a", p2.RelativePath())
|
|
}
|
|
|
|
func TestIsValid(t *testing.T) {
|
|
p := Pointer{}
|
|
assert.False(t, p.IsValid())
|
|
|
|
p = Pointer{Oid: "123"}
|
|
assert.False(t, p.IsValid())
|
|
|
|
p = Pointer{Oid: "z4cb57646c54a297c9807697e80a30946f79a4b82cb079d2606847825b1812cc"}
|
|
assert.False(t, p.IsValid())
|
|
|
|
p = Pointer{Oid: "94cb57646c54a297c9807697e80a30946f79a4b82cb079d2606847825b1812cc"}
|
|
assert.True(t, p.IsValid())
|
|
|
|
p = Pointer{Oid: "94cb57646c54a297c9807697e80a30946f79a4b82cb079d2606847825b1812cc", Size: -1}
|
|
assert.False(t, p.IsValid())
|
|
}
|
|
|
|
func TestGeneratePointer(t *testing.T) {
|
|
p, err := GeneratePointer(strings.NewReader("Gitea"))
|
|
assert.NoError(t, err)
|
|
assert.True(t, p.IsValid())
|
|
assert.Equal(t, "94cb57646c54a297c9807697e80a30946f79a4b82cb079d2606847825b1812cc", p.Oid)
|
|
assert.Equal(t, int64(5), p.Size)
|
|
}
|
|
|
|
func TestReadPointerFromBuffer(t *testing.T) {
|
|
p, err := ReadPointerFromBuffer([]byte{})
|
|
assert.ErrorIs(t, err, ErrMissingPrefix)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("test"))
|
|
assert.ErrorIs(t, err, ErrMissingPrefix)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\n"))
|
|
assert.ErrorIs(t, err, ErrInvalidStructure)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a\nsize 1234\n"))
|
|
assert.ErrorIs(t, err, ErrInvalidOIDFormat)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a2146z4ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n"))
|
|
assert.ErrorIs(t, err, ErrInvalidOIDFormat)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\ntest 1234\n"))
|
|
assert.Error(t, err)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize test\n"))
|
|
assert.Error(t, err)
|
|
assert.False(t, p.IsValid())
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n"))
|
|
assert.NoError(t, err)
|
|
assert.True(t, p.IsValid())
|
|
assert.Equal(t, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", p.Oid)
|
|
assert.Equal(t, int64(1234), p.Size)
|
|
|
|
p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\ntest"))
|
|
assert.NoError(t, err)
|
|
assert.True(t, p.IsValid())
|
|
assert.Equal(t, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", p.Oid)
|
|
assert.Equal(t, int64(1234), p.Size)
|
|
}
|
|
|
|
func TestReadPointer(t *testing.T) {
|
|
p, err := ReadPointer(strings.NewReader("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n"))
|
|
assert.NoError(t, err)
|
|
assert.True(t, p.IsValid())
|
|
assert.Equal(t, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", p.Oid)
|
|
assert.Equal(t, int64(1234), p.Size)
|
|
}
|