Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

install_test.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 integration
  5. import (
  6. "fmt"
  7. "net/http"
  8. "os"
  9. "os/user"
  10. "testing"
  11. "time"
  12. "code.gitea.io/gitea/integrations/internal/utils"
  13. )
  14. // The HTTP port listened by the Gitea server.
  15. const ServerHTTPPort = "3001"
  16. const _RetryLimit = 10
  17. func makeSimpleSettings(user, port string) map[string][]string {
  18. return map[string][]string{
  19. "db_type": {"SQLite3"},
  20. "db_host": {"localhost"},
  21. "db_path": {"data/gitea.db"},
  22. "app_name": {"Gitea: Git with a cup of tea"},
  23. "repo_root_path": {"repositories"},
  24. "run_user": {user},
  25. "domain": {"localhost"},
  26. "ssh_port": {"22"},
  27. "http_port": {port},
  28. "app_url": {"http://localhost:" + port},
  29. "log_root_path": {"log"},
  30. }
  31. }
  32. func install(t *utils.T) error {
  33. var r *http.Response
  34. var err error
  35. for i := 1; i <= _RetryLimit; i++ {
  36. r, err = http.Get("http://:" + ServerHTTPPort + "/")
  37. if err == nil {
  38. fmt.Fprintln(os.Stderr)
  39. break
  40. }
  41. // Give the server some amount of time to warm up.
  42. time.Sleep(100 * time.Millisecond)
  43. fmt.Fprint(os.Stderr, ".")
  44. }
  45. if err != nil {
  46. return err
  47. }
  48. defer r.Body.Close()
  49. _user, err := user.Current()
  50. if err != nil {
  51. return err
  52. }
  53. settings := makeSimpleSettings(_user.Username, ServerHTTPPort)
  54. r, err = http.PostForm("http://:"+ServerHTTPPort+"/install", settings)
  55. if err != nil {
  56. return err
  57. }
  58. defer r.Body.Close()
  59. if r.StatusCode != http.StatusOK {
  60. return fmt.Errorf("'/install': %s", r.Status)
  61. }
  62. return nil
  63. }
  64. func TestInstall(t *testing.T) {
  65. conf := utils.Config{
  66. Program: "../gitea",
  67. WorkDir: "",
  68. Args: []string{"web", "--port", ServerHTTPPort},
  69. LogFile: os.Stderr,
  70. }
  71. if err := utils.New(t, &conf).RunTest(install); err != nil {
  72. t.Fatal(err)
  73. }
  74. }