]> git.giacomolli.uk - onechat/blobdiff - schedule_test.go
Test the commit message wrapping boundaries
[onechat] / schedule_test.go
index 5743a22bb3fdae5fd18289a348a58b0ead9fb4cd..f93427e0fedae4661b5ed7e85b00da0ca9591b5a 100644 (file)
@@ -23,14 +23,14 @@ func TestSchedulesSet(t *testing.T) {
                listed string
        }{
                {
                listed string
        }{
                {
-                       name:   "a one-time schedule at a local time",
+                       name:   "sets a one-time run at its local time",
                        text:   "Remind the user to drink water.",
                        at:     new("2026-11-09 09:00"),
                        answer: "Schedule 1 set. Next: Monday 2026-11-09 09:00 -03:00.",
                        listed: "1 | Monday 2026-11-09 09:00 -03:00 | once | Remind the user to drink water.",
                },
                {
                        text:   "Remind the user to drink water.",
                        at:     new("2026-11-09 09:00"),
                        answer: "Schedule 1 set. Next: Monday 2026-11-09 09:00 -03:00.",
                        listed: "1 | Monday 2026-11-09 09:00 -03:00 | once | Remind the user to drink water.",
                },
                {
-                       name:   "a repeating schedule at the next match",
+                       name:   "sets a repeating run at its next match",
                        text:   "Tell the user\nthe time.",
                        cron:   new("*/5  * * * *"),
                        answer: "Schedule 1 set. Next: Sunday 2026-11-08 20:05 -03:00.",
                        text:   "Tell the user\nthe time.",
                        cron:   new("*/5  * * * *"),
                        answer: "Schedule 1 set. Next: Sunday 2026-11-08 20:05 -03:00.",
@@ -59,43 +59,43 @@ func TestSchedulesSetRefuses(t *testing.T) {
                message string
        }{
                {
                message string
        }{
                {
-                       name:    "an empty text",
+                       name:    "refuses an empty text",
                        text:    " \n",
                        at:      new("2026-11-09 09:00"),
                        message: "the text must have 1 to 4096 bytes",
                },
                {
                        text:    " \n",
                        at:      new("2026-11-09 09:00"),
                        message: "the text must have 1 to 4096 bytes",
                },
                {
-                       name:    "a text that is too long",
+                       name:    "refuses a text that is too long",
                        text:    strings.Repeat("x", scheduleTextBytes+1),
                        at:      new("2026-11-09 09:00"),
                        message: "the text must have 1 to 4096 bytes",
                },
                {
                        text:    strings.Repeat("x", scheduleTextBytes+1),
                        at:      new("2026-11-09 09:00"),
                        message: "the text must have 1 to 4096 bytes",
                },
                {
-                       name:    "neither at nor cron",
+                       name:    "refuses neither at nor cron",
                        text:    "Tell the user the time.",
                        message: "give either at or cron, and null for the other",
                },
                {
                        text:    "Tell the user the time.",
                        message: "give either at or cron, and null for the other",
                },
                {
-                       name:    "both at and cron",
+                       name:    "refuses both at and cron",
                        text:    "Tell the user the time.",
                        at:      new("2026-11-09 09:00"),
                        cron:    new("0 9 * * *"),
                        message: "give either at or cron, and null for the other",
                },
                {
                        text:    "Tell the user the time.",
                        at:      new("2026-11-09 09:00"),
                        cron:    new("0 9 * * *"),
                        message: "give either at or cron, and null for the other",
                },
                {
-                       name:    "a time in another layout",
+                       name:    "refuses a time in another layout",
                        text:    "Tell the user the time.",
                        at:      new("2026-11-09T09:00:00-03:00"),
                        message: "at must be a local time such as 2026-11-08 20:00",
                },
                {
                        text:    "Tell the user the time.",
                        at:      new("2026-11-09T09:00:00-03:00"),
                        message: "at must be a local time such as 2026-11-08 20:00",
                },
                {
-                       name:    "a time that is past",
+                       name:    "refuses a time that is past",
                        text:    "Tell the user the time.",
                        at:      new("2026-11-08 20:00"),
                        message: "the time Sunday 2026-11-08 20:00 -03:00 is not after now, Sunday 2026-11-08 20:00 -03:00",
                },
                {
                        text:    "Tell the user the time.",
                        at:      new("2026-11-08 20:00"),
                        message: "the time Sunday 2026-11-08 20:00 -03:00 is not after now, Sunday 2026-11-08 20:00 -03:00",
                },
                {
-                       name:    "runs less than 5 minutes apart",
+                       name:    "refuses runs less than 5 minutes apart",
                        text:    "Tell the user the time.",
                        cron:    new("* * * * *"),
                        message: "at least 5 minutes apart",
                        text:    "Tell the user the time.",
                        cron:    new("* * * * *"),
                        message: "at least 5 minutes apart",
@@ -199,7 +199,7 @@ func TestScheduleMessage(t *testing.T) {
                message  string
        }{
                {
                message  string
        }{
                {
-                       name: "a one-time run on time",
+                       name: "labels an on-time run as once",
                        schedule: Schedule{
                                ID:   3,
                                Text: "Remind the user to drink water.",
                        schedule: Schedule{
                                ID:   3,
                                Text: "Remind the user to drink water.",
@@ -209,7 +209,7 @@ func TestScheduleMessage(t *testing.T) {
                        message: "[Schedule 3] Monday 2026-11-09 09:00 -03:00, once\nRemind the user to drink water.\n" + scheduleEmptyReply,
                },
                {
                        message: "[Schedule 3] Monday 2026-11-09 09:00 -03:00, once\nRemind the user to drink water.\n" + scheduleEmptyReply,
                },
                {
-                       name: "a late repeating run",
+                       name: "marks a late run with its repeating expression",
                        schedule: Schedule{
                                ID:   4,
                                Text: "Tell the user the news.",
                        schedule: Schedule{
                                ID:   4,
                                Text: "Tell the user the news.",
@@ -287,6 +287,7 @@ func TestSchedulesRunMissedSchedulesOnceAtTheStart(t *testing.T) {
                "[Schedule 1] Sunday 2026-11-08 09:00 -03:00, once\nRemind the user to call.\n" + scheduleLateLine + "\n" + scheduleEmptyReply,
                "[Schedule 2] Sunday 2026-11-08 10:00 -03:00, repeats 0 * * * *\nTell the user the time.\n" + scheduleLateLine + "\n" + scheduleEmptyReply,
        }, texts[len(texts)-2:])
                "[Schedule 1] Sunday 2026-11-08 09:00 -03:00, once\nRemind the user to call.\n" + scheduleLateLine + "\n" + scheduleEmptyReply,
                "[Schedule 2] Sunday 2026-11-08 10:00 -03:00, repeats 0 * * * *\nTell the user the time.\n" + scheduleLateLine + "\n" + scheduleEmptyReply,
        }, texts[len(texts)-2:])
+
        require.Equal(t, "2 | Sunday 2026-11-08 21:00 -03:00 | 0 * * * * | Tell the user the time.", schedules.List())
        require.Equal(t, "<6>schedule ran id=1 late=11h30m0s\n<6>schedule ran id=2 late=10h30m0s\n", logs.String())
 }
        require.Equal(t, "2 | Sunday 2026-11-08 21:00 -03:00 | 0 * * * * | Tell the user the time.", schedules.List())
        require.Equal(t, "<6>schedule ran id=1 late=11h30m0s\n<6>schedule ran id=2 late=10h30m0s\n", logs.String())
 }
@@ -336,7 +337,7 @@ func TestSchedulesCheckTheClockAfterItsWaitLimit(t *testing.T) {
                synctest.Wait()
                require.Zero(t, loop.memory.Len())
                clock.Set(clock.Now().Add(5 * time.Minute))
                synctest.Wait()
                require.Zero(t, loop.memory.Len())
                clock.Set(clock.Now().Add(5 * time.Minute))
-               time.Sleep(scheduleCheck)
+               time.Sleep(scheduleClockWaitTimeout)
                synctest.Wait()
                require.Equal(t, 1, loop.memory.Len())
                require.Contains(t, events.Last("work"), "Check the clock.")
                synctest.Wait()
                require.Equal(t, 1, loop.memory.Len())
                require.Contains(t, events.Last("work"), "Check the clock.")