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

elasticsearch_test.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package elasticsearch
  4. import (
  5. "fmt"
  6. "net/http"
  7. "os"
  8. "testing"
  9. "time"
  10. "code.gitea.io/gitea/modules/indexer/issues/internal/tests"
  11. )
  12. func TestElasticsearchIndexer(t *testing.T) {
  13. // The elasticsearch instance started by pull-db-tests.yml > test-unit > services > elasticsearch
  14. url := "http://elastic:changeme@elasticsearch:9200"
  15. if os.Getenv("CI") == "" {
  16. // Make it possible to run tests against a local elasticsearch instance
  17. url = os.Getenv("TEST_ELASTICSEARCH_URL")
  18. if url == "" {
  19. t.Skip("TEST_ELASTICSEARCH_URL not set and not running in CI")
  20. return
  21. }
  22. }
  23. ok := false
  24. for i := 0; i < 60; i++ {
  25. resp, err := http.Get(url)
  26. if err == nil && resp.StatusCode == http.StatusOK {
  27. ok = true
  28. break
  29. }
  30. t.Logf("Waiting for elasticsearch to be up: %v", err)
  31. time.Sleep(time.Second)
  32. }
  33. if !ok {
  34. t.Fatalf("Failed to wait for elasticsearch to be up")
  35. return
  36. }
  37. indexer := NewIndexer(url, fmt.Sprintf("test_elasticsearch_indexer_%d", time.Now().Unix()))
  38. defer indexer.Close()
  39. tests.TestIndexer(t, indexer)
  40. }