tests.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // +build integration
  5. package tests
  6. import (
  7. "math/rand"
  8. "strconv"
  9. "strings"
  10. "testing"
  11. "time"
  12. miniflux "miniflux.app/client"
  13. )
  14. const (
  15. testBaseURL = "http://127.0.0.1:8080/"
  16. testAdminUsername = "admin"
  17. testAdminPassword = "test123"
  18. testStandardPassword = "secret"
  19. testFeedURL = "https://miniflux.app/feed.xml"
  20. testFeedTitle = "Miniflux"
  21. testSubscriptionTitle = "Miniflux Releases"
  22. testWebsiteURL = "https://miniflux.app/"
  23. )
  24. func getRandomUsername() string {
  25. rand.Seed(time.Now().UnixNano())
  26. var suffix []string
  27. for i := 0; i < 10; i++ {
  28. suffix = append(suffix, strconv.Itoa(rand.Intn(1000)))
  29. }
  30. return "user" + strings.Join(suffix, "")
  31. }
  32. func createClient(t *testing.T) *miniflux.Client {
  33. username := getRandomUsername()
  34. client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
  35. _, err := client.CreateUser(username, testStandardPassword, false)
  36. if err != nil {
  37. t.Fatal(err)
  38. }
  39. return miniflux.New(testBaseURL, username, testStandardPassword)
  40. }
  41. func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflux.Category) {
  42. categories, err := client.Categories()
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
  47. FeedURL: testFeedURL,
  48. CategoryID: categories[0].ID,
  49. })
  50. if err != nil {
  51. t.Fatal(err)
  52. }
  53. if feedID == 0 {
  54. t.Fatalf(`Invalid feed ID, got %q`, feedID)
  55. }
  56. feed, err := client.Feed(feedID)
  57. if err != nil {
  58. t.Fatal(err)
  59. }
  60. return feed, categories[0]
  61. }