mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Stop various tests from adding to the source tree (#9515)
Instead of just adding test generated files to .gitignore prevent them from being produced in the first place. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -5,18 +5,42 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func createSSHAuthorizedKeysTmpPath(t *testing.T) func() {
|
||||
tmpDir, err := ioutil.TempDir("", "tmp-ssh")
|
||||
if err != nil {
|
||||
assert.Fail(t, "Unable to create temporary directory: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
oldPath := setting.SSH.RootPath
|
||||
setting.SSH.RootPath = tmpDir
|
||||
|
||||
return func() {
|
||||
setting.SSH.RootPath = oldPath
|
||||
os.RemoveAll(tmpDir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddReadOnlyDeployKey(t *testing.T) {
|
||||
if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
|
||||
defer deferable()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
models.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
||||
@@ -39,6 +63,12 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddReadWriteOnlyDeployKey(t *testing.T) {
|
||||
if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
|
||||
defer deferable()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
models.PrepareTestEnv(t)
|
||||
|
||||
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
||||
|
Reference in New Issue
Block a user