Skip to content

Commit

Permalink
added coverage.txt into .gitignore and solved some linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
raybittu committed Feb 16, 2021
1 parent 73df8db commit d0437fd
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 72 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
*.so
*.dylib

.DS_Store

# Test binary, built with `go test -c`
*.test

./.DS_Store
.DS_Store
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.DS_Store

./panel/coverage.txt
./panel/service/coverage.txt
./panel/store/coverage.txt
./panel/http/coverage.txt

# Dependency directories (remove the comment below to include it)
# vendor/

Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func main() {

dataStore := store.New()
dataService := service.New(dataStore)
dataHttp := http.New(dataService)
dataHTTP := http.New(dataService)

app.GET("/{companyID}/employees", dataHttp.GetAllEmployee)
app.GET("/{companyID}/employees/{employeeID}", dataHttp.GetEmployeeByID)
app.POST("/{companyID}/employees", dataHttp.CreateEmployee)
app.PUT("/{companyID}/employees/{employeeID}", dataHttp.EditEmployee)
app.DELETE("/{companyID}/employees/{employeeID}", dataHttp.DeleteEmployee)
app.GET("/{companyID}/employees", dataHTTP.GetAllEmployee)
app.GET("/{companyID}/employees/{employeeID}", dataHTTP.GetEmployeeByID)
app.POST("/{companyID}/employees", dataHTTP.CreateEmployee)
app.PUT("/{companyID}/employees/{employeeID}", dataHTTP.EditEmployee)
app.DELETE("/{companyID}/employees/{employeeID}", dataHTTP.DeleteEmployee)

app.Run()
}
11 changes: 5 additions & 6 deletions panel/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestHTTPLayer(t *testing.T) {
db, _, _ := sqlmock.New()
c := &gofr.Context{Container: &gofr.Container{
Logger: logging.NewLogger(logging.DEBUG),
DB: &gofr.DB{db},
DB: &gofr.DB{DB: db},
}}

testCreateEmployeeHTTP(t, c)
Expand Down Expand Up @@ -136,7 +136,6 @@ func testGetEmployeeByIDHTTP(t *testing.T, c *gofr.Context) {
}

for i := range testcases {
//req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/{%s}/employees", testcases[i].input.companyID), bytes.NewBuffer(testcases[i].input.Emp))
req := httptest.NewRequest(http.MethodGet, "/someURL/", nil)
req = mux.SetURLVars(req, map[string]string{"companyID": testcases[i].input.companyID, "employeeID": testcases[i].input.employeeID})
gofrReq := gofrHTTP.NewRequest(req)
Expand Down Expand Up @@ -195,7 +194,7 @@ func testEditEmployeeHTTP(t *testing.T, c *gofr.Context) {
},
}

for i, _ := range testcases {
for i := range testcases {
req := httptest.NewRequest(http.MethodPut, "/someURL/", nil)
req = mux.SetURLVars(req, map[string]string{"companyID": testcases[i].input.companyID, "employeeID": testcases[i].input.employeeID})
gofrReq := gofrHTTP.NewRequest(req)
Expand Down Expand Up @@ -306,7 +305,7 @@ func (m mockService) CreateEmployee(c *gofr.Context, companyID int, emp *models.
return models.Employee{}, customerror.ErrDBServer
}

func (m mockService) GetEmployeeByID(c *gofr.Context, companyID int, employeeID int) (models.Employee, error) {
func (m mockService) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) {
if companyID == 1 && employeeID == 1 {
return models.Employee{ID: 1, Name: "Ishan Pandey", Email: "[email protected]", Phone: 7250073079, Designation: "SDE1", YOE: 2, CompanyID: 1}, nil
}
Expand All @@ -323,7 +322,7 @@ func (m mockService) GetAllEmployee(c *gofr.Context, companyID int, queryParams
return nil, customerror.ErrDBServer
}

func (m mockService) EditEmployee(c *gofr.Context, companyID int, employeeID int, emp *models.Employee) (models.Employee, error) {
func (m mockService) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (models.Employee, error) {
if companyID == 1 && employeeID == 3 {
return models.Employee{ID: 3, Name: "Ishanx Pandey", Email: "[email protected]", Phone: 7250073079, Designation: "SDE1", YOE: 2, CompanyID: 1}, nil
}
Expand All @@ -333,6 +332,6 @@ func (m mockService) EditEmployee(c *gofr.Context, companyID int, employeeID int
return models.Employee{}, customerror.ErrDBServer
}

func (m mockService) DeleteEmployee(c *gofr.Context, companyID int, employeeID int) error {
func (m mockService) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error {
return nil
}
4 changes: 2 additions & 2 deletions panel/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type panelEmployeeService struct {
store store.Panel
}

func New(store store.Panel) PanelEmployee {
return panelEmployeeService{store: store}
func New(storeInterface store.Panel) PanelEmployee {
return panelEmployeeService{store: storeInterface}
}

func (p panelEmployeeService) GetAllEmployee(c *gofr.Context, companyID int, queryParam map[string]interface{}) ([]models.Employee, error) {
Expand Down
19 changes: 4 additions & 15 deletions panel/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestServiceLayer(t *testing.T) {
db, _, _ := sqlmock.New()
c := &gofr.Context{Container: &gofr.Container{
Logger: logging.NewLogger(logging.DEBUG),
DB: &gofr.DB{db},
DB: &gofr.DB{DB: db},
}}

testCreateEmployeeService(t, c)
Expand All @@ -36,8 +36,7 @@ func TestServiceLayer(t *testing.T) {
}

func testAllEmployeeService(t *testing.T, c *gofr.Context) {

testCases := []struct {
var testCases = []struct {
input int
expectedOutput []models.Employee
expectedErr error
Expand All @@ -46,7 +45,7 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) {
{
input: 1,
expectedOutput: []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
{2, "Bittu Ray", "[email protected]", 7250073080, "sde2", 2, 1},
{ID: 2, Name: "Bittu Ray", Email: "[email protected]", Phone: 7250073080, Designation: "sde2", YOE: 2, CompanyID: 1},
},
expectedErr: nil,
queryParams: map[string]interface{}{
Expand Down Expand Up @@ -92,7 +91,6 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) {
},
},
}

for i := range testCases {
dataService := New(mockStore{})
output, err := dataService.GetAllEmployee(c, testCases[i].input, testCases[i].queryParams)
Expand All @@ -111,7 +109,7 @@ func testEmployeeByIDService(t *testing.T, c *gofr.Context) {
}{
{
input: inputData{1, 1},
expectedOutput: models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
expectedOutput: models.Employee{ID: 1, Name: "Bittu", Email: "[email protected]", Phone: 7250073079, Designation: "sde1", YOE: 2, CompanyID: 1},
expectedErr: nil,
},

Expand Down Expand Up @@ -141,7 +139,6 @@ func testEmployeeByIDService(t *testing.T, c *gofr.Context) {
}

func testCreateEmployeeService(t *testing.T, c *gofr.Context) {

type InputData struct {
companyID int
body models.Employee
Expand Down Expand Up @@ -197,7 +194,6 @@ func testCreateEmployeeService(t *testing.T, c *gofr.Context) {
output, err := dataService.CreateEmployee(c, testCases[i].input.companyID, &testCases[i].input.body)
CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output)
}

}

func testEditEmployeeService(t *testing.T, c *gofr.Context) {
Expand Down Expand Up @@ -242,11 +238,8 @@ func testEditEmployeeService(t *testing.T, c *gofr.Context) {
&testCases[i].input.body)
CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output)
}

}

func testDeleteEmployeeService(t *testing.T, c *gofr.Context) {

type InputData struct {
companyID int
employeeID int
Expand Down Expand Up @@ -304,11 +297,9 @@ func (m mockStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID i
if companyID == 2 {
return nil, customerror.ErrDBServer
}

res := []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
{2, "Bittu Ray", "[email protected]", 7250073080, "sde2", 2, 1},
}

return res, nil
}

Expand All @@ -319,9 +310,7 @@ func (m mockStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (
if companyID != employeeID {
return models.Employee{}, customerror.ErrRecordNotFound
}

return models.Employee{}, nil

}

func (m mockStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (int, error) {
Expand Down
2 changes: 1 addition & 1 deletion panel/store/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ type Panel interface {
GetEmployeeByID(*gofr.Context, int, int) (models.Employee, error)
CreateEmployee(*gofr.Context, int, *models.Employee) (int, error)
EditEmployee(*gofr.Context, int, int, *models.Employee) (int, error)
DeleteEmployee(c *gofr.Context, id, companyId int) error
DeleteEmployee(*gofr.Context, int, int) error
}
6 changes: 5 additions & 1 deletion panel/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (p panelStore) GetAllEmployeeWithDesignation(c *gofr.Context, companyID int
if len(res) == 0 {
return res, customerror.ErrRecordNotFound
}

return res, nil
}

Expand All @@ -55,6 +56,7 @@ func (p panelStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID
if len(res) == 0 {
return res, customerror.ErrRecordNotFound
}

return res, nil
}

Expand All @@ -74,7 +76,6 @@ func (p panelStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int)
}
}
if res.ID == 0 {
//fmt.Println("res is ", res)
return res, customerror.ErrRecordNotFound
}
return res, nil
Expand All @@ -92,6 +93,7 @@ func (p panelStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.E
if id == -1 {
return -1, customerror.ErrRecordNotFound
}

return int(id), nil
}

Expand All @@ -107,6 +109,7 @@ func (p panelStore) EditEmployee(c *gofr.Context, companyID, employeeID int, emp
if r == 0 {
return -1, customerror.ErrRecordNotFound
}

return int(r), nil
}

Expand All @@ -123,5 +126,6 @@ func (p panelStore) DeleteEmployee(c *gofr.Context, companyID, employeeID int) e
// Some issue while deleting record.
return customerror.ErrRecordNotFound
}

return err
}
Loading

0 comments on commit d0437fd

Please sign in to comment.