@@ -6,7 +6,6 @@ package cmd
6
6
import (
7
7
"fmt"
8
8
"io"
9
- "os"
10
9
"path/filepath"
11
10
"strings"
12
11
"testing"
@@ -113,37 +112,17 @@ func TestCliCmd(t *testing.T) {
113
112
_ , _ = fmt .Fprint (ctx .App .Writer , makePathOutput (setting .AppWorkPath , setting .CustomPath , setting .CustomConf ))
114
113
return nil
115
114
})
116
- var envBackup []string
117
- for _ , s := range os .Environ () {
118
- if strings .HasPrefix (s , "GITEA_" ) && strings .Contains (s , "=" ) {
119
- envBackup = append (envBackup , s )
120
- }
121
- }
122
- clearGiteaEnv := func () {
123
- for _ , s := range os .Environ () {
124
- if strings .HasPrefix (s , "GITEA_" ) {
125
- _ = os .Unsetenv (s )
126
- }
127
- }
128
- }
129
- defer func () {
130
- clearGiteaEnv ()
131
- for _ , s := range envBackup {
132
- k , v , _ := strings .Cut (s , "=" )
133
- _ = os .Setenv (k , v )
134
- }
135
- }()
136
-
137
115
for _ , c := range cases {
138
- clearGiteaEnv ()
139
- for k , v := range c .env {
140
- _ = os .Setenv (k , v )
141
- }
142
- args := strings .Split (c .cmd , " " ) // for test only, "split" is good enough
143
- r , err := runTestApp (app , args ... )
144
- assert .NoError (t , err , c .cmd )
145
- assert .NotEmpty (t , c .exp , c .cmd )
146
- assert .Contains (t , r .Stdout , c .exp , c .cmd )
116
+ t .Run (c .cmd , func (t * testing.T ) {
117
+ for k , v := range c .env {
118
+ t .Setenv (k , v )
119
+ }
120
+ args := strings .Split (c .cmd , " " ) // for test only, "split" is good enough
121
+ r , err := runTestApp (app , args ... )
122
+ assert .NoError (t , err , c .cmd )
123
+ assert .NotEmpty (t , c .exp , c .cmd )
124
+ assert .Contains (t , r .Stdout , c .exp , c .cmd )
125
+ })
147
126
}
148
127
}
149
128
0 commit comments