summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-12-28 02:08:05 +0000
committerLunny Xiao <xiaolunwen@gmail.com>2019-12-28 10:08:05 +0800
commit55cd33e124e152869fa2f2dc420e6a5be98a3cbe (patch)
tree85f9b800248c202d024c7b6b6c1dc37243782f58 /routers/repo
parent884173232fa036b032f77d5a10d78e695e96b5de (diff)
downloadgitea-55cd33e124e152869fa2f2dc420e6a5be98a3cbe.tar.gz
gitea-55cd33e124e152869fa2f2dc420e6a5be98a3cbe.zip
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>
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/settings_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/routers/repo/settings_test.go b/routers/repo/settings_test.go
index a05a96cea2..2325c0255c 100644
--- a/routers/repo/settings_test.go
+++ b/routers/repo/settings_test.go
@@ -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")