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