mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +08:00

* Update copyright comment for go files Signed-off-by: nwneisen <nwneisen@gmail.com> * Update copyright in assortment of file types Signed-off-by: nwneisen <nwneisen@gmail.com> * Remove missed copyright date Signed-off-by: nwneisen <nwneisen@gmail.com>
54 lines
1004 B
Go
54 lines
1004 B
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package producer_test
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/go-redis/redis"
|
|
dockertest "gopkg.in/ory-am/dockertest.v3"
|
|
)
|
|
|
|
const (
|
|
wrongID = 0
|
|
wrongValue = "wrong-value"
|
|
)
|
|
|
|
var redisClient *redis.Client
|
|
|
|
func TestMain(m *testing.M) {
|
|
pool, err := dockertest.NewPool("")
|
|
if err != nil {
|
|
log.Fatalf("Could not connect to docker: %s", err)
|
|
}
|
|
|
|
container, err := pool.Run("redis", "5.0-alpine", nil)
|
|
if err != nil {
|
|
log.Fatalf("Could not start container: %s", err)
|
|
}
|
|
|
|
if err := pool.Retry(func() error {
|
|
redisClient = redis.NewClient(&redis.Options{
|
|
Addr: fmt.Sprintf("localhost:%s", container.GetPort("6379/tcp")),
|
|
Password: "",
|
|
DB: 0,
|
|
})
|
|
|
|
return redisClient.Ping().Err()
|
|
}); err != nil {
|
|
log.Fatalf("Could not connect to docker: %s", err)
|
|
}
|
|
|
|
code := m.Run()
|
|
|
|
if err := pool.Purge(container); err != nil {
|
|
log.Fatalf("Could not purge container: %s", err)
|
|
}
|
|
|
|
os.Exit(code)
|
|
}
|