gitea源码

elasticsearch_test.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. "github.com/stretchr/testify/require"
  12. )
  13. func TestElasticsearchIndexer(t *testing.T) {
  14. // The elasticsearch instance started by pull-db-tests.yml > test-unit > services > elasticsearch
  15. url := "http://elastic:changeme@elasticsearch:9200"
  16. if os.Getenv("CI") == "" {
  17. // Make it possible to run tests against a local elasticsearch instance
  18. url = os.Getenv("TEST_ELASTICSEARCH_URL")
  19. if url == "" {
  20. t.Skip("TEST_ELASTICSEARCH_URL not set and not running in CI")
  21. return
  22. }
  23. }
  24. require.Eventually(t, func() bool {
  25. resp, err := http.Get(url)
  26. return err == nil && resp.StatusCode == http.StatusOK
  27. }, time.Minute, time.Second, "Expected elasticsearch to be up")
  28. indexer := NewIndexer(url, fmt.Sprintf("test_elasticsearch_indexer_%d", time.Now().Unix()))
  29. defer indexer.Close()
  30. tests.TestIndexer(t, indexer)
  31. }