CrudGO

Basic CRUD API (https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) in Golang with data stored in Mongo DB.

Installation

1. cd CrudGo 
2. go run main.go
3. Open Postman & test APIs
4. run testcases : go test -v OR goconvey

Note :
Fetching dependencies 
$ go get github.com/smartystreets/goconvey/convey gopkg.in/mgo.v2 github.com/gorilla/mux github.com/sirupsen/logrus

1. [Install Go ](https://golang.org/doc/install)
2. [Install Mongo](https://docs.mongodb.com/manual/installation/)
3. Install GoConvey (go get  "github.com/smartystreets/goconvey/convey")
4. Install Logrus (go get "github.com/sirupsen/logrus")

Schema

User

{ "users": 
    [{ "username": "jsmith", "displayName": "John Smith", "department": "Sales" }, 
    { "username": "jdoe", "displayName": "John Doe", "department": "Development" }] 
} 

API Lists

API 1 : Get All Users

API 2 : Insert a user

API 4 : Delete user by username

Running Test cases

sourabh:user sourabh$ go test -v
=== RUN   TestInsertNewUser

  Testing InsertNewUser function 
    Testing for incorrect input 
      Testing for empty username input 
        Error returned by InsertNewUser should not be nil ✔
    Testing for correct input 
      Testing for valid input (inserting test user) 
        Error returned by InsertNewUser should be nil ✔


2 total assertions

--- PASS: TestInsertNewUser (0.01s)
=== RUN   TestGetAllUsers

  Testing GetAllUsers function 
    Testing for valid input 
      Error returned by GetAllUsers should be nil ✔
      Length of users list returned by GetAllUsers should be not be nil ✔


4 total assertions

--- PASS: TestGetAllUsers (0.00s)
=== RUN   TestGetUserByName

  Testing GetUserByName function 
    Testing for invalid input 
      Testing for empty username 
        Error returned by GetUserByName should be nil ✔
    Testing for valid input 
      Error returned by GetUserByName should be nil ✔


6 total assertions

--- PASS: TestGetUserByName (0.00s)
=== RUN   TestDeleteUser

  Testing DeleteUser function 
    Document should be deleted after calling DeleteUser function ✔


7 total assertions

--- PASS: TestDeleteUser (0.02s)
PASS
ok      github.com/CrudGO/user  0.053s