Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use testcontainers-go for the integration tests #824

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions elasticsearch_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
"github.com/elastic/go-elasticsearch/v8/typedapi/some"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/result"
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
"log"
"net"
"net/http"
Expand All @@ -47,11 +41,40 @@ import (
"github.com/elastic/elastic-transport-go/v8/elastictransport"
"github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/esapi"
"github.com/elastic/go-elasticsearch/v8/internal/containertest"
"github.com/elastic/go-elasticsearch/v8/internal/version"
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
"github.com/elastic/go-elasticsearch/v8/typedapi/some"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/result"
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
)

func TestClientTransport(t *testing.T) {
stackVersion := version.Client
if v := os.Getenv("STACK_VERSION"); v != "" {
stackVersion = v
}

elasticsearchSrv, err := containertest.NewElasticsearchService(stackVersion)
if err != nil {
t.Fatalf("Error setting up Elasticsearch container: %s", err)
}
defer func() {
if err := elasticsearchSrv.Terminate(context.Background()); err != nil {
t.Fatalf("Error terminating Elasticsearch container: %s", err)
}
}()

tcCfg := elasticsearchSrv.ESConfig()

t.Setenv("ELASTICSEARCH_URL", tcCfg.Addresses[0])
t.Setenv("ELASTICSEARCH_USERNAME", tcCfg.Username)
t.Setenv("ELASTICSEARCH_PASSWORD", tcCfg.Password)

t.Run("Persistent", func(t *testing.T) {
es, err := elasticsearch.NewDefaultClient()
es, err := elasticsearch.NewClient(tcCfg)
if err != nil {
t.Fatalf("Error creating the client: %s", err)
}
Expand Down Expand Up @@ -103,7 +126,7 @@ func TestClientTransport(t *testing.T) {
t.Run("Concurrent", func(t *testing.T) {
var wg sync.WaitGroup

es, err := elasticsearch.NewDefaultClient()
es, err := elasticsearch.NewClient(tcCfg)
if err != nil {
t.Fatalf("Error creating the client: %s", err)
}
Expand All @@ -126,7 +149,7 @@ func TestClientTransport(t *testing.T) {
})

t.Run("WithContext", func(t *testing.T) {
es, err := elasticsearch.NewDefaultClient()
es, err := elasticsearch.NewClient(tcCfg)
if err != nil {
t.Fatalf("Error creating the client: %s", err)
}
Expand Down Expand Up @@ -154,6 +177,12 @@ func TestClientTransport(t *testing.T) {
InsecureSkipVerify: true,
},
},
Addresses: []string{
tcCfg.Addresses[0],
},
Username: tcCfg.Username,
Password: tcCfg.Password,
CACert: tcCfg.CACert,
}

es, err := elasticsearch.NewClient(cfg)
Expand Down
45 changes: 45 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,57 @@ go 1.21

require (
github.com/elastic/elastic-transport-go/v8 v8.5.0
github.com/testcontainers/testcontainers-go v0.29.1
github.com/testcontainers/testcontainers-go/modules/elasticsearch v0.29.1
go.opentelemetry.io/otel/trace v1.21.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading
Loading