Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"code.gitcaddy.com/server/v3/modules/git/gitcmd"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetTemplateSubmoduleCommits(t *testing.T) {
|
|
testRepoPath := filepath.Join(testReposDir, "repo4_submodules")
|
|
submodules, err := GetTemplateSubmoduleCommits(t.Context(), testRepoPath)
|
|
require.NoError(t, err)
|
|
|
|
assert.Len(t, submodules, 2)
|
|
|
|
assert.Equal(t, "<°)))><", submodules[0].Path)
|
|
assert.Equal(t, "d2932de67963f23d43e1c7ecf20173e92ee6c43c", submodules[0].Commit)
|
|
|
|
assert.Equal(t, "libtest", submodules[1].Path)
|
|
assert.Equal(t, "1234567890123456789012345678901234567890", submodules[1].Commit)
|
|
}
|
|
|
|
func TestAddTemplateSubmoduleIndexes(t *testing.T) {
|
|
ctx := t.Context()
|
|
tmpDir := t.TempDir()
|
|
var err error
|
|
_, _, err = gitcmd.NewCommand("init").WithDir(tmpDir).RunStdString(ctx)
|
|
require.NoError(t, err)
|
|
_ = os.Mkdir(filepath.Join(tmpDir, "new-dir"), 0o755)
|
|
err = AddTemplateSubmoduleIndexes(ctx, tmpDir, []TemplateSubmoduleCommit{{Path: "new-dir", Commit: "1234567890123456789012345678901234567890"}})
|
|
require.NoError(t, err)
|
|
_, _, err = gitcmd.NewCommand("add", "--all").WithDir(tmpDir).RunStdString(ctx)
|
|
require.NoError(t, err)
|
|
_, _, err = gitcmd.NewCommand("-c", "user.name=a", "-c", "user.email=b", "commit", "-m=test").WithDir(tmpDir).RunStdString(ctx)
|
|
require.NoError(t, err)
|
|
submodules, err := GetTemplateSubmoduleCommits(t.Context(), tmpDir)
|
|
require.NoError(t, err)
|
|
assert.Len(t, submodules, 1)
|
|
assert.Equal(t, "new-dir", submodules[0].Path)
|
|
assert.Equal(t, "1234567890123456789012345678901234567890", submodules[0].Commit)
|
|
}
|