diff options
Diffstat (limited to 'storage_test.go')
-rw-r--r-- | storage_test.go | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/storage_test.go b/storage_test.go index 6b36833..b46b60a 100644 --- a/storage_test.go +++ b/storage_test.go @@ -1,21 +1,11 @@ package main import ( - "crypto/sha256" - "fmt" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" - "golang.org/x/net/context" - "os" "testing" - "time" ) const testCollection = "characters" -var storage Storage -var testContext context.Context - func testInsert(t *testing.T) { // insert a document in an invalid connection insertedId, err := storage.InsertOne(testContext, "invalid_collection", @@ -98,37 +88,3 @@ func TestBasicOperations(t *testing.T) { t.Run("testInsert", testInsert) t.Run("testFindOne", testFindOne) } - -func TestMain(m *testing.M) { - mongoHost, ok := os.LookupEnv("MONGO_HOST") - if !ok { - mongoHost = "localhost" - } - mongoPort, ok := os.LookupEnv("MONGO_PORT") - if !ok { - mongoPort = "27017" - } - - uniqueDatabaseName := sha256.Sum256([]byte(time.Now().String())) - - client, err := mongo.NewClient(options.Client().ApplyURI(fmt.Sprintf("mongodb://%s:%v", mongoHost, mongoPort))) - if err != nil { - panic("failed to create mongo client") - } - - db := client.Database(fmt.Sprintf("%x", uniqueDatabaseName[:31])) - storage = Storage{ - client: client, - collections: map[string]*mongo.Collection{testCollection: db.Collection(testCollection)}, - } - - testContext, _ = context.WithTimeout(context.Background(), 10 * time.Second) - - err = storage.Connect(nil) - if err != nil { - panic(err) - } - - exitCode := m.Run() - os.Exit(exitCode) -} |