integration_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package integration
  4. import (
  5. "bytes"
  6. "log/slog"
  7. "strings"
  8. "testing"
  9. "miniflux.app/v2/internal/model"
  10. )
  11. func TestSendEntryLogsLinkwardenCollectionID(t *testing.T) {
  12. var buf bytes.Buffer
  13. handler := slog.NewJSONHandler(&buf, nil)
  14. logger := slog.New(handler)
  15. prev := slog.Default()
  16. slog.SetDefault(logger)
  17. defer slog.SetDefault(prev)
  18. entry := &model.Entry{ID: 52, URL: "https://example.org/test.html", Title: "Test"}
  19. coll := int64(12345)
  20. userIntegrations := &model.Integration{
  21. UserID: 1,
  22. LinkwardenEnabled: true,
  23. LinkwardenCollectionID: &coll,
  24. LinkwardenURL: "",
  25. LinkwardenAPIKey: "",
  26. }
  27. SendEntry(entry, userIntegrations)
  28. out := buf.String()
  29. if !strings.Contains(out, `"collection_id":12345`) {
  30. t.Fatalf("expected collection_id in logs; got: %s", out)
  31. }
  32. }
  33. func TestSendEntryLogsLinkwardenWithoutCollectionID(t *testing.T) {
  34. var buf bytes.Buffer
  35. handler := slog.NewJSONHandler(&buf, nil)
  36. logger := slog.New(handler)
  37. prev := slog.Default()
  38. slog.SetDefault(logger)
  39. defer slog.SetDefault(prev)
  40. entry := &model.Entry{ID: 52, URL: "https://example.org/test.html", Title: "Test"}
  41. userIntegrations := &model.Integration{
  42. UserID: 1,
  43. LinkwardenEnabled: true,
  44. LinkwardenURL: "",
  45. LinkwardenAPIKey: "",
  46. }
  47. SendEntry(entry, userIntegrations)
  48. out := buf.String()
  49. if strings.Contains(out, "collection_id") {
  50. t.Fatalf("did not expect collection_id in logs; got: %s", out)
  51. }
  52. }