-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve LFS tests + fix lfs url refs + keep path upper/lowercase in db. #3092
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
95be3d7
Add failing test
sapk 93726dc
Fix urls
sapk e5d1c78
Improve url in tests
sapk d7dbb1d
improve testing
sapk 0dd5514
Remove debug code
sapk b652e5e
Add deps
sapk 3a034b7
LFS corner-case : Search on lower but store with case
sapk 41d054e
Temporary comment of blocking action
sapk de40873
fix hooks
sapk 503ec29
Use temporary repo for git client test
sapk 2985b3e
Merge branch 'master' into test-more-lfs
lunny 97bafb9
Merge branch 'master' into test-more-lfs
lunny 10f1bc2
Use userPassword in place of hard-coded password
sapk 3ec055e
Merge branch 'master' into test-more-lfs
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,27 +6,32 @@ package integrations | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"math/rand" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"code.gitea.io/git" | ||
"code.gitea.io/gitea/modules/setting" | ||
api "code.gitea.io/sdk/gitea" | ||
|
||
"github.com/Unknwon/com" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func onGiteaWebRun(t *testing.T, callback func(*testing.T, string)) { | ||
func onGiteaWebRun(t *testing.T, callback func(*testing.T, *url.URL)) { | ||
s := http.Server{ | ||
Handler: mac, | ||
} | ||
|
||
listener, err := net.Listen("tcp", "") | ||
u, err := url.Parse(setting.AppURL) | ||
assert.NoError(t, err) | ||
listener, err := net.Listen("tcp", u.Host) | ||
assert.NoError(t, err) | ||
|
||
defer func() { | ||
|
@@ -37,24 +42,144 @@ func onGiteaWebRun(t *testing.T, callback func(*testing.T, string)) { | |
|
||
go s.Serve(listener) | ||
|
||
_, port, err := net.SplitHostPort(listener.Addr().String()) | ||
assert.NoError(t, err) | ||
|
||
callback(t, fmt.Sprintf("http://localhost:%s/", port)) | ||
callback(t, u) | ||
} | ||
|
||
func TestClone_ViaHTTP_NoLogin(t *testing.T) { | ||
func TestGit(t *testing.T) { | ||
prepareTestEnv(t) | ||
|
||
onGiteaWebRun(t, func(t *testing.T, urlPrefix string) { | ||
dstPath, err := ioutil.TempDir("", "repo1") | ||
onGiteaWebRun(t, func(t *testing.T, u *url.URL) { | ||
dstPath, err := ioutil.TempDir("", "repo-tmp-17") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(dstPath) | ||
u.Path = "user2/repo1.git" | ||
|
||
err = git.Clone(fmt.Sprintf("%suser2/repo1.git", urlPrefix), | ||
dstPath, git.CloneRepoOptions{}) | ||
assert.NoError(t, err) | ||
t.Run("Standard", func(t *testing.T) { | ||
|
||
t.Run("CloneNoLogin", func(t *testing.T) { | ||
dstLocalPath, err := ioutil.TempDir("", "repo1") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(dstLocalPath) | ||
err = git.Clone(u.String(), dstLocalPath, git.CloneRepoOptions{}) | ||
assert.NoError(t, err) | ||
assert.True(t, com.IsExist(filepath.Join(dstLocalPath, "README.md"))) | ||
}) | ||
|
||
t.Run("CreateRepo", func(t *testing.T) { | ||
session := loginUser(t, "user2") | ||
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos", &api.CreateRepoOption{ | ||
AutoInit: true, | ||
Description: "Temporary repo", | ||
Name: "repo-tmp-17", | ||
Private: false, | ||
Gitignores: "", | ||
License: "WTFPL", | ||
Readme: "Default", | ||
}) | ||
session.MakeRequest(t, req, http.StatusCreated) | ||
}) | ||
|
||
u.Path = "user2/repo-tmp-17.git" | ||
u.User = url.UserPassword("user2", "password") | ||
t.Run("Clone", func(t *testing.T) { | ||
err = git.Clone(u.String(), dstPath, git.CloneRepoOptions{}) | ||
assert.NoError(t, err) | ||
assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md"))) | ||
}) | ||
|
||
t.Run("PushCommit", func(t *testing.T) { | ||
data := make([]byte, 1024) | ||
_, err := rand.Read(data) | ||
assert.NoError(t, err) | ||
tmpFile, err := ioutil.TempFile(dstPath, "data-file-") | ||
defer tmpFile.Close() | ||
_, err = tmpFile.Write(data) | ||
assert.NoError(t, err) | ||
|
||
//Commit | ||
err = git.AddChanges(dstPath, false, filepath.Base(tmpFile.Name())) | ||
assert.NoError(t, err) | ||
err = git.CommitChanges(dstPath, git.CommitChangesOptions{ | ||
Committer: &git.Signature{ | ||
Email: "[email protected]", | ||
Name: "User Two", | ||
When: time.Now(), | ||
}, | ||
Author: &git.Signature{ | ||
Email: "[email protected]", | ||
Name: "User Two", | ||
When: time.Now(), | ||
}, | ||
Message: "Testing commit", | ||
}) | ||
assert.NoError(t, err) | ||
|
||
//Push | ||
err = git.Push(dstPath, git.PushOptions{ | ||
Branch: "master", | ||
Remote: u.String(), | ||
Force: false, | ||
}) | ||
assert.NoError(t, err) | ||
}) | ||
}) | ||
t.Run("LFS", func(t *testing.T) { | ||
t.Run("PushCommit", func(t *testing.T) { | ||
/* Generate random file */ | ||
data := make([]byte, 1024) | ||
_, err := rand.Read(data) | ||
assert.NoError(t, err) | ||
tmpFile, err := ioutil.TempFile(dstPath, "data-file-") | ||
defer tmpFile.Close() | ||
_, err = tmpFile.Write(data) | ||
assert.NoError(t, err) | ||
|
||
//Setup git LFS | ||
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath) | ||
assert.NoError(t, err) | ||
_, err = git.NewCommand("lfs").AddArguments("track", "data-file-*").RunInDir(dstPath) | ||
assert.NoError(t, err) | ||
|
||
//Commit | ||
err = git.AddChanges(dstPath, false, ".gitattributes", filepath.Base(tmpFile.Name())) | ||
assert.NoError(t, err) | ||
err = git.CommitChanges(dstPath, git.CommitChangesOptions{ | ||
Committer: &git.Signature{ | ||
Email: "[email protected]", | ||
Name: "User Two", | ||
When: time.Now(), | ||
}, | ||
Author: &git.Signature{ | ||
Email: "[email protected]", | ||
Name: "User Two", | ||
When: time.Now(), | ||
}, | ||
Message: "Testing LFS ", | ||
}) | ||
assert.NoError(t, err) | ||
|
||
//Push | ||
u.User = url.UserPassword("user2", "password") | ||
err = git.Push(dstPath, git.PushOptions{ | ||
Branch: "master", | ||
Remote: u.String(), | ||
Force: false, | ||
}) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("Locks", func(t *testing.T) { | ||
_, err = git.NewCommand("remote").AddArguments("set-url", "origin", u.String()).RunInDir(dstPath) //TODO add test ssh git-lfs-creds | ||
assert.NoError(t, err) | ||
_, err = git.NewCommand("lfs").AddArguments("locks").RunInDir(dstPath) | ||
assert.NoError(t, err) | ||
_, err = git.NewCommand("lfs").AddArguments("lock", "README.md").RunInDir(dstPath) | ||
assert.NoError(t, err) | ||
_, err = git.NewCommand("lfs").AddArguments("locks").RunInDir(dstPath) | ||
assert.NoError(t, err) | ||
_, err = git.NewCommand("lfs").AddArguments("unlock", "README.md").RunInDir(dstPath) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md"))) | ||
}) | ||
}) | ||
} |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user2/repo1.git/hooks/post-receive.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' post-receive | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user2/repo1.git/hooks/pre-receive.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' pre-receive | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user2/repo1.git/hooks/update.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' update $1 $2 $3 | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3 |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user2/repo15.git/hooks/post-receive.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' post-receive | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user2/repo15.git/hooks/pre-receive.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' pre-receive | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user2/repo15.git/hooks/update.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' update $1 $2 $3 | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3 |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user3/repo3.git/hooks/post-receive.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' post-receive | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user3/repo3.git/hooks/pre-receive.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' pre-receive | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive |
2 changes: 1 addition & 1 deletion
2
integrations/gitea-repositories-meta/user3/repo3.git/hooks/update.d/gitea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env bash | ||
"$GITEA_ROOT/gitea" hook --config='integrations/app.ini' update $1 $2 $3 | ||
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use the
userPassword
constant (also in 162).