コード例 #1
0
ファイル: main.go プロジェクト: CrazyCompiler/todoMaker
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)
	}

}
コード例 #2
0
ファイル: task_test.go プロジェクト: CrazyCompiler/todoMaker
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)
	}
}
コード例 #3
0
ファイル: task_test.go プロジェクト: CrazyCompiler/todoMaker
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)
	}
}
コード例 #4
0
ファイル: task_test.go プロジェクト: CrazyCompiler/todoMaker
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)
	}
}