Skip to content

Commit

Permalink
fix(elasticsearch): close es test container after tests (#78)
Browse files Browse the repository at this point in the history
* fix: kill es test container after tests

* fix: remove stopped es test container
  • Loading branch information
bsushmith authored Feb 17, 2022
1 parent 1f87a44 commit bd2e4cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions store/elasticsearch/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"testing"

Expand All @@ -20,8 +21,13 @@ func TestMain(m *testing.M) {
// an elasticsearch server. That means you can't run unit tests
// standlone :/
esTestServer = testutil.NewElasticsearchTestServer()
defer esTestServer.Close()
os.Exit(m.Run())
exitCode := m.Run()

if err := esTestServer.Close(); err != nil {
fmt.Println("Error closing elasticsearch test server:", err)
return
}
os.Exit(exitCode)
}

// name this somethings that's more generic
Expand Down
3 changes: 1 addition & 2 deletions store/elasticsearch/testutil/elastic_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (

var (
elasticSearchCmdLine = []string{
"docker", "run", "-d", "-P", "-e", "discovery.type=single-node",
"elasticsearch:7.6.1",
"docker", "run", "-d", "-P", "--rm", "-e", "discovery.type=single-node", "elasticsearch:7.6.1",
}
// "9200/tcp" refers to the default container port where elasticsearch server runs
esHostQuery = `{{index .NetworkSettings.Ports "9200/tcp" 0 "HostIp"}}:{{index .NetworkSettings.Ports "9200/tcp" 0 "HostPort"}}`
Expand Down

0 comments on commit bd2e4cc

Please sign in to comment.