Add integration test for export API endpoint
This commit is contained in:
parent
4aec2453f4
commit
631e0a2e20
5 changed files with 62 additions and 9 deletions
2
Gopkg.lock
generated
2
Gopkg.lock
generated
|
@ -41,7 +41,7 @@
|
|||
branch = "master"
|
||||
name = "github.com/miniflux/miniflux-go"
|
||||
packages = ["."]
|
||||
revision = "3d654932d84b6afdbd5e66b34b08392f62229e61"
|
||||
revision = "887ba3b062946784f0e64edb1734f435beb204f9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/tdewolff/minify"
|
||||
|
|
|
@ -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) {
|
||||
username := getRandomUsername()
|
||||
client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword)
|
||||
|
|
15
vendor/github.com/miniflux/miniflux-go/README.md
generated
vendored
15
vendor/github.com/miniflux/miniflux-go/README.md
generated
vendored
|
@ -40,6 +40,21 @@ func main() {
|
|||
return
|
||||
}
|
||||
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!")
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
|
|
17
vendor/github.com/miniflux/miniflux-go/client.go
generated
vendored
17
vendor/github.com/miniflux/miniflux-go/client.go
generated
vendored
|
@ -7,6 +7,7 @@ package miniflux
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -213,6 +214,22 @@ func (c *Client) Feeds() (Feeds, error) {
|
|||
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.
|
||||
func (c *Client) Feed(feedID int64) (*Feed, error) {
|
||||
body, err := c.request.Get(fmt.Sprintf("/v1/feeds/%d", feedID))
|
||||
|
|
18
vendor/github.com/miniflux/miniflux-go/miniflux.go
generated
vendored
18
vendor/github.com/miniflux/miniflux-go/miniflux.go
generated
vendored
|
@ -18,14 +18,16 @@ const (
|
|||
|
||||
// User represents a user in the system.
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password,omitempty"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
Theme string `json:"theme"`
|
||||
Language string `json:"language"`
|
||||
Timezone string `json:"timezone"`
|
||||
LastLoginAt *time.Time `json:"last_login_at"`
|
||||
ID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password,omitempty"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
Theme string `json:"theme"`
|
||||
Language string `json:"language"`
|
||||
Timezone string `json:"timezone"`
|
||||
EntryDirection string `json:"entry_sorting_direction"`
|
||||
LastLoginAt *time.Time `json:"last_login_at"`
|
||||
Extra map[string]string `json:"extra"`
|
||||
}
|
||||
|
||||
func (u User) String() string {
|
||||
|
|
Loading…
Reference in a new issue