2018-08-25 14:53:14 -04:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-03-23 00:04:10 -04:00
|
|
|
// +build integration
|
|
|
|
|
2018-08-25 14:53:14 -04:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
miniflux "miniflux.app/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-11-18 01:53:11 -05:00
|
|
|
testBaseURL = "http://127.0.0.1:8080/"
|
|
|
|
testAdminUsername = "admin"
|
|
|
|
testAdminPassword = "test123"
|
|
|
|
testStandardPassword = "secret"
|
|
|
|
testFeedURL = "https://miniflux.app/feed.xml"
|
|
|
|
testFeedTitle = "Miniflux"
|
|
|
|
testSubscriptionTitle = "Miniflux Releases"
|
|
|
|
testWebsiteURL = "https://miniflux.app/"
|
2018-08-25 14:53:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func getRandomUsername() string {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
var suffix []string
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
suffix = append(suffix, strconv.Itoa(rand.Intn(1000)))
|
|
|
|
}
|
|
|
|
return "user" + strings.Join(suffix, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func createClient(t *testing.T) *miniflux.Client {
|
|
|
|
username := getRandomUsername()
|
|
|
|
client := miniflux.New(testBaseURL, testAdminUsername, testAdminPassword)
|
|
|
|
_, err := client.CreateUser(username, testStandardPassword, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return miniflux.New(testBaseURL, username, testStandardPassword)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflux.Category) {
|
|
|
|
categories, err := client.Categories()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-01-02 19:33:41 -05:00
|
|
|
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
|
|
|
|
FeedURL: testFeedURL,
|
|
|
|
CategoryID: categories[0].ID,
|
|
|
|
})
|
2018-08-25 14:53:14 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if feedID == 0 {
|
|
|
|
t.Fatalf(`Invalid feed ID, got %q`, feedID)
|
|
|
|
}
|
|
|
|
|
|
|
|
feed, err := client.Feed(feedID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return feed, categories[0]
|
|
|
|
}
|