1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00
Manuel Imperiale a185855c06
MF-1061 - Add name, protocol and publisher tests to influxdb-reader (#1320)
* MF-1061 - Add name, protocol and publisher tests to influxdb-reader

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix typo

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Use short package aliases

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2021-01-11 10:53:38 +01:00

59 lines
1.3 KiB
Go

package influxdb_test
import (
"fmt"
"os"
"testing"
"time"
influxdata "github.com/influxdata/influxdb/client/v2"
influxdb "github.com/influxdata/influxdb/client/v2"
log "github.com/mainflux/mainflux/logger"
dockertest "github.com/ory/dockertest/v3"
)
var (
testLog, _ = log.New(os.Stdout, log.Info.String())
clientCfg = influxdata.HTTPConfig{
Username: "test",
Password: "test",
}
)
func TestMain(m *testing.M) {
pool, err := dockertest.NewPool("")
if err != nil {
testLog.Error(fmt.Sprintf("Could not connect to docker: %s", err))
}
cfg := []string{
"INFLUXDB_USER=test",
"INFLUXDB_USER_PASSWORD=test",
"INFLUXDB_DB=test",
}
container, err := pool.Run("influxdb", "1.6.4-alpine", cfg)
if err != nil {
testLog.Error(fmt.Sprintf("Could not start container: %s", err))
}
port := container.GetPort("8086/tcp")
clientCfg.Addr = fmt.Sprintf("http://localhost:%s", port)
if err := pool.Retry(func() error {
client, err = influxdb.NewHTTPClient(clientCfg)
_, _, err = client.Ping(5 * time.Millisecond)
return err
}); err != nil {
testLog.Error(fmt.Sprintf("Could not connect to docker: %s", err))
}
code := m.Run()
if err := pool.Purge(container); err != nil {
testLog.Error(fmt.Sprintf("Could not purge container: %s", err))
}
os.Exit(code)
}