1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-21 08:31:27 -05:00

test: enforce tenv usage in tests

This commit is contained in:
TheFox0x7 2024-07-17 23:07:41 +02:00
parent 20f5f050f3
commit 3fca6c0bf5
No known key found for this signature in database
GPG key ID: 6CA33903484AF7C2
5 changed files with 8 additions and 11 deletions

View file

@ -19,6 +19,7 @@ linters:
- revive
- staticcheck
- stylecheck
- tenv
- typecheck
- unconvert
- unused

View file

@ -6,7 +6,6 @@ package base
import (
"crypto/sha1"
"fmt"
"os"
"testing"
"time"
@ -168,9 +167,9 @@ func TestInt64sToStrings(t *testing.T) {
// TODO: Test EntryIcon
func TestSetupGiteaRoot(t *testing.T) {
_ = os.Setenv("GITEA_ROOT", "test")
t.Setenv("GITEA_ROOT", "test")
assert.Equal(t, "test", SetupGiteaRoot())
_ = os.Setenv("GITEA_ROOT", "")
t.Setenv("GITEA_ROOT", "")
assert.NotEqual(t, "test", SetupGiteaRoot())
}

View file

@ -4,7 +4,6 @@
package user
import (
"os"
"os/exec"
"runtime"
"strings"
@ -36,7 +35,7 @@ func TestCurrentUsername(t *testing.T) {
if user != whoami {
t.Errorf("expected %s as user, got: %s", whoami, user)
}
os.Setenv("USER", "spoofed")
t.Setenv("USER", "spoofed")
user = CurrentUsername()
if user != whoami {
t.Errorf("expected %s as user, got: %s", whoami, user)

View file

@ -40,10 +40,10 @@ func withKeyFile(t *testing.T, keyname string, callback func(string)) {
assert.NoError(t, err)
// Setup ssh wrapper
os.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
os.Setenv("GIT_SSH_COMMAND",
t.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
t.Setenv("GIT_SSH_COMMAND",
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
os.Setenv("GIT_SSH_VARIANT", "ssh")
t.Setenv("GIT_SSH_VARIANT", "ssh")
callback(keyFile)
}

View file

@ -30,10 +30,8 @@ func TestGPGGit(t *testing.T) {
err := os.Chmod(tmpDir, 0o700)
assert.NoError(t, err)
oldGNUPGHome := os.Getenv("GNUPGHOME")
err = os.Setenv("GNUPGHOME", tmpDir)
t.Setenv("GNUPGHOME", tmpDir)
assert.NoError(t, err)
defer os.Setenv("GNUPGHOME", oldGNUPGHome)
// Need to create a root key
rootKeyPair, err := importTestingKey()