Skip to content

Commit 503ec29

Browse files
committed
Use temporary repo for git client test
1 parent de40873 commit 503ec29

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

integrations/git_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"code.gitea.io/git"
2020
"code.gitea.io/gitea/modules/setting"
21+
api "code.gitea.io/sdk/gitea"
2122

2223
"github.com/Unknwon/com"
2324
"github.com/stretchr/testify/assert"
@@ -48,17 +49,44 @@ func TestGit(t *testing.T) {
4849
prepareTestEnv(t)
4950

5051
onGiteaWebRun(t, func(t *testing.T, u *url.URL) {
51-
dstPath, err := ioutil.TempDir("", "repo1")
52+
dstPath, err := ioutil.TempDir("", "repo-tmp-17")
5253
assert.NoError(t, err)
5354
defer os.RemoveAll(dstPath)
5455
u.Path = "user2/repo1.git"
5556

5657
t.Run("Standard", func(t *testing.T) {
58+
5759
t.Run("CloneNoLogin", func(t *testing.T) {
60+
dstLocalPath, err := ioutil.TempDir("", "repo1")
61+
assert.NoError(t, err)
62+
defer os.RemoveAll(dstLocalPath)
63+
err = git.Clone(u.String(), dstLocalPath, git.CloneRepoOptions{})
64+
assert.NoError(t, err)
65+
assert.True(t, com.IsExist(filepath.Join(dstLocalPath, "README.md")))
66+
})
67+
68+
t.Run("CreateRepo", func(t *testing.T) {
69+
session := loginUser(t, "user2")
70+
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos", &api.CreateRepoOption{
71+
AutoInit: true,
72+
Description: "Temporary repo",
73+
Name: "repo-tmp-17",
74+
Private: false,
75+
Gitignores: "",
76+
License: "WTFPL",
77+
Readme: "Default",
78+
})
79+
session.MakeRequest(t, req, http.StatusCreated)
80+
})
81+
82+
u.Path = "user2/repo-tmp-17.git"
83+
u.User = url.UserPassword("user2", "password")
84+
t.Run("Clone", func(t *testing.T) {
5885
err = git.Clone(u.String(), dstPath, git.CloneRepoOptions{})
5986
assert.NoError(t, err)
6087
assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md")))
6188
})
89+
6290
t.Run("PushCommit", func(t *testing.T) {
6391
data := make([]byte, 1024)
6492
_, err := rand.Read(data)
@@ -87,7 +115,6 @@ func TestGit(t *testing.T) {
87115
assert.NoError(t, err)
88116

89117
//Push
90-
u.User = url.UserPassword("user2", "password")
91118
err = git.Push(dstPath, git.PushOptions{
92119
Branch: "master",
93120
Remote: u.String(),

0 commit comments

Comments
 (0)