You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git_clone_wiki_test.go 1.5KB

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