Ejemplo n.º 1
0
func main() {
	configObject := config.ContextObject{}
	errorLogFilePath := "errorLog"
	errorFile, err := os.OpenFile(errorLogFilePath, os.O_APPEND|os.O_WRONLY, 0600)
	if err != nil {
		panic(err)
	}
	defer errorFile.Close()

	configObject.ErrorLogFile = errorFile

	dbConfigFilePath := "dbConfigFile"
	if len(os.Args) > 1 {
		dbConfigFilePath = os.Args[1]
	}
	dbConfigDataJson := fileReaders.ReadJsonFile(dbConfigFilePath)
	dbinfo := database.CreateDbInfo(dbConfigDataJson)

	configObject.Db, err = sql.Open("postgres", dbinfo)

	configObject.Db.Ping()

	if err != nil {
		errorHandler.ErrorHandler(configObject.ErrorLogFile, err)
	}

	defer configObject.Db.Close()
	routers.HandleRequests(configObject)

	err = http.ListenAndServe(":9090", nil)
	if err != nil {
		fmt.Println("their was error ", err)
	}

}
Ejemplo n.º 2
0
func TestGet(t *testing.T) {
	db, mock, err := sqlmock.New()
	assert.Nil(t, err)
	rows := sqlmock.NewRows([]string{"hello", "High"})
	mock.ExpectQuery("select taskId,task,priority from tasks;").WillReturnRows(rows)

	contextObject := config.ContextObject{}
	contextObject.ErrorLogFile, err = os.OpenFile(errorLogFilePath, os.O_APPEND|os.O_WRONLY, 0600)
	contextObject.Db = db

	Get(contextObject)

	if err := mock.ExpectationsWereMet(); err != nil {
		t.Errorf("there were unfulfilled expections: %s", err)
	}
}
Ejemplo n.º 3
0
func TestDelete(t *testing.T) {
	db, mock, err := sqlmock.New()
	assert.Nil(t, err)

	taskId := 1

	mock.ExpectExec("delete from tasks").
		WithArgs(taskId).
		WillReturnResult(sqlmock.NewResult(1, 1))

	contextObject := config.ContextObject{}
	contextObject.ErrorLogFile, err = os.OpenFile(errorLogFilePath, os.O_APPEND|os.O_WRONLY, 0600)
	contextObject.Db = db

	Delete(contextObject, taskId)

	if err := mock.ExpectationsWereMet(); err != nil {
		t.Errorf("there were unfulfilled expections: %s", err)
	}
}
Ejemplo n.º 4
0
func TestAdd(t *testing.T) {
	db, mock, err := sqlmock.New()
	assert.Nil(t, err)

	task := "dring water"
	priority := "High"

	mock.ExpectExec("insert into tasks").
		WithArgs(task, priority).
		WillReturnResult(sqlmock.NewResult(1, 1))

	contextObject := config.ContextObject{}
	contextObject.ErrorLogFile, err = os.OpenFile(errorLogFilePath, os.O_APPEND|os.O_WRONLY, 0600)
	contextObject.Db = db

	Add(contextObject, task, priority)

	if err := mock.ExpectationsWereMet(); err != nil {
		t.Errorf("there were unfulfilled expections: %s", err)
	}
}