示例#1
0
文件: todo_test.go 项目: elos/elos
// --- `elos todo today` {{{
func TestTodoToday(t *testing.T) {
	ui, db, user, c := newMockTodoCommand(t)

	// load a task into the db
	tsk := newTestTask(t, db, user)
	taskName := "Take out the trash"
	tsk.Name = taskName
	task.StopAndComplete(tsk)
	if err := db.Save(tsk); err != nil {
		t.Fatal(err)
	}

	tsk2 := newTestTask(t, db, user)
	task2Name := "shouldn't show up"
	tsk2.Name = task2Name
	tsk2.CompletedAt = models.TimestampFrom(time.Now().Add(-48 * time.Hour))
	if err := db.Save(tsk2); err != nil {
		t.Fatal(err)
	}

	t.Log("running: `elos todo today`")
	code := c.Run([]string{"today"})
	t.Log("command 'today' terminated")

	errput := ui.ErrorWriter.String()
	output := ui.OutputWriter.String()
	t.Logf("Error output:\n %s", errput)
	t.Logf("Output:\n %s", output)

	// verify there were no errors
	if errput != "" {
		t.Fatalf("Expected no error output, got: %s", errput)
	}

	// verify success
	if code != success {
		t.Fatalf("Expected successful exit code along with empty error output.")
	}

	// verify some of the output
	if !strings.Contains(output, taskName) {
		t.Fatalf("Output should have contained a task we completed today: %s", taskName)
	}

	if strings.Contains(output, task2Name) {
		t.Fatalf("Output should not have contained: '%s', the name of a task completed 2 days ago", task2Name)
	}
}
示例#2
0
文件: todo.go 项目: elos/elos
// runComplete executes the "elos todo complete" command.
//
// Complete first prints a numbered list of the user's tasks.
// Then it prompts the user for which number task to complete.
// The user's tasks list (c.tasks) only contains incomplete tasks.
// If the task is in progress, it is also stopped. Finally, the task is
// removed from the c.tasks.
func (c *TodoCommand) runComplete() int {
	tsk, index := c.promptSelectTask()
	if index < 0 {
		return failure
	}

	task.StopAndComplete(tsk)

	err := c.DB.Save(tsk)
	if err != nil {
		c.errorf("(subcommand complete) Error: %s", err)
		return failure
	}

	// remove the tasks from the list becuase it is now complete
	c.removeTask(index)

	c.UI.Info(fmt.Sprintf("Completed '%s'", tsk.Name))
	c.UI.Info(fmt.Sprintf("Worked for %s total", task.TimeSpent(tsk)))

	return success
}