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:
zeripath 2019-12-28 02:08:05 +00:00 committed by Lunny Xiao
parent 884173232f
commit 55cd33e124
6 changed files with 92 additions and 14 deletions

View file

@ -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")