tests.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. //go:build integration
  5. // +build integration
  6. package tests
  7. import (
  8. "math/rand"
  9. "strconv"
  10. "strings"
  11. "testing"
  12. "time"
  13. miniflux "miniflux.app/client"
  14. )
  15. const (
  16. testBaseURL = "http://127.0.0.1:8080/"
  17. testAdminUsername = "admin"
  18. testAdminPassword = "test123"
  19. testStandardPassword = "secret"
  20. testFeedURL = "https://miniflux.app/feed.xml"
  21. testFeedTitle = "Miniflux"
  22. testSubscriptionTitle = "Miniflux Releases"
  23. testWebsiteURL = "https://miniflux.app/"
  24. )
  25. func getRandomUsername() string {
  26. rand.Seed(time.Now().UnixNano())
  27. var suffix []string
  28. for i := 0; i < 10; i++ {
  29. suffix = append(suffix, strconv.Itoa(rand.Intn(1000)))
  30. }
  31. return "user" + strings.Join(suffix, "")
  32. }
  33. func createClient(t *testing.T) *miniflux.Client {
  34. username := getRandomUsername()
  35. client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
  36. _, err := client.CreateUser(username, testStandardPassword, false)
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. return miniflux.New(testBaseURL, username, testStandardPassword)
  41. }
  42. func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflux.Category) {
  43. categories, err := client.Categories()
  44. if err != nil {
  45. t.Fatal(err)
  46. }
  47. feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
  48. FeedURL: testFeedURL,
  49. CategoryID: categories[0].ID,
  50. })
  51. if err != nil {
  52. t.Fatal(err)
  53. }
  54. if feedID == 0 {
  55. t.Fatalf(`Invalid feed ID, got %q`, feedID)
  56. }
  57. feed, err := client.Feed(feedID)
  58. if err != nil {
  59. t.Fatal(err)
  60. }
  61. return feed, categories[0]
  62. }