tests.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. //go:build integration
  4. // +build integration
  5. package tests
  6. import (
  7. "fmt"
  8. "math"
  9. "math/rand"
  10. "testing"
  11. miniflux "miniflux.app/v2/client"
  12. )
  13. const (
  14. testBaseURL = "http://127.0.0.1:8080/"
  15. testAdminUsername = "admin"
  16. testAdminPassword = "test123"
  17. testStandardPassword = "secret"
  18. testFeedURL = "https://miniflux.app/feed.xml"
  19. testFeedTitle = "Miniflux"
  20. testSubscriptionTitle = "Miniflux Releases"
  21. testWebsiteURL = "https://miniflux.app"
  22. )
  23. func getRandomUsername() string {
  24. return fmt.Sprintf("user%10d", rand.Intn(math.MaxInt64))
  25. }
  26. func createClient(t *testing.T) *miniflux.Client {
  27. username := getRandomUsername()
  28. client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
  29. _, err := client.CreateUser(username, testStandardPassword, false)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. return miniflux.New(testBaseURL, username, testStandardPassword)
  34. }
  35. func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflux.Category) {
  36. categories, err := client.Categories()
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
  41. FeedURL: testFeedURL,
  42. CategoryID: categories[0].ID,
  43. })
  44. if err != nil {
  45. t.Fatal(err)
  46. }
  47. if feedID == 0 {
  48. t.Fatalf(`Invalid feed ID, got %q`, feedID)
  49. }
  50. feed, err := client.Feed(feedID)
  51. if err != nil {
  52. t.Fatal(err)
  53. }
  54. return feed, categories[0]
  55. }