1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
Ivan Milošević effade00aa MF-325 - Add SPDX license and copyright headers (#362)
* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Add SPDX license and copyright headers

Signed-off-by: Ivan Milošević <iva@blokovi.com>

* MF-325 - Change mainflux version from 0.4.0 to 0.5.0

Signed-off-by: Ivan Milošević <iva@blokovi.com>
2018-08-26 13:15:48 +02:00

54 lines
1.0 KiB
Go

//
// Copyright (c) 2018
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package mongodb_test
import (
"context"
"fmt"
"os"
"testing"
"github.com/mongodb/mongo-go-driver/mongo"
dockertest "gopkg.in/ory-am/dockertest.v3"
)
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{
"MONGO_INITDB_DATABASE=test",
}
container, err := pool.Run("mongo", "3.6-jessie", cfg)
if err != nil {
testLog.Error(fmt.Sprintf("Could not start container: %s", err))
}
port = container.GetPort("27017/tcp")
addr = fmt.Sprintf("mongodb://localhost:%s", port)
if err := pool.Retry(func() error {
_, err := mongo.Connect(context.Background(), addr, nil)
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)
}