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.

install_test.go 2.1 kB

Add basic integration test infrastructure (and new endpoint `/api/v1/version` for testing it) (#741) * Implement '/api/v1/version' * Cleanup and various fixes * Enhance run.sh * Add install_test.go * Add parameter utils.Config for testing handlers * Re-organize TestVersion.go * Rename functions * handling process cleanup properly * Fix missing function renaming * Cleanup the 'retry' logic * Cleanup * Remove unneeded logging code * Logging messages tweaking * Logging message tweaking * Fix logging messages * Use 'const' instead of hardwired numbers * We don't really need retries anymore * Move constant ServerHttpPort to install_test.go * Restore mistakenly removed constant * Add required comments to make the linter happy. * Fix comments and naming to address linter's complaints * Detect Gitea executale version automatically * Remove tests/run.sh, `go test` suffices. * Make `make build` a prerequisite of `make test` * Do not sleep before trying * Speedup the server pinging loop * Use defined const instead of hardwired numbers * Remove redundant error handling * Use a dedicated target for running code.gitea.io/tests * Do not make 'test' depend on 'build' target * Rectify the excluded package list * Remove redundant 'exit 1' * Change the API to allow passing test.T to test handlers * Make testing.T an embedded field * Use assert.Equal to comparing results * Add copyright info * Parametrized logging output * Use tmpdir instead * Eliminate redundant casting * Remove unneeded variable * Fix last commit * Add missing copyright info * Replace fmt.Fprintf with fmt.Fprint * rename the xtest to integration-test * Use Symlink instead of hard-link for cross-device linking * Turn debugging logs on * Follow the existing framework for APIs * Output logs only if test.v is true * Re-order import statements * Enhance the error message * Fix comment which breaks the linter's rule * Rename 'integration-test' to 'e2e-test' for saving keystrokes * Add comment to avoid possible confusion * Rename tests -> integration-tests Also change back the Makefile to use `make integration-test`. * Use tests/integration for now * tests/integration -> integrations Slightly flattened directory hierarchy is better. * Update Makefile accordingly * Fix a missing change in Makefile * govendor update code.gitea.io/sdk/gitea * Fix comment of struct fields * Fix conditional nonsense * Fix missing updates regarding version string changes * Make variable naming more consistent * Check http status code * Rectify error messages
8 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. "path/filepath"
  11. "testing"
  12. "time"
  13. "code.gitea.io/gitea/integrations/internal/utils"
  14. )
  15. // The HTTP port listened by the Gitea server.
  16. const ServerHTTPPort = "3001"
  17. const _RetryLimit = 10
  18. func makeSimpleSettings(user, workdir, port string) map[string][]string {
  19. return map[string][]string{
  20. "db_type": {"SQLite3"},
  21. "db_host": {"localhost"},
  22. "db_path": {workdir + "data/gitea.db"},
  23. "app_name": {"Gitea: Git with a cup of tea"},
  24. "repo_root_path": {workdir + "repositories"},
  25. "run_user": {user},
  26. "domain": {"localhost"},
  27. "ssh_port": {"22"},
  28. "http_port": {port},
  29. "app_url": {"http://localhost:" + port},
  30. "log_root_path": {workdir + "log"},
  31. }
  32. }
  33. func install(t *utils.T) error {
  34. var r *http.Response
  35. var err error
  36. for i := 1; i <= _RetryLimit; i++ {
  37. r, err = http.Get("http://:" + ServerHTTPPort + "/")
  38. if err == nil {
  39. fmt.Fprintln(os.Stderr)
  40. break
  41. }
  42. // Give the server some amount of time to warm up.
  43. time.Sleep(100 * time.Millisecond)
  44. fmt.Fprint(os.Stderr, ".")
  45. }
  46. if err != nil {
  47. return err
  48. }
  49. defer r.Body.Close()
  50. _user, err := user.Current()
  51. if err != nil {
  52. return err
  53. }
  54. path, err := filepath.Abs(t.Config.WorkDir)
  55. if err != nil {
  56. return err
  57. }
  58. settings := makeSimpleSettings(_user.Username, path, ServerHTTPPort)
  59. r, err = http.PostForm("http://:"+ServerHTTPPort+"/install", settings)
  60. if err != nil {
  61. return err
  62. }
  63. defer r.Body.Close()
  64. if r.StatusCode != http.StatusOK {
  65. return fmt.Errorf("'/install': %s", r.Status)
  66. }
  67. return nil
  68. }
  69. func TestInstall(t *testing.T) {
  70. conf := utils.Config{
  71. Program: "../gitea",
  72. WorkDir: "",
  73. Args: []string{"web", "--port", ServerHTTPPort},
  74. LogFile: os.Stderr,
  75. }
  76. if err := utils.New(t, &conf).RunTest(install); err != nil {
  77. t.Fatal(err)
  78. }
  79. }