@@ -6,7 +6,6 @@ package cmd
66import (
77 "fmt"
88 "io"
9- "os"
109 "path/filepath"
1110 "strings"
1211 "testing"
@@ -113,37 +112,17 @@ func TestCliCmd(t *testing.T) {
113112 _ , _ = fmt .Fprint (ctx .App .Writer , makePathOutput (setting .AppWorkPath , setting .CustomPath , setting .CustomConf ))
114113 return nil
115114 })
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-
137115 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+ })
147126 }
148127}
149128
0 commit comments