1
0
Fork 0

Add integration test for export API endpoint

This commit is contained in:
Frédéric Guillot 2018-01-12 18:16:51 -08:00
parent 4aec2453f4
commit 631e0a2e20
5 changed files with 62 additions and 9 deletions

2
Gopkg.lock generated
View file

@ -41,7 +41,7 @@
branch = "master" branch = "master"
name = "github.com/miniflux/miniflux-go" name = "github.com/miniflux/miniflux-go"
packages = ["."] packages = ["."]
revision = "3d654932d84b6afdbd5e66b34b08392f62229e61" revision = "887ba3b062946784f0e64edb1734f435beb204f9"
[[projects]] [[projects]]
name = "github.com/tdewolff/minify" name = "github.com/tdewolff/minify"

View file

@ -634,6 +634,25 @@ func TestCreateFeedWithInexistingCategory(t *testing.T) {
} }
} }
func TestExport(t *testing.T) {
username := getRandomUsername()
client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
_, err := client.CreateUser(username, testStandardPassword, false)
if err != nil {
t.Fatal(err)
}
client = miniflux.NewClient(testBaseURL, username, testStandardPassword)
output, err := client.Export()
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(string(output), "<?xml") {
t.Fatalf(`Invalid OPML export, got "%s"`, string(output))
}
}
func TestUpdateFeed(t *testing.T) { func TestUpdateFeed(t *testing.T) {
username := getRandomUsername() username := getRandomUsername()
client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword) client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)

View file

@ -40,6 +40,21 @@ func main() {
return return
} }
fmt.Println(feeds) fmt.Println(feeds)
// Backup to opml file.
opml, err := client.Export()
if err != nil {
fmt.Println(err)
return
}
err = ioutil.WriteFile("opml.xml", opml, 0644)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("backup done!")
} }
``` ```

View file

@ -7,6 +7,7 @@ package miniflux
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"strconv" "strconv"
) )
@ -213,6 +214,22 @@ func (c *Client) Feeds() (Feeds, error) {
return feeds, nil return feeds, nil
} }
// Export creates OPML file.
func (c *Client) Export() ([]byte, error) {
body, err := c.request.Get("/v1/export")
if err != nil {
return nil, err
}
defer body.Close()
opml, err := ioutil.ReadAll(body)
if err != nil {
return nil, err
}
return opml, nil
}
// Feed gets a feed. // Feed gets a feed.
func (c *Client) Feed(feedID int64) (*Feed, error) { func (c *Client) Feed(feedID int64) (*Feed, error) {
body, err := c.request.Get(fmt.Sprintf("/v1/feeds/%d", feedID)) body, err := c.request.Get(fmt.Sprintf("/v1/feeds/%d", feedID))

View file

@ -25,7 +25,9 @@ type User struct {
Theme string `json:"theme"` Theme string `json:"theme"`
Language string `json:"language"` Language string `json:"language"`
Timezone string `json:"timezone"` Timezone string `json:"timezone"`
EntryDirection string `json:"entry_sorting_direction"`
LastLoginAt *time.Time `json:"last_login_at"` LastLoginAt *time.Time `json:"last_login_at"`
Extra map[string]string `json:"extra"`
} }
func (u User) String() string { func (u User) String() string {