You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

integration_test.go 14 kB

Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
Template Repositories (#8768) * Start work on templates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Continue work Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix IsTemplate vs IsGenerated Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tabs vs spaces * Tabs vs Spaces * Add templates to API & start adding tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix integration tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove unused User Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move template tests to existing repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Minor re-check updates and cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test cleanup Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix optionalbool Signed-off-by: jolheiser <john.olheiser@gmail.com> * make fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Test fixes and icon change Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add new user and repo for tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests (finally) Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update meta repo with env variables Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move generation to create page Combine with repo create template Modify API search to prioritize owner for repo Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix tests and coverage Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger and JS lint Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API searching for own private repos Signed-off-by: jolheiser <john.olheiser@gmail.com> * Change wording Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix repo search test. User had a private repo that didn't show up Signed-off-by: jolheiser <john.olheiser@gmail.com> * Another search test fix Signed-off-by: jolheiser <john.olheiser@gmail.com> * Clarify git content Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Feedback updates Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add topics WIP Signed-off-by: jolheiser <john.olheiser@gmail.com> * Finish adding topics Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update locale Signed-off-by: jolheiser <john.olheiser@gmail.com>
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "bytes"
  7. "context"
  8. "database/sql"
  9. "encoding/json"
  10. "fmt"
  11. "io"
  12. "net/http"
  13. "net/http/cookiejar"
  14. "net/http/httptest"
  15. "net/url"
  16. "os"
  17. "path"
  18. "path/filepath"
  19. "runtime"
  20. "strings"
  21. "testing"
  22. "time"
  23. "code.gitea.io/gitea/models"
  24. "code.gitea.io/gitea/modules/base"
  25. "code.gitea.io/gitea/modules/graceful"
  26. "code.gitea.io/gitea/modules/log"
  27. "code.gitea.io/gitea/modules/queue"
  28. "code.gitea.io/gitea/modules/setting"
  29. "code.gitea.io/gitea/modules/storage"
  30. "code.gitea.io/gitea/modules/util"
  31. "code.gitea.io/gitea/routers"
  32. "code.gitea.io/gitea/routers/routes"
  33. "github.com/PuerkitoBio/goquery"
  34. "github.com/go-chi/chi"
  35. "github.com/stretchr/testify/assert"
  36. "github.com/unknwon/com"
  37. )
  38. var c chi.Router
  39. type NilResponseRecorder struct {
  40. httptest.ResponseRecorder
  41. Length int
  42. }
  43. func (n *NilResponseRecorder) Write(b []byte) (int, error) {
  44. n.Length += len(b)
  45. return len(b), nil
  46. }
  47. // NewRecorder returns an initialized ResponseRecorder.
  48. func NewNilResponseRecorder() *NilResponseRecorder {
  49. return &NilResponseRecorder{
  50. ResponseRecorder: *httptest.NewRecorder(),
  51. }
  52. }
  53. func TestMain(m *testing.M) {
  54. defer log.Close()
  55. managerCtx, cancel := context.WithCancel(context.Background())
  56. graceful.InitManager(managerCtx)
  57. defer cancel()
  58. initIntegrationTest()
  59. c = routes.NewChi()
  60. c.Mount("/", routes.NormalRoutes())
  61. routes.DelegateToMacaron(c)
  62. // integration test settings...
  63. if setting.Cfg != nil {
  64. testingCfg := setting.Cfg.Section("integration-tests")
  65. slowTest = testingCfg.Key("SLOW_TEST").MustDuration(slowTest)
  66. slowFlush = testingCfg.Key("SLOW_FLUSH").MustDuration(slowFlush)
  67. }
  68. if os.Getenv("GITEA_SLOW_TEST_TIME") != "" {
  69. duration, err := time.ParseDuration(os.Getenv("GITEA_SLOW_TEST_TIME"))
  70. if err == nil {
  71. slowTest = duration
  72. }
  73. }
  74. if os.Getenv("GITEA_SLOW_FLUSH_TIME") != "" {
  75. duration, err := time.ParseDuration(os.Getenv("GITEA_SLOW_FLUSH_TIME"))
  76. if err == nil {
  77. slowFlush = duration
  78. }
  79. }
  80. err := models.InitFixtures(
  81. path.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
  82. )
  83. if err != nil {
  84. fmt.Printf("Error initializing test database: %v\n", err)
  85. os.Exit(1)
  86. }
  87. exitCode := m.Run()
  88. writerCloser.t = nil
  89. if err = util.RemoveAll(setting.Indexer.IssuePath); err != nil {
  90. fmt.Printf("util.RemoveAll: %v\n", err)
  91. os.Exit(1)
  92. }
  93. if err = util.RemoveAll(setting.Indexer.RepoPath); err != nil {
  94. fmt.Printf("Unable to remove repo indexer: %v\n", err)
  95. os.Exit(1)
  96. }
  97. os.Exit(exitCode)
  98. }
  99. func initIntegrationTest() {
  100. giteaRoot := base.SetupGiteaRoot()
  101. if giteaRoot == "" {
  102. fmt.Println("Environment variable $GITEA_ROOT not set")
  103. os.Exit(1)
  104. }
  105. giteaBinary := "gitea"
  106. if runtime.GOOS == "windows" {
  107. giteaBinary += ".exe"
  108. }
  109. setting.AppPath = path.Join(giteaRoot, giteaBinary)
  110. if _, err := os.Stat(setting.AppPath); err != nil {
  111. fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)
  112. os.Exit(1)
  113. }
  114. giteaConf := os.Getenv("GITEA_CONF")
  115. if giteaConf == "" {
  116. fmt.Println("Environment variable $GITEA_CONF not set")
  117. os.Exit(1)
  118. } else if !path.IsAbs(giteaConf) {
  119. setting.CustomConf = path.Join(giteaRoot, giteaConf)
  120. } else {
  121. setting.CustomConf = giteaConf
  122. }
  123. setting.SetCustomPathAndConf("", "", "")
  124. setting.NewContext()
  125. util.RemoveAll(models.LocalCopyPath())
  126. setting.CheckLFSVersion()
  127. setting.InitDBConfig()
  128. if err := storage.Init(); err != nil {
  129. fmt.Printf("Init storage failed: %v", err)
  130. os.Exit(1)
  131. }
  132. switch {
  133. case setting.Database.UseMySQL:
  134. db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
  135. setting.Database.User, setting.Database.Passwd, setting.Database.Host))
  136. defer db.Close()
  137. if err != nil {
  138. log.Fatal("sql.Open: %v", err)
  139. }
  140. if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name)); err != nil {
  141. log.Fatal("db.Exec: %v", err)
  142. }
  143. case setting.Database.UsePostgreSQL:
  144. db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
  145. setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
  146. defer db.Close()
  147. if err != nil {
  148. log.Fatal("sql.Open: %v", err)
  149. }
  150. dbrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = '%s'", setting.Database.Name))
  151. if err != nil {
  152. log.Fatal("db.Query: %v", err)
  153. }
  154. defer dbrows.Close()
  155. if !dbrows.Next() {
  156. if _, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", setting.Database.Name)); err != nil {
  157. log.Fatal("db.Exec: CREATE DATABASE: %v", err)
  158. }
  159. }
  160. // Check if we need to setup a specific schema
  161. if len(setting.Database.Schema) == 0 {
  162. break
  163. }
  164. db.Close()
  165. db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
  166. setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
  167. // This is a different db object; requires a different Close()
  168. defer db.Close()
  169. if err != nil {
  170. log.Fatal("sql.Open: %v", err)
  171. }
  172. schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema))
  173. if err != nil {
  174. log.Fatal("db.Query: %v", err)
  175. }
  176. defer schrows.Close()
  177. if !schrows.Next() {
  178. // Create and setup a DB schema
  179. if _, err = db.Exec(fmt.Sprintf("CREATE SCHEMA %s", setting.Database.Schema)); err != nil {
  180. log.Fatal("db.Exec: CREATE SCHEMA: %v", err)
  181. }
  182. }
  183. case setting.Database.UseMSSQL:
  184. host, port := setting.ParseMSSQLHostPort(setting.Database.Host)
  185. db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;",
  186. host, port, "master", setting.Database.User, setting.Database.Passwd))
  187. if err != nil {
  188. log.Fatal("sql.Open: %v", err)
  189. }
  190. if _, err := db.Exec(fmt.Sprintf("If(db_id(N'%s') IS NULL) BEGIN CREATE DATABASE %s; END;", setting.Database.Name, setting.Database.Name)); err != nil {
  191. log.Fatal("db.Exec: %v", err)
  192. }
  193. defer db.Close()
  194. }
  195. routers.GlobalInit(graceful.GetManager().HammerContext())
  196. }
  197. func prepareTestEnv(t testing.TB, skip ...int) func() {
  198. t.Helper()
  199. ourSkip := 2
  200. if len(skip) > 0 {
  201. ourSkip += skip[0]
  202. }
  203. deferFn := PrintCurrentTest(t, ourSkip)
  204. assert.NoError(t, models.LoadFixtures())
  205. assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
  206. assert.NoError(t, com.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
  207. setting.RepoRootPath))
  208. return deferFn
  209. }
  210. type TestSession struct {
  211. jar http.CookieJar
  212. }
  213. func (s *TestSession) GetCookie(name string) *http.Cookie {
  214. baseURL, err := url.Parse(setting.AppURL)
  215. if err != nil {
  216. return nil
  217. }
  218. for _, c := range s.jar.Cookies(baseURL) {
  219. if c.Name == name {
  220. return c
  221. }
  222. }
  223. return nil
  224. }
  225. func (s *TestSession) MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
  226. t.Helper()
  227. baseURL, err := url.Parse(setting.AppURL)
  228. assert.NoError(t, err)
  229. for _, c := range s.jar.Cookies(baseURL) {
  230. req.AddCookie(c)
  231. }
  232. resp := MakeRequest(t, req, expectedStatus)
  233. ch := http.Header{}
  234. ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";"))
  235. cr := http.Request{Header: ch}
  236. s.jar.SetCookies(baseURL, cr.Cookies())
  237. return resp
  238. }
  239. func (s *TestSession) MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseRecorder {
  240. t.Helper()
  241. baseURL, err := url.Parse(setting.AppURL)
  242. assert.NoError(t, err)
  243. for _, c := range s.jar.Cookies(baseURL) {
  244. req.AddCookie(c)
  245. }
  246. resp := MakeRequestNilResponseRecorder(t, req, expectedStatus)
  247. ch := http.Header{}
  248. ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";"))
  249. cr := http.Request{Header: ch}
  250. s.jar.SetCookies(baseURL, cr.Cookies())
  251. return resp
  252. }
  253. const userPassword = "password"
  254. var loginSessionCache = make(map[string]*TestSession, 10)
  255. func emptyTestSession(t testing.TB) *TestSession {
  256. t.Helper()
  257. jar, err := cookiejar.New(nil)
  258. assert.NoError(t, err)
  259. return &TestSession{jar: jar}
  260. }
  261. func loginUser(t testing.TB, userName string) *TestSession {
  262. t.Helper()
  263. if session, ok := loginSessionCache[userName]; ok {
  264. return session
  265. }
  266. session := loginUserWithPassword(t, userName, userPassword)
  267. loginSessionCache[userName] = session
  268. return session
  269. }
  270. func loginUserWithPassword(t testing.TB, userName, password string) *TestSession {
  271. t.Helper()
  272. req := NewRequest(t, "GET", "/user/login")
  273. resp := MakeRequest(t, req, http.StatusOK)
  274. doc := NewHTMLParser(t, resp.Body)
  275. req = NewRequestWithValues(t, "POST", "/user/login", map[string]string{
  276. "_csrf": doc.GetCSRF(),
  277. "user_name": userName,
  278. "password": password,
  279. })
  280. resp = MakeRequest(t, req, http.StatusFound)
  281. ch := http.Header{}
  282. ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";"))
  283. cr := http.Request{Header: ch}
  284. session := emptyTestSession(t)
  285. baseURL, err := url.Parse(setting.AppURL)
  286. assert.NoError(t, err)
  287. session.jar.SetCookies(baseURL, cr.Cookies())
  288. return session
  289. }
  290. //token has to be unique this counter take care of
  291. var tokenCounter int64
  292. func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
  293. t.Helper()
  294. tokenCounter++
  295. req := NewRequest(t, "GET", "/user/settings/applications")
  296. resp := session.MakeRequest(t, req, http.StatusOK)
  297. doc := NewHTMLParser(t, resp.Body)
  298. req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{
  299. "_csrf": doc.GetCSRF(),
  300. "name": fmt.Sprintf("api-testing-token-%d", tokenCounter),
  301. })
  302. resp = session.MakeRequest(t, req, http.StatusFound)
  303. req = NewRequest(t, "GET", "/user/settings/applications")
  304. resp = session.MakeRequest(t, req, http.StatusOK)
  305. htmlDoc := NewHTMLParser(t, resp.Body)
  306. token := htmlDoc.doc.Find(".ui.info p").Text()
  307. return token
  308. }
  309. func NewRequest(t testing.TB, method, urlStr string) *http.Request {
  310. t.Helper()
  311. return NewRequestWithBody(t, method, urlStr, nil)
  312. }
  313. func NewRequestf(t testing.TB, method, urlFormat string, args ...interface{}) *http.Request {
  314. t.Helper()
  315. return NewRequest(t, method, fmt.Sprintf(urlFormat, args...))
  316. }
  317. func NewRequestWithValues(t testing.TB, method, urlStr string, values map[string]string) *http.Request {
  318. t.Helper()
  319. urlValues := url.Values{}
  320. for key, value := range values {
  321. urlValues[key] = []string{value}
  322. }
  323. req := NewRequestWithBody(t, method, urlStr, bytes.NewBufferString(urlValues.Encode()))
  324. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  325. return req
  326. }
  327. func NewRequestWithJSON(t testing.TB, method, urlStr string, v interface{}) *http.Request {
  328. t.Helper()
  329. jsonBytes, err := json.Marshal(v)
  330. assert.NoError(t, err)
  331. req := NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes))
  332. req.Header.Add("Content-Type", "application/json")
  333. return req
  334. }
  335. func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *http.Request {
  336. t.Helper()
  337. request, err := http.NewRequest(method, urlStr, body)
  338. assert.NoError(t, err)
  339. request.RequestURI = urlStr
  340. return request
  341. }
  342. func AddBasicAuthHeader(request *http.Request, username string) *http.Request {
  343. request.SetBasicAuth(username, userPassword)
  344. return request
  345. }
  346. const NoExpectedStatus = -1
  347. func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
  348. t.Helper()
  349. recorder := httptest.NewRecorder()
  350. c.ServeHTTP(recorder, req)
  351. if expectedStatus != NoExpectedStatus {
  352. if !assert.EqualValues(t, expectedStatus, recorder.Code,
  353. "Request: %s %s", req.Method, req.URL.String()) {
  354. logUnexpectedResponse(t, recorder)
  355. }
  356. }
  357. return recorder
  358. }
  359. func MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseRecorder {
  360. t.Helper()
  361. recorder := NewNilResponseRecorder()
  362. c.ServeHTTP(recorder, req)
  363. if expectedStatus != NoExpectedStatus {
  364. if !assert.EqualValues(t, expectedStatus, recorder.Code,
  365. "Request: %s %s", req.Method, req.URL.String()) {
  366. logUnexpectedResponse(t, &recorder.ResponseRecorder)
  367. }
  368. }
  369. return recorder
  370. }
  371. // logUnexpectedResponse logs the contents of an unexpected response.
  372. func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
  373. t.Helper()
  374. respBytes := recorder.Body.Bytes()
  375. if len(respBytes) == 0 {
  376. return
  377. } else if len(respBytes) < 500 {
  378. // if body is short, just log the whole thing
  379. t.Log("Response:", string(respBytes))
  380. return
  381. }
  382. // log the "flash" error message, if one exists
  383. // we must create a new buffer, so that we don't "use up" resp.Body
  384. htmlDoc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(respBytes))
  385. if err != nil {
  386. return // probably a non-HTML response
  387. }
  388. errMsg := htmlDoc.Find(".ui.negative.message").Text()
  389. if len(errMsg) > 0 {
  390. t.Log("A flash error message was found:", errMsg)
  391. }
  392. }
  393. func DecodeJSON(t testing.TB, resp *httptest.ResponseRecorder, v interface{}) {
  394. t.Helper()
  395. decoder := json.NewDecoder(resp.Body)
  396. assert.NoError(t, decoder.Decode(v))
  397. }
  398. func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
  399. t.Helper()
  400. req := NewRequest(t, "GET", urlStr)
  401. resp := session.MakeRequest(t, req, http.StatusOK)
  402. doc := NewHTMLParser(t, resp.Body)
  403. return doc.GetCSRF()
  404. }
  405. // resetFixtures flushes queues, reloads fixtures and resets test repositories within a single test.
  406. // Most tests should call defer prepareTestEnv(t)() (or have onGiteaRun do that for them) but sometimes
  407. // within a single test this is required
  408. func resetFixtures(t *testing.T) {
  409. assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
  410. assert.NoError(t, models.LoadFixtures())
  411. assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
  412. assert.NoError(t, com.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
  413. setting.RepoRootPath))
  414. }