]> git.giacomolli.uk - onechat/blobdiff - daemon_test.go
Log each change of the WhatsApp connection
[onechat] / daemon_test.go
index 4b0ba0a1238a6c4850dd6216825863e82836cec3..9f457927124674c505a377fdc6b264c1630be245 100644 (file)
@@ -36,6 +36,8 @@ func TestClientsSeeTheTurnAsItHappens(t *testing.T) {
 
        first.Type(stopCommand)
        first.WaitFor(t, "[error] no turn runs")
+       first.Type(stopCommand + " BlueFox")
+       first.WaitFor(t, "[error] no subagent BlueFox runs")
        require.NotContains(t, second.Output(), "no turn runs")
        require.NoError(t, first.Close())
 }
@@ -96,6 +98,35 @@ func TestDaemonWritesNoFileForALongSocketPath(t *testing.T) {
        require.Empty(t, entries)
 }
 
+func TestDaemonLogHasATimeStampOnlyOutsideTheJournal(t *testing.T) {
+       testCases := []struct {
+               name    string
+               journal string
+               line    string
+       }{
+               {
+                       name:    "the journal adds the time itself",
+                       journal: "8:12345",
+                       line:    `^onechat: the agent is ready\n$`,
+               },
+               {
+                       name:    "a terminal gets the time in the line",
+                       journal: "",
+                       line:    `^onechat: \d{4}/\d\d/\d\d \d\d:\d\d:\d\d the agent is ready\n$`,
+               },
+       }
+
+       for _, tc := range testCases {
+               t.Run(tc.name, func(t *testing.T) {
+                       t.Setenv("JOURNAL_STREAM", tc.journal)
+
+                       var out strings.Builder
+                       daemonLogger(&out, "onechat: ").Print("the agent is ready")
+                       require.Regexp(t, tc.line, out.String())
+               })
+       }
+}
+
 // daemonStartTest serves a new agent on a socket in a temporary directory and
 // returns the socket path. The commands of the agent run in a temporary
 // directory.