|
| 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 | + |
| 5 | +package integrations |
| 6 | + |
| 7 | +import ( |
| 8 | + "context" |
| 9 | + "fmt" |
| 10 | + "io/ioutil" |
| 11 | + "net/url" |
| 12 | + "path/filepath" |
| 13 | + "testing" |
| 14 | + |
| 15 | + "code.gitea.io/gitea/modules/git" |
| 16 | + "code.gitea.io/gitea/modules/util" |
| 17 | + "github.com/stretchr/testify/assert" |
| 18 | +) |
| 19 | + |
| 20 | +func assertFileExist(t *testing.T, p string) { |
| 21 | + exist, err := util.IsExist(p) |
| 22 | + assert.NoError(t, err) |
| 23 | + assert.True(t, exist) |
| 24 | +} |
| 25 | + |
| 26 | +func assertFileEqual(t *testing.T, p string, content []byte) { |
| 27 | + bs, err := ioutil.ReadFile(p) |
| 28 | + assert.NoError(t, err) |
| 29 | + assert.EqualValues(t, content, bs) |
| 30 | +} |
| 31 | + |
| 32 | +func TestRepoCloneWiki(t *testing.T) { |
| 33 | + onGiteaRun(t, func(t *testing.T, u *url.URL) { |
| 34 | + defer prepareTestEnv(t)() |
| 35 | + |
| 36 | + dstPath, err := ioutil.TempDir("", "clone_wiki") |
| 37 | + assert.NoError(t, err) |
| 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(), u.String(), dstPath, allowLFSFilters(), 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 | +} |
0 commit comments