Integrations-Tests-MongoDBAtlas-Go

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2022 License: MIT

README

Integration Tests to MongoDBAtlas with Go GitHub go.mod Go version

This repository can help you to integrate a MongoDBAtlas cluster database into your Go application and test the operations of creating, reading, updating, and deleting documents from a collection.


Pre-requirements 📋

Have access to a MongoDBAtlas cluster.
In this link you have a guide on how to create it: https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster/


Instalation 🔧
  • Install the MongoDB driver as a dependency
go get go.mongodb.org/mongo-driver/mongo  
  • Inside the database folder, modify the mongodb.con.go file. Add the uri of your cluster and the name of your database
var (
	// Add the uri of your cluster of MongoDBAtlas
	// https://www.mongodb.com/docs/drivers/go/current/quick-start/#connect-to-your-cluster
	uri = ""
	// Add the name of your database
	database = ""
)

Running the test ⚙️

To run the test, type this command:

go test
  • To verify the connection, run the test inside /database directory.
  • To test CRUD operations, run the test inside /service/user.service directory.
    By default it will create the "users" collection, if you want to change the collection, modify the user.repository.go file located inside /repositories/user.repository/
// Name of collection
var collection = database.GetCollection("users")

Directories

Path Synopsis
repositories
services

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL