Ejemplo n.º 1
0
func TestNextRunTime(t *testing.T) {

	for _, testCase := range TestCases {
		/*
		 * Set up
		 */
		var job *Job = NewJob("JobA", "blah", "dude")
		timeSpec, _ := parseFullTimeSpec(testCase.timeSpec)
		job.FullTimeSpec = *timeSpec

		var now time.Time = testCase.startTime
		for _, expRunTime := range testCase.expRunTimes {
			fmt.Printf("time spec: %v\n", testCase.timeSpec)
			fmt.Printf("now: %v\n", TimeString(now))

			/*
			 * Call
			 */
			var actualRunTime *time.Time = nextRunTime(job, now)

			/*
			 * Test
			 */
			require.NotNil(t, actualRunTime)
			msg := fmt.Sprintf("%v != %v",
				TimeString(expRunTime),
				TimeString(*actualRunTime))
			require.Equal(t, expRunTime, *actualRunTime, msg)

			now = actualRunTime.Add(time.Second)
		}
	}
}
Ejemplo n.º 2
0
func TestReadNewJobberFile(t *testing.T) {
	/*
	 * Set up
	 */
	buf := bytes.NewBufferString(NewJobFileEx)

	/*
	 * Call
	 */
	var file *JobberFile
	file, err := readJobberFile(buf, UsernameEx)

	/*
	 * Test
	 */
	if err != nil {
		t.Fatalf("Got error: %v", err)
	}
	if file == nil {
		t.Fatalf("jobs == nil")
	}

	// test prefs
	require.NotNil(t, file.Prefs.Notifier)

	// test jobs
	require.Equal(t, 2, len(file.Jobs))

	// test DailyBackup
	daily := file.Jobs[0]
	require.Equal(t, "DailyBackup", daily.Name)
	require.Equal(t, "backup daily", daily.Cmd)
	require.Equal(t, &ErrorHandlerStop, daily.ErrorHandler)
	require.Equal(t, false, daily.NotifyOnError)
	require.Equal(t, true, daily.NotifyOnFailure)

	// test WeeklyBackup
	weekly := file.Jobs[1]
	require.Equal(t, "WeeklyBackup", weekly.Name)
	require.Equal(t, `multi-
line
script
`, weekly.Cmd)
	require.Equal(t, &ErrorHandlerBackoff, weekly.ErrorHandler)
	require.Equal(t, true, weekly.NotifyOnError)
	require.Equal(t, false, weekly.NotifyOnFailure)
}