rename remote to rpc
This commit is contained in:
+20
-20
@@ -26,9 +26,9 @@ import (
|
||||
|
||||
"github.com/umputun/remark/backend/app/migrator"
|
||||
"github.com/umputun/remark/backend/app/notify"
|
||||
"github.com/umputun/remark/backend/app/remote"
|
||||
"github.com/umputun/remark/backend/app/rest/api"
|
||||
"github.com/umputun/remark/backend/app/rest/proxy"
|
||||
"github.com/umputun/remark/backend/app/rpc"
|
||||
"github.com/umputun/remark/backend/app/store"
|
||||
"github.com/umputun/remark/backend/app/store/admin"
|
||||
"github.com/umputun/remark/backend/app/store/engine"
|
||||
@@ -88,12 +88,12 @@ type AuthGroup struct {
|
||||
|
||||
// StoreGroup defines options group for store params
|
||||
type StoreGroup struct {
|
||||
Type string `long:"type" env:"TYPE" description:"type of storage" choice:"bolt" choice:"remote" default:"bolt"`
|
||||
Type string `long:"type" env:"TYPE" description:"type of storage" choice:"bolt" choice:"rpc" default:"bolt"`
|
||||
Bolt struct {
|
||||
Path string `long:"path" env:"PATH" default:"./var" description:"parent dir for bolt files"`
|
||||
Timeout time.Duration `long:"timeout" env:"TIMEOUT" default:"30s" description:"bolt timeout"`
|
||||
} `group:"bolt" namespace:"bolt" env-namespace:"BOLT"`
|
||||
Remote RemoteGroup `group:"remote" namespace:"remote" env-namespace:"REMOTE"`
|
||||
RPC RPCGroup `group:"rpc" namespace:"rpc" env-namespace:"TPC"`
|
||||
}
|
||||
|
||||
// ImageGroup defines options group for store pictures
|
||||
@@ -136,12 +136,12 @@ type CacheGroup struct {
|
||||
|
||||
// AdminGroup defines options group for admin params
|
||||
type AdminGroup struct {
|
||||
Type string `long:"type" env:"TYPE" description:"type of admin store" choice:"shared" choice:"remote" default:"shared"`
|
||||
Type string `long:"type" env:"TYPE" description:"type of admin store" choice:"shared" choice:"rpc" default:"shared"`
|
||||
Shared struct {
|
||||
Admins []string `long:"id" env:"ID" description:"admin(s) ids" env-delim:","`
|
||||
Email string `long:"email" env:"EMAIL" default:"" description:"admin email"`
|
||||
} `group:"shared" namespace:"shared" env-namespace:"SHARED"`
|
||||
Remote RemoteGroup `group:"remote" namespace:"remote" env-namespace:"REMOTE"`
|
||||
RPC RPCGroup `group:"rpc" namespace:"rpc" env-namespace:"RPC"`
|
||||
}
|
||||
|
||||
// NotifyGroup defines options for notification
|
||||
@@ -173,9 +173,9 @@ type StreamGroup struct {
|
||||
MaxActive int `long:"max" env:"MAX" default:"500" description:"max number of parallel streams"`
|
||||
}
|
||||
|
||||
// RemoteGroup defines options for remote modules (plugins)
|
||||
type RemoteGroup struct {
|
||||
API string `long:"api" env:"API" description:"remote extension api url"`
|
||||
// RPCGroup defines options for remote modules (plugins)
|
||||
type RPCGroup struct {
|
||||
API string `long:"api" env:"API" description:"rpc extension api url"`
|
||||
TimeOut time.Duration `long:"timeout" env:"TIMEOUT" default:"5s" description:"http timeout"`
|
||||
AuthUser string `long:"auth_user" env:"AUTH_USER" description:"basic auth user name"`
|
||||
AuthPassword string `long:"auth_passwd" env:"AUTH_PASSWD" description:"basic auth user password"`
|
||||
@@ -417,12 +417,12 @@ func (s *ServerCommand) makeDataStore() (result engine.Interface, err error) {
|
||||
sites = append(sites, engine.BoltSite{SiteID: site, FileName: fmt.Sprintf("%s/%s.db", s.Store.Bolt.Path, site)})
|
||||
}
|
||||
result, err = engine.NewBoltDB(bolt.Options{Timeout: s.Store.Bolt.Timeout}, sites...)
|
||||
case "remote":
|
||||
r := &engine.Remote{Client: remote.Client{
|
||||
API: s.Store.Remote.API,
|
||||
Client: http.Client{Timeout: s.Store.Remote.TimeOut},
|
||||
AuthUser: s.Store.Remote.AuthUser,
|
||||
AuthPasswd: s.Store.Remote.AuthPassword,
|
||||
case "rpc":
|
||||
r := &engine.RPC{Client: rpc.Client{
|
||||
API: s.Store.RPC.API,
|
||||
Client: http.Client{Timeout: s.Store.RPC.TimeOut},
|
||||
AuthUser: s.Store.RPC.AuthUser,
|
||||
AuthPasswd: s.Store.RPC.AuthPassword,
|
||||
}}
|
||||
return r, nil
|
||||
default:
|
||||
@@ -482,12 +482,12 @@ func (s *ServerCommand) makeAdminStore() (admin.Store, error) {
|
||||
}
|
||||
}
|
||||
return admin.NewStaticStore(s.SharedSecret, s.Admin.Shared.Admins, s.Admin.Shared.Email), nil
|
||||
case "remote":
|
||||
r := &admin.Remote{Client: remote.Client{
|
||||
API: s.Admin.Remote.API,
|
||||
Client: http.Client{Timeout: s.Admin.Remote.TimeOut},
|
||||
AuthUser: s.Admin.Remote.AuthUser,
|
||||
AuthPasswd: s.Admin.Remote.AuthPassword,
|
||||
case "rpc":
|
||||
r := &admin.RPC{Client: rpc.Client{
|
||||
API: s.Admin.RPC.API,
|
||||
Client: http.Client{Timeout: s.Admin.RPC.TimeOut},
|
||||
AuthUser: s.Admin.RPC.AuthUser,
|
||||
AuthPasswd: s.Admin.RPC.AuthPassword,
|
||||
}}
|
||||
return r, nil
|
||||
default:
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestServerApp(t *testing.T) {
|
||||
})
|
||||
|
||||
go func() { _ = app.run(ctx) }()
|
||||
time.Sleep(100 * time.Millisecond) // let server start
|
||||
time.Sleep(250 * time.Millisecond) // let server start
|
||||
|
||||
// send ping
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/api/v1/ping", port))
|
||||
@@ -194,8 +194,8 @@ func TestServerApp_WithRemote(t *testing.T) {
|
||||
// prepare options
|
||||
p := flags.NewParser(&opts, flags.Default)
|
||||
_, err := p.ParseArgs([]string{"--admin-passwd=password", "--cache.type=none",
|
||||
"--store.type=remote", "--store.remote.api=http://127.0.0.1",
|
||||
"--port=12345", "--admin.type=remote", "--admin.remote.api=http://127.0.0.1", "--avatar.fs.path=/tmp"})
|
||||
"--store.type=rpc", "--store.rpc.api=http://127.0.0.1",
|
||||
"--port=12345", "--admin.type=rpc", "--admin.rpc.api=http://127.0.0.1", "--avatar.fs.path=/tmp"})
|
||||
require.Nil(t, err)
|
||||
opts.Auth.Github.CSEC, opts.Auth.Github.CID = "csec", "cid"
|
||||
opts.BackupLocation, opts.Image.FS.Path = "/tmp", "/tmp"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package remote
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package remote
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,8 +1,8 @@
|
||||
// Package remote implements client ans server for RPC-like communication with remote storage.
|
||||
// Package rpc implements client ans server for RPC-like communication with remote storage.
|
||||
// The protocol is somewhat simplified version of json-rpc with a single POST call sending
|
||||
// Request json (method name and the list of parameters) and receiving back json Response with "result" json
|
||||
// and error string
|
||||
package remote
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -1,4 +1,4 @@
|
||||
package remote
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package remote
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -9,16 +9,16 @@ package admin
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/umputun/remark/backend/app/remote"
|
||||
"github.com/umputun/remark/backend/app/rpc"
|
||||
)
|
||||
|
||||
// Remote implements remote engine and delegates all Calls to remote http server
|
||||
type Remote struct {
|
||||
remote.Client
|
||||
// RPC implements remote engine and delegates all Calls to remote http server
|
||||
type RPC struct {
|
||||
rpc.Client
|
||||
}
|
||||
|
||||
// Key returns the key, same for all sites
|
||||
func (r *Remote) Key() (key string, err error) {
|
||||
func (r *RPC) Key() (key string, err error) {
|
||||
resp, err := r.Call("admin.key")
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -29,7 +29,7 @@ func (r *Remote) Key() (key string, err error) {
|
||||
}
|
||||
|
||||
// Admins returns list of admin's ids for given site
|
||||
func (r *Remote) Admins(siteID string) (ids []string, err error) {
|
||||
func (r *RPC) Admins(siteID string) (ids []string, err error) {
|
||||
resp, err := r.Call("admin.admins", siteID)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
@@ -42,7 +42,7 @@ func (r *Remote) Admins(siteID string) (ids []string, err error) {
|
||||
}
|
||||
|
||||
// Email gets email address for given site
|
||||
func (r *Remote) Email(siteID string) (email string, err error) {
|
||||
func (r *RPC) Email(siteID string) (email string, err error) {
|
||||
resp, err := r.Call("admin.email", siteID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -16,14 +16,14 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/umputun/remark/backend/app/remote"
|
||||
"github.com/umputun/remark/backend/app/rpc"
|
||||
)
|
||||
|
||||
func TestRemote_Key(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"admin.key","id":1}`,
|
||||
`{"result":"12345","id":1}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
var a Store = &c
|
||||
_ = a
|
||||
@@ -38,7 +38,7 @@ func TestRemote_Admins(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"admin.admins","params":["site-1"],"id":1}`,
|
||||
`{"result":["id1","id2"],"id":1}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
var a Store = &c
|
||||
_ = a
|
||||
@@ -53,7 +53,7 @@ func TestRemote_Email(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"admin.email","params":["site-1"],"id":1}`,
|
||||
`{"result":"bbb@example.com","id":1}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
var a Store = &c
|
||||
_ = a
|
||||
|
||||
@@ -3,17 +3,17 @@ package engine
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/umputun/remark/backend/app/remote"
|
||||
"github.com/umputun/remark/backend/app/rpc"
|
||||
"github.com/umputun/remark/backend/app/store"
|
||||
)
|
||||
|
||||
// Remote implements remote engine and delegates all Calls to remote http server
|
||||
type Remote struct {
|
||||
remote.Client
|
||||
// RPC implements remote engine and delegates all Calls to remote http server
|
||||
type RPC struct {
|
||||
rpc.Client
|
||||
}
|
||||
|
||||
// Create comment and return ID
|
||||
func (r *Remote) Create(comment store.Comment) (commentID string, err error) {
|
||||
func (r *RPC) Create(comment store.Comment) (commentID string, err error) {
|
||||
|
||||
resp, err := r.Call("store.create", comment)
|
||||
if err != nil {
|
||||
@@ -25,7 +25,7 @@ func (r *Remote) Create(comment store.Comment) (commentID string, err error) {
|
||||
}
|
||||
|
||||
// Get comment by ID
|
||||
func (r *Remote) Get(req GetRequest) (comment store.Comment, err error) {
|
||||
func (r *RPC) Get(req GetRequest) (comment store.Comment, err error) {
|
||||
resp, err := r.Call("store.get", req)
|
||||
if err != nil {
|
||||
return store.Comment{}, err
|
||||
@@ -36,13 +36,13 @@ func (r *Remote) Get(req GetRequest) (comment store.Comment, err error) {
|
||||
}
|
||||
|
||||
// Update comment, mutable parts only
|
||||
func (r *Remote) Update(comment store.Comment) error {
|
||||
func (r *RPC) Update(comment store.Comment) error {
|
||||
_, err := r.Call("store.update", comment)
|
||||
return err
|
||||
}
|
||||
|
||||
// Find comments for locator
|
||||
func (r *Remote) Find(req FindRequest) (comments []store.Comment, err error) {
|
||||
func (r *RPC) Find(req FindRequest) (comments []store.Comment, err error) {
|
||||
resp, err := r.Call("store.find", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,7 +52,7 @@ func (r *Remote) Find(req FindRequest) (comments []store.Comment, err error) {
|
||||
}
|
||||
|
||||
// Info returns post(s) meta info
|
||||
func (r *Remote) Info(req InfoRequest) (info []store.PostInfo, err error) {
|
||||
func (r *RPC) Info(req InfoRequest) (info []store.PostInfo, err error) {
|
||||
resp, err := r.Call("store.info", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -62,7 +62,7 @@ func (r *Remote) Info(req InfoRequest) (info []store.PostInfo, err error) {
|
||||
}
|
||||
|
||||
// Flag sets and gets flags
|
||||
func (r *Remote) Flag(req FlagRequest) (status bool, err error) {
|
||||
func (r *RPC) Flag(req FlagRequest) (status bool, err error) {
|
||||
resp, err := r.Call("store.flag", req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -72,7 +72,7 @@ func (r *Remote) Flag(req FlagRequest) (status bool, err error) {
|
||||
}
|
||||
|
||||
// ListFlags get list of flagged keys, like blocked & verified user
|
||||
func (r *Remote) ListFlags(req FlagRequest) (list []interface{}, err error) {
|
||||
func (r *RPC) ListFlags(req FlagRequest) (list []interface{}, err error) {
|
||||
resp, err := r.Call("store.list_flags", req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -82,7 +82,7 @@ func (r *Remote) ListFlags(req FlagRequest) (list []interface{}, err error) {
|
||||
}
|
||||
|
||||
// Count gets comments count by user or site
|
||||
func (r *Remote) Count(req FindRequest) (count int, err error) {
|
||||
func (r *RPC) Count(req FindRequest) (count int, err error) {
|
||||
resp, err := r.Call("store.count", req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -92,13 +92,13 @@ func (r *Remote) Count(req FindRequest) (count int, err error) {
|
||||
}
|
||||
|
||||
// Delete post(s) by id or by userID
|
||||
func (r *Remote) Delete(req DeleteRequest) error {
|
||||
func (r *RPC) Delete(req DeleteRequest) error {
|
||||
_, err := r.Call("store.delete", req)
|
||||
return err
|
||||
}
|
||||
|
||||
// Close storage engine
|
||||
func (r *Remote) Close() error {
|
||||
func (r *RPC) Close() error {
|
||||
_, err := r.Call("store.close")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/umputun/remark/backend/app/remote"
|
||||
"github.com/umputun/remark/backend/app/rpc"
|
||||
"github.com/umputun/remark/backend/app/store"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestRemote_Create(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.create","params":{"id":"123","pid":"","text":"msg","user":{"name":"","id":"","picture":"","admin":false},"locator":{"site":"site","url":"http://example.com/url"},"score":0,"vote":0,"time":"0001-01-01T00:00:00Z"},"id":1}`,
|
||||
`{"result":"12345","id":1}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
var eng Interface = &c
|
||||
_ = eng
|
||||
@@ -35,7 +35,7 @@ func TestRemote_Create(t *testing.T) {
|
||||
func TestRemote_Get(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.get","params":{"locator":{"url":"http://example.com/url"},"comment_id":"site"},"id":1}`, `{"result":{"id":"123","pid":"","text":"msg","delete":true}}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
req := GetRequest{Locator: store.Locator{URL: "http://example.com/url"}, CommentID: "site"}
|
||||
res, err := c.Get(req)
|
||||
@@ -47,7 +47,7 @@ func TestRemote_Get(t *testing.T) {
|
||||
func TestRemote_GetWithErrorResult(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.get","params":{"locator":{"url":"http://example.com/url"},"comment_id":"site"},"id":1}`, `{"error":"failed"}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
req := GetRequest{Locator: store.Locator{URL: "http://example.com/url"}, CommentID: "site"}
|
||||
_, err := c.Get(req)
|
||||
@@ -57,7 +57,7 @@ func TestRemote_GetWithErrorResult(t *testing.T) {
|
||||
func TestRemote_GetWithErrorDecode(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.get","params":{"locator":{"url":"http://example.com/url"},"comment_id":"site"},"id":1}`, ``)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
req := GetRequest{Locator: store.Locator{URL: "http://example.com/url"}, CommentID: "site"}
|
||||
_, err := c.Get(req)
|
||||
@@ -65,7 +65,7 @@ func TestRemote_GetWithErrorDecode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemote_GetWithErrorRemote(t *testing.T) {
|
||||
c := Remote{Client: remote.Client{API: "http://127.0.0.2", Client: http.Client{Timeout: 10 * time.Millisecond}}}
|
||||
c := RPC{Client: rpc.Client{API: "http://127.0.0.2", Client: http.Client{Timeout: 10 * time.Millisecond}}}
|
||||
|
||||
req := GetRequest{Locator: store.Locator{URL: "http://example.com/url"}, CommentID: "site"}
|
||||
_, err := c.Get(req)
|
||||
@@ -81,7 +81,7 @@ func TestRemote_FailedStatus(t *testing.T) {
|
||||
w.WriteHeader(400)
|
||||
}))
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
req := GetRequest{Locator: store.Locator{URL: "http://example.com/url"}, CommentID: "site"}
|
||||
_, err := c.Get(req)
|
||||
@@ -91,7 +91,7 @@ func TestRemote_FailedStatus(t *testing.T) {
|
||||
func TestRemote_Update(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.update","params":{"id":"123","pid":"","text":"msg","user":{"name":"","id":"","picture":"","admin":false},"locator":{"site":"site123","url":"http://example.com/url"},"score":0,"vote":0,"time":"0001-01-01T00:00:00Z"},"id":1}`, `{}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
err := c.Update(store.Comment{ID: "123", Locator: store.Locator{URL: "http://example.com/url", SiteID: "site123"},
|
||||
Text: "msg"})
|
||||
@@ -102,7 +102,7 @@ func TestRemote_Update(t *testing.T) {
|
||||
func TestRemote_Find(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.find","params":{"locator":{"url":"http://example.com/url"},"sort":"-time","since":"0001-01-01T00:00:00Z","limit":10},"id":1}`, `{"result":[{"text":"1"},{"text":"2"}]}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
res, err := c.Find(FindRequest{Locator: store.Locator{URL: "http://example.com/url"}, Sort: "-time", Limit: 10})
|
||||
assert.NoError(t, err)
|
||||
@@ -112,7 +112,7 @@ func TestRemote_Find(t *testing.T) {
|
||||
func TestRemote_Info(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.info","params":{"locator":{"url":"http://example.com/url"},"limit":10,"skip":5,"ro_age":10},"id":1}`, `{"result":[{"url":"u1","count":22},{"url":"u2","count":33}]}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
res, err := c.Info(InfoRequest{Locator: store.Locator{URL: "http://example.com/url"},
|
||||
Limit: 10, Skip: 5, ReadOnlyAge: 10})
|
||||
@@ -123,7 +123,7 @@ func TestRemote_Info(t *testing.T) {
|
||||
func TestRemote_Flag(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.flag","params":{"flag":"verified","locator":{"url":"http://example.com/url"}},"id":1}`, `{"result":false}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
res, err := c.Flag(FlagRequest{Locator: store.Locator{URL: "http://example.com/url"}, Flag: Verified})
|
||||
assert.NoError(t, err)
|
||||
@@ -133,7 +133,7 @@ func TestRemote_Flag(t *testing.T) {
|
||||
func TestRemote_ListFlag(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.list_flags","params":{"flag":"blocked","locator":{"site":"site_id","url":""}},"id":1}`, `{"result":[{"ID":"id1"},{"ID":"id2"}]}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
res, err := c.ListFlags(FlagRequest{Locator: store.Locator{SiteID: "site_id"}, Flag: Blocked})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []interface{}{map[string]interface{}{"ID": "id1"}, map[string]interface{}{"ID": "id2"}}, res)
|
||||
@@ -142,7 +142,7 @@ func TestRemote_ListFlag(t *testing.T) {
|
||||
func TestRemote_Count(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.count","params":{"locator":{"url":"http://example.com/url"},"since":"0001-01-01T00:00:00Z"},"id":1}`, `{"result":11}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
res, err := c.Count(FindRequest{Locator: store.Locator{URL: "http://example.com/url"}})
|
||||
assert.NoError(t, err)
|
||||
@@ -153,7 +153,7 @@ func TestRemote_Delete(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.delete","params":{"locator":{"url":"http://example.com/url"},"del_mode":0},"id":1}`,
|
||||
`{}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
|
||||
err := c.Delete(DeleteRequest{Locator: store.Locator{URL: "http://example.com/url"}})
|
||||
assert.NoError(t, err)
|
||||
@@ -162,7 +162,7 @@ func TestRemote_Delete(t *testing.T) {
|
||||
func TestRemote_Close(t *testing.T) {
|
||||
ts := testServer(t, `{"method":"store.close","id":1}`, `{}`)
|
||||
defer ts.Close()
|
||||
c := Remote{Client: remote.Client{API: ts.URL, Client: http.Client{}}}
|
||||
c := RPC{Client: rpc.Client{API: ts.URL, Client: http.Client{}}}
|
||||
err := c.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user