code.gitea.io/gitea@v1.21.7/tests/integration/git_clone_wiki_test.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"net/url"
    10  	"os"
    11  	"path/filepath"
    12  	"testing"
    13  
    14  	"code.gitea.io/gitea/modules/git"
    15  	"code.gitea.io/gitea/modules/util"
    16  	"code.gitea.io/gitea/tests"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  )
    20  
    21  func assertFileExist(t *testing.T, p string) {
    22  	exist, err := util.IsExist(p)
    23  	assert.NoError(t, err)
    24  	assert.True(t, exist)
    25  }
    26  
    27  func assertFileEqual(t *testing.T, p string, content []byte) {
    28  	bs, err := os.ReadFile(p)
    29  	assert.NoError(t, err)
    30  	assert.EqualValues(t, content, bs)
    31  }
    32  
    33  func TestRepoCloneWiki(t *testing.T) {
    34  	onGiteaRun(t, func(t *testing.T, u *url.URL) {
    35  		defer tests.PrepareTestEnv(t)()
    36  
    37  		dstPath := t.TempDir()
    38  
    39  		r := fmt.Sprintf("%suser2/repo1.wiki.git", u.String())
    40  		u, _ = url.Parse(r)
    41  		u.User = url.UserPassword("user2", userPassword)
    42  		t.Run("Clone", func(t *testing.T) {
    43  			assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstPath, git.CloneRepoOptions{}))
    44  			assertFileEqual(t, filepath.Join(dstPath, "Home.md"), []byte("# Home page\n\nThis is the home page!\n"))
    45  			assertFileExist(t, filepath.Join(dstPath, "Page-With-Image.md"))
    46  			assertFileExist(t, filepath.Join(dstPath, "Page-With-Spaced-Name.md"))
    47  			assertFileExist(t, filepath.Join(dstPath, "images"))
    48  			assertFileExist(t, filepath.Join(dstPath, "jpeg.jpg"))
    49  		})
    50  	})
    51  }