git-module

fork of https://git.lin.moe/gogs/git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"context"
 5	"fmt"
 6	"os"
 7	"path/filepath"
 8	"testing"
 9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12)
13
14func TestUpdateServerInfo(t *testing.T) {
15	ctx := context.Background()
16	err := os.RemoveAll(filepath.Join(repoPath, "info"))
17	require.NoError(t, err)
18	err = UpdateServerInfo(ctx, repoPath, UpdateServerInfoOptions{Force: true})
19	require.NoError(t, err)
20	assert.True(t, isFile(filepath.Join(repoPath, "info", "refs")))
21}
22
23func TestReceivePack(t *testing.T) {
24	ctx := context.Background()
25	got, err := ReceivePack(ctx, repoPath, ReceivePackOptions{HTTPBackendInfoRefs: true})
26	require.NoError(t, err)
27	var regPattern = fmt.Sprintf(
28		"report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta (push-options |)object-format=%s agent=git/",
29		testrepoObjectFormat,
30	)
31	assert.Regexp(t, regPattern, string(got))
32}
33
34func TestUploadPack(t *testing.T) {
35	ctx := context.Background()
36	got, err := UploadPack(ctx, repoPath,
37		UploadPackOptions{
38			StatelessRPC:        true,
39			Strict:              true,
40			HTTPBackendInfoRefs: true,
41		},
42	)
43	require.NoError(t, err)
44	var regPattern = fmt.Sprintf("multi_ack thin-pack side-band side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative no-progress include-tag multi_ack_detailed (allow-tip-sha1-in-want |)(allow-reachable-sha1-in-want |)no-done symref=HEAD:refs/heads/master (filter |)object-format=%s agent=git/", testrepoObjectFormat)
45	assert.Regexp(t, regPattern, string(got))
46}