aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/tests.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-08-25 11:53:14 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-08-25 11:55:47 -0700
commitfebce4f2e3a86da4171783fcc593b25a807c3da8 (patch)
tree3e15ba526680fda44620bc81a49f2d844a77a087 /tests/tests.go
parentdf2bebaf3dc9ab46c03883d795ae6637faa4a2c1 (diff)
Split integration tests into multiple files
Diffstat (limited to 'tests/tests.go')
-rw-r--r--tests/tests.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/tests.go b/tests/tests.go
new file mode 100644
index 0000000..8183327
--- /dev/null
+++ b/tests/tests.go
@@ -0,0 +1,68 @@
+// 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.
+
+package tests
+
+import (
+ "math/rand"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+
+ miniflux "miniflux.app/client"
+)
+
+const (
+ testBaseURL = "http://127.0.0.1:8080/"
+ testAdminUsername = "admin"
+ testAdminPassword = "test123"
+ testStandardPassword = "secret"
+ testFeedURL = "https://github.com/miniflux/miniflux/commits/master.atom"
+ testFeedTitle = "Recent Commits to miniflux:master"
+ testWebsiteURL = "https://github.com/miniflux/miniflux/commits/master"
+)
+
+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)
+ }
+
+ feedID, err := client.CreateFeed(testFeedURL, categories[0].ID)
+ 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]
+}