X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/48d7bce28b18ecef4c52c98821675605464cecb9..f5c601f1801aaa276f8c335fcb51c373edc0b50c:/whatsapp_test.go diff --git a/whatsapp_test.go b/whatsapp_test.go index f098c90..9ed4105 100644 --- a/whatsapp_test.go +++ b/whatsapp_test.go @@ -2,6 +2,7 @@ package main import ( "errors" + "log/slog" "os" "path/filepath" "strings" @@ -249,12 +250,12 @@ func TestWhatsAppLongFirstConnectionOutageGivesOneNotice(t *testing.T) { since := time.Now().Format(whatsappTimeLayout) - time.Sleep(whatsappNoticeDelay) + time.Sleep(whatsappOutageNoticeDelay) synctest.Wait() require.Equal(t, 1, test.events.Count("notice")) require.Equal(t, "WhatsApp is disconnected since "+since+". OneChat tries again.", test.events.Last("notice")) - time.Sleep(whatsappNoticeDelay) + time.Sleep(whatsappOutageNoticeDelay) synctest.Wait() require.Equal(t, 1, test.events.Count("notice")) test.fake.mutex.Lock() @@ -613,18 +614,18 @@ func TestWhatsAppLongDisconnectionGivesOneNotice(t *testing.T) { require.True(t, test.fake.Emit(&events.Connected{})) require.True(t, test.fake.Emit(&events.Disconnected{})) require.True(t, test.fake.Emit(&events.Connected{})) - time.Sleep(whatsappNoticeDelay + time.Second) + time.Sleep(whatsappOutageNoticeDelay + time.Second) synctest.Wait() require.Zero(t, test.events.Count("notice")) require.True(t, test.fake.Emit(&events.Disconnected{})) require.True(t, test.fake.Emit(&events.Disconnected{})) - time.Sleep(whatsappNoticeDelay) + time.Sleep(whatsappOutageNoticeDelay) synctest.Wait() require.Equal(t, 1, test.events.Count("notice")) require.Contains(t, test.events.Last("notice"), "OneChat tries again.") require.True(t, test.fake.Emit(&events.Disconnected{})) - time.Sleep(whatsappNoticeDelay) + time.Sleep(whatsappOutageNoticeDelay) synctest.Wait() require.Equal(t, 1, test.events.Count("notice")) @@ -753,3 +754,8 @@ func TestSubagentHasNoWhatsAppTools(t *testing.T) { require.Equal(t, `error: unknown tool "whatsapp_find"`, box.run(t.Context(), "whatsapp_find", `{"name":"ana"}`)) require.Equal(t, `error: unknown tool "whatsapp_send"`, box.run(t.Context(), "whatsapp_send", `{"id":"a","chat":"15550002222@s.whatsapp.net","text":"hi"}`)) } + +// whatsappDiscardLog is a logger for a WhatsApp whose log a test does not read. +func whatsappDiscardLog() *slog.Logger { + return slog.New(slog.DiscardHandler) +}