update coverage

This commit is contained in:
Philippe-Adrien Nousse 2018-07-25 16:52:55 +02:00
parent a936492816
commit bad0dac6f0
2 changed files with 244 additions and 201 deletions

View File

@ -1,42 +1,107 @@
mode: count
github.com/partitio/gonextcloud/utils.go:13.138,14.19 1 21
github.com/partitio/gonextcloud/utils.go:17.2,18.16 2 20
github.com/partitio/gonextcloud/utils.go:21.2,21.20 1 20
github.com/partitio/gonextcloud/utils.go:24.2,28.30 2 20
github.com/partitio/gonextcloud/utils.go:37.2,37.16 1 20
github.com/partitio/gonextcloud/utils.go:41.2,44.34 4 19
github.com/partitio/gonextcloud/utils.go:48.2,48.17 1 18
github.com/partitio/gonextcloud/users.go:15.47,18.16 2 1
github.com/partitio/gonextcloud/users.go:21.2,23.30 3 1
github.com/partitio/gonextcloud/users.go:18.16,20.3 1 0
github.com/partitio/gonextcloud/users.go:26.57,27.16 1 13
github.com/partitio/gonextcloud/users.go:30.2,31.16 2 12
github.com/partitio/gonextcloud/users.go:34.2,38.55 4 11
github.com/partitio/gonextcloud/users.go:41.2,41.25 1 11
github.com/partitio/gonextcloud/users.go:27.16,29.3 1 1
github.com/partitio/gonextcloud/users.go:31.16,33.3 1 1
github.com/partitio/gonextcloud/users.go:38.55,40.3 1 0
github.com/partitio/gonextcloud/users.go:44.62,49.16 3 1
github.com/partitio/gonextcloud/users.go:52.2,54.30 3 1
github.com/partitio/gonextcloud/users.go:49.16,51.3 1 0
github.com/partitio/gonextcloud/users.go:57.87,64.71 2 4
github.com/partitio/gonextcloud/users.go:67.2,67.17 1 3
github.com/partitio/gonextcloud/users.go:70.2,70.27 1 1
github.com/partitio/gonextcloud/users.go:64.71,66.3 1 1
github.com/partitio/gonextcloud/users.go:67.17,69.3 1 2
github.com/partitio/gonextcloud/users.go:73.48,75.2 1 3
github.com/partitio/gonextcloud/users.go:77.48,82.2 2 1
github.com/partitio/gonextcloud/users.go:84.49,89.2 2 1
github.com/partitio/gonextcloud/users.go:91.58,93.2 1 0
github.com/partitio/gonextcloud/users.go:95.53,99.19 4 2
github.com/partitio/gonextcloud/users.go:113.2,113.12 1 2
github.com/partitio/gonextcloud/users.go:117.2,117.35 1 2
github.com/partitio/gonextcloud/users.go:99.19,100.50 1 22
github.com/partitio/gonextcloud/users.go:100.50,102.38 2 12
github.com/partitio/gonextcloud/users.go:102.38,104.87 2 12
github.com/partitio/gonextcloud/users.go:104.87,109.6 1 0
github.com/partitio/gonextcloud/users.go:113.12,116.3 2 2
github.com/partitio/gonextcloud/users.go:120.67,122.2 1 1
github.com/partitio/gonextcloud/users.go:124.79,126.2 1 1
github.com/partitio/gonextcloud/users.go:128.67,130.2 1 1
github.com/partitio/gonextcloud/users.go:132.71,134.2 1 1
github.com/partitio/gonextcloud/users.go:136.71,138.2 1 1
github.com/partitio/gonextcloud/users.go:140.71,142.2 1 1
github.com/partitio/gonextcloud/users.go:144.73,146.2 1 1
github.com/partitio/gonextcloud/users.go:148.64,150.2 1 1
github.com/partitio/gonextcloud/users.go:152.63,154.16 2 1
github.com/partitio/gonextcloud/users.go:157.2,159.31 3 1
github.com/partitio/gonextcloud/users.go:154.16,156.3 1 0
github.com/partitio/gonextcloud/users.go:162.64,169.2 2 1
github.com/partitio/gonextcloud/users.go:171.67,178.2 2 0
github.com/partitio/gonextcloud/users.go:180.68,187.2 2 1
github.com/partitio/gonextcloud/users.go:189.67,196.2 2 1
github.com/partitio/gonextcloud/users.go:198.71,199.19 1 2
github.com/partitio/gonextcloud/users.go:202.2,205.16 4 2
github.com/partitio/gonextcloud/users.go:208.2,210.24 3 2
github.com/partitio/gonextcloud/users.go:199.19,201.3 1 0
github.com/partitio/gonextcloud/users.go:205.16,207.3 1 0
github.com/partitio/gonextcloud/users.go:213.83,221.2 2 20
github.com/partitio/gonextcloud/users.go:223.106,226.2 2 32
github.com/partitio/gonextcloud/users.go:228.40,230.25 2 44
github.com/partitio/gonextcloud/users.go:235.2,235.14 1 24
github.com/partitio/gonextcloud/users.go:230.25,231.15 1 180
github.com/partitio/gonextcloud/users.go:231.15,233.4 1 20
github.com/partitio/gonextcloud/utils.go:13.138,14.19 1 52
github.com/partitio/gonextcloud/utils.go:17.2,18.16 2 51
github.com/partitio/gonextcloud/utils.go:21.2,21.20 1 51
github.com/partitio/gonextcloud/utils.go:24.2,28.30 2 51
github.com/partitio/gonextcloud/utils.go:37.2,37.16 1 51
github.com/partitio/gonextcloud/utils.go:41.2,44.34 4 50
github.com/partitio/gonextcloud/utils.go:48.2,48.17 1 48
github.com/partitio/gonextcloud/utils.go:14.19,16.3 1 1
github.com/partitio/gonextcloud/utils.go:18.16,20.3 1 16
github.com/partitio/gonextcloud/utils.go:21.20,23.3 1 6
github.com/partitio/gonextcloud/utils.go:28.30,30.3 1 2
github.com/partitio/gonextcloud/utils.go:30.8,30.38 1 18
github.com/partitio/gonextcloud/utils.go:30.38,32.3 1 5
github.com/partitio/gonextcloud/utils.go:32.8,32.37 1 13
github.com/partitio/gonextcloud/utils.go:32.37,34.3 1 10
github.com/partitio/gonextcloud/utils.go:34.8,34.40 1 3
github.com/partitio/gonextcloud/utils.go:34.40,36.3 1 3
github.com/partitio/gonextcloud/utils.go:18.16,20.3 1 42
github.com/partitio/gonextcloud/utils.go:21.20,23.3 1 7
github.com/partitio/gonextcloud/utils.go:28.30,30.3 1 17
github.com/partitio/gonextcloud/utils.go:30.8,30.38 1 34
github.com/partitio/gonextcloud/utils.go:30.38,32.3 1 7
github.com/partitio/gonextcloud/utils.go:32.8,32.37 1 27
github.com/partitio/gonextcloud/utils.go:32.37,34.3 1 22
github.com/partitio/gonextcloud/utils.go:34.8,34.40 1 5
github.com/partitio/gonextcloud/utils.go:34.40,36.3 1 5
github.com/partitio/gonextcloud/utils.go:37.16,39.3 1 1
github.com/partitio/gonextcloud/utils.go:44.34,47.3 2 1
github.com/partitio/gonextcloud/utils.go:51.39,58.2 4 10
github.com/partitio/gonextcloud/apps.go:8.46,9.19 1 0
github.com/partitio/gonextcloud/apps.go:12.2,14.16 3 0
github.com/partitio/gonextcloud/apps.go:17.2,20.17 4 0
github.com/partitio/gonextcloud/apps.go:9.19,11.3 1 0
github.com/partitio/gonextcloud/apps.go:14.16,16.3 1 0
github.com/partitio/gonextcloud/apps.go:23.106,25.16 2 0
github.com/partitio/gonextcloud/apps.go:28.2,30.34 3 0
github.com/partitio/gonextcloud/apps.go:34.2,34.12 1 0
github.com/partitio/gonextcloud/apps.go:25.16,27.3 1 0
github.com/partitio/gonextcloud/apps.go:30.34,33.3 2 0
github.com/partitio/gonextcloud/utils.go:44.34,47.3 2 2
github.com/partitio/gonextcloud/utils.go:51.39,58.2 4 11
github.com/partitio/gonextcloud/apps.go:9.46,11.16 2 0
github.com/partitio/gonextcloud/apps.go:14.2,16.29 3 0
github.com/partitio/gonextcloud/apps.go:11.16,13.3 1 0
github.com/partitio/gonextcloud/apps.go:19.53,24.16 3 0
github.com/partitio/gonextcloud/apps.go:27.2,29.29 3 0
github.com/partitio/gonextcloud/apps.go:24.16,26.3 1 0
github.com/partitio/gonextcloud/apps.go:32.54,37.16 3 0
github.com/partitio/gonextcloud/apps.go:40.2,42.29 3 0
github.com/partitio/gonextcloud/apps.go:37.16,39.3 1 0
github.com/partitio/gonextcloud/apps.go:45.59,47.16 2 0
github.com/partitio/gonextcloud/apps.go:50.2,52.24 3 0
github.com/partitio/gonextcloud/apps.go:47.16,49.3 1 0
github.com/partitio/gonextcloud/apps.go:55.47,57.16 2 0
github.com/partitio/gonextcloud/apps.go:60.2,62.12 3 0
github.com/partitio/gonextcloud/apps.go:57.16,59.3 1 0
github.com/partitio/gonextcloud/apps.go:65.48,67.16 2 0
github.com/partitio/gonextcloud/apps.go:70.2,72.12 3 0
github.com/partitio/gonextcloud/apps.go:67.16,69.3 1 0
github.com/partitio/gonextcloud/apps.go:75.106,78.2 2 0
github.com/partitio/gonextcloud/auth.go:11.64,22.16 7 3
github.com/partitio/gonextcloud/auth.go:25.2,30.19 4 2
github.com/partitio/gonextcloud/auth.go:34.2,34.12 1 1
github.com/partitio/gonextcloud/auth.go:22.16,24.3 1 1
github.com/partitio/gonextcloud/auth.go:30.19,33.3 2 1
github.com/partitio/gonextcloud/auth.go:37.33,43.2 4 1
github.com/partitio/gonextcloud/auth.go:45.34,47.27 1 39
github.com/partitio/gonextcloud/auth.go:50.2,50.45 1 38
github.com/partitio/gonextcloud/auth.go:45.34,47.27 1 57
github.com/partitio/gonextcloud/auth.go:50.2,50.45 1 56
github.com/partitio/gonextcloud/auth.go:47.27,49.3 1 1
github.com/partitio/gonextcloud/client.go:58.50,60.16 2 3
github.com/partitio/gonextcloud/client.go:67.2,74.16 2 3
@ -60,66 +125,4 @@ github.com/partitio/gonextcloud/groups.go:55.77,57.3 1 0
github.com/partitio/gonextcloud/groups.go:61.67,63.16 2 0
github.com/partitio/gonextcloud/groups.go:66.2,68.30 3 0
github.com/partitio/gonextcloud/groups.go:63.16,65.3 1 0
github.com/partitio/gonextcloud/groups.go:71.107,73.16 2 2
github.com/partitio/gonextcloud/groups.go:76.2,78.12 3 2
github.com/partitio/gonextcloud/groups.go:73.16,75.3 1 0
github.com/partitio/gonextcloud/users.go:12.47,13.19 1 1
github.com/partitio/gonextcloud/users.go:16.2,18.16 3 1
github.com/partitio/gonextcloud/users.go:21.2,23.30 3 1
github.com/partitio/gonextcloud/users.go:13.19,15.3 1 0
github.com/partitio/gonextcloud/users.go:18.16,20.3 1 0
github.com/partitio/gonextcloud/users.go:26.57,27.16 1 11
github.com/partitio/gonextcloud/users.go:30.2,30.19 1 10
github.com/partitio/gonextcloud/users.go:33.2,36.16 4 10
github.com/partitio/gonextcloud/users.go:39.2,43.55 4 10
github.com/partitio/gonextcloud/users.go:46.2,46.34 1 9
github.com/partitio/gonextcloud/users.go:50.2,50.25 1 9
github.com/partitio/gonextcloud/users.go:27.16,29.3 1 1
github.com/partitio/gonextcloud/users.go:30.19,32.3 1 0
github.com/partitio/gonextcloud/users.go:36.16,38.3 1 0
github.com/partitio/gonextcloud/users.go:43.55,45.3 1 1
github.com/partitio/gonextcloud/users.go:46.34,49.3 2 0
github.com/partitio/gonextcloud/users.go:53.62,54.19 1 1
github.com/partitio/gonextcloud/users.go:57.2,62.16 4 1
github.com/partitio/gonextcloud/users.go:65.2,67.34 3 1
github.com/partitio/gonextcloud/users.go:71.2,71.30 1 1
github.com/partitio/gonextcloud/users.go:54.19,56.3 1 0
github.com/partitio/gonextcloud/users.go:62.16,64.3 1 0
github.com/partitio/gonextcloud/users.go:67.34,70.3 2 0
github.com/partitio/gonextcloud/users.go:74.69,82.2 2 2
github.com/partitio/gonextcloud/users.go:84.48,86.2 1 1
github.com/partitio/gonextcloud/users.go:88.48,93.2 2 1
github.com/partitio/gonextcloud/users.go:95.49,100.2 2 1
github.com/partitio/gonextcloud/users.go:102.58,104.2 1 0
github.com/partitio/gonextcloud/users.go:106.67,108.2 1 1
github.com/partitio/gonextcloud/users.go:110.79,112.2 1 1
github.com/partitio/gonextcloud/users.go:114.67,116.2 1 1
github.com/partitio/gonextcloud/users.go:118.71,120.2 1 1
github.com/partitio/gonextcloud/users.go:122.71,124.2 1 1
github.com/partitio/gonextcloud/users.go:126.71,128.2 1 1
github.com/partitio/gonextcloud/users.go:130.73,132.2 1 1
github.com/partitio/gonextcloud/users.go:134.64,136.2 1 1
github.com/partitio/gonextcloud/users.go:138.63,139.19 1 1
github.com/partitio/gonextcloud/users.go:142.2,145.16 4 1
github.com/partitio/gonextcloud/users.go:148.2,150.34 3 1
github.com/partitio/gonextcloud/users.go:154.2,154.31 1 1
github.com/partitio/gonextcloud/users.go:139.19,141.3 1 0
github.com/partitio/gonextcloud/users.go:145.16,147.3 1 0
github.com/partitio/gonextcloud/users.go:150.34,153.3 2 0
github.com/partitio/gonextcloud/users.go:157.64,164.2 2 1
github.com/partitio/gonextcloud/users.go:166.67,173.2 2 0
github.com/partitio/gonextcloud/users.go:175.68,182.2 2 1
github.com/partitio/gonextcloud/users.go:184.67,191.2 2 1
github.com/partitio/gonextcloud/users.go:193.71,194.19 1 2
github.com/partitio/gonextcloud/users.go:197.2,200.16 4 2
github.com/partitio/gonextcloud/users.go:203.2,205.34 3 2
github.com/partitio/gonextcloud/users.go:209.2,209.24 1 1
github.com/partitio/gonextcloud/users.go:194.19,196.3 1 0
github.com/partitio/gonextcloud/users.go:200.16,202.3 1 0
github.com/partitio/gonextcloud/users.go:205.34,208.3 2 1
github.com/partitio/gonextcloud/users.go:212.83,220.2 2 8
github.com/partitio/gonextcloud/users.go:222.106,224.16 2 16
github.com/partitio/gonextcloud/users.go:227.2,229.34 3 15
github.com/partitio/gonextcloud/users.go:233.2,233.12 1 15
github.com/partitio/gonextcloud/users.go:224.16,226.3 1 1
github.com/partitio/gonextcloud/users.go:229.34,232.3 2 0
github.com/partitio/gonextcloud/groups.go:71.107,74.2 2 2

View File

@ -60,9 +60,9 @@
<option value="file2">github.com/partitio/gonextcloud/client.go (85.7%)</option>
<option value="file3">github.com/partitio/gonextcloud/groups.go (39.5%)</option>
<option value="file3">github.com/partitio/gonextcloud/groups.go (35.3%)</option>
<option value="file4">github.com/partitio/gonextcloud/users.go (79.2%)</option>
<option value="file4">github.com/partitio/gonextcloud/users.go (89.0%)</option>
<option value="file5">github.com/partitio/gonextcloud/utils.go (100.0%)</option>
@ -92,36 +92,79 @@
import (
req "github.com/levigross/grequests"
"github.com/partitio/gonextcloud/types"
"net/http"
)
func (c *Client) AppList() ([]string, error) <span class="cov0" title="0">{
if !c.loggedIn() </span><span class="cov0" title="0">{
return nil, unauthorized
}</span>
<span class="cov0" title="0">u := c.baseURL.ResolveReference(routes.apps)
res, err := c.session.Get(u.String(), nil)
res, err := c.baseRequest(routes.apps, "", "", nil, http.MethodGet)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov0" title="0">var r types.AppListResponse
res.JSON(&amp;r)
return r.Ocs.Data.Apps, nil
return nil, nil</span>
return r.Ocs.Data.Apps, nil</span>
}
func (c *Client) appsBaseRequest(name string, route string, ro *req.RequestOptions, method string) error <span class="cov0" title="0">{
res, err := c.baseRequest(routes.apps, name, route, ro, method)
func (c *Client) AppListEnabled() ([]string, error) <span class="cov0" title="0">{
ro := &amp;req.RequestOptions{
Params: map[string]string{"filter": "enabled"},
}
res, err := c.baseRequest(routes.apps, "", "", ro, http.MethodGet)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov0" title="0">var r types.AppListResponse
res.JSON(&amp;r)
return r.Ocs.Data.Apps, nil</span>
}
func (c *Client) AppListDisabled() ([]string, error) <span class="cov0" title="0">{
ro := &amp;req.RequestOptions{
Params: map[string]string{"filter": "disabled"},
}
res, err := c.baseRequest(routes.apps, "", "", ro, http.MethodGet)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov0" title="0">var r types.AppListResponse
res.JSON(&amp;r)
return r.Ocs.Data.Apps, nil</span>
}
func (c *Client) AppInfos(name string) (types.App, error) <span class="cov0" title="0">{
res, err := c.baseRequest(routes.apps, name, "", nil, http.MethodGet)
if err != nil </span><span class="cov0" title="0">{
return types.App{}, err
}</span>
<span class="cov0" title="0">var r types.AppResponse
res.JSON(&amp;r)
return r.Ocs.Data, nil</span>
}
func (c *Client) AppEnable(name string) error <span class="cov0" title="0">{
res, err := c.baseRequest(routes.apps, name, "", nil, http.MethodPut)
if err != nil </span><span class="cov0" title="0">{
return err
}</span>
<span class="cov0" title="0">var r types.UserResponse
<span class="cov0" title="0">var r types.BaseResponse
res.JSON(&amp;r)
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov0" title="0">{
e := types.ErrorFromMeta(r.Ocs.Meta)
return &amp;e
}</span>
<span class="cov0" title="0">return nil</span>
return nil</span>
}
func (c *Client) AppDisable(name string) error <span class="cov0" title="0">{
res, err := c.baseRequest(routes.apps, name, "", nil, http.MethodDelete)
if err != nil </span><span class="cov0" title="0">{
return err
}</span>
<span class="cov0" title="0">var r types.BaseResponse
res.JSON(&amp;r)
return nil</span>
}
func (c *Client) appsBaseRequest(name string, route string, ro *req.RequestOptions, method string) error <span class="cov0" title="0">{
_, err := c.baseRequest(routes.apps, name, route, ro, method)
return err
}</span>
</pre>
<pre class="file" id="file1" style="display: none">package gonextcloud
@ -168,12 +211,12 @@ func (c *Client) Logout() error <span class="cov1" title="1">{
return nil
}</span>
func (c *Client) loggedIn() bool <span class="cov10" title="39">{
func (c *Client) loggedIn() bool <span class="cov10" title="57">{
// When authentication failed, capabilities doesn't contains core information
if c.capabilities == nil </span><span class="cov1" title="1">{
return false
}</span>
<span class="cov9" title="38">return c.capabilities.Core.WebdavRoot != ""</span>
<span class="cov9" title="56">return c.capabilities.Core.WebdavRoot != ""</span>
}
</pre>
@ -325,33 +368,28 @@ func (c *Client) GroupSubAdminList(name string) ([]string, error) <span class="c
}
func (c *Client) groupBaseRequest(name string, route string, ro *req.RequestOptions, method string) error <span class="cov10" title="2">{
res, err := c.baseRequest(routes.groups, name, route, ro, method)
if err != nil </span><span class="cov0" title="0">{
return err
}</span>
<span class="cov10" title="2">var r types.GroupListResponse
res.JSON(&amp;r)
return nil</span>
}
_, err := c.baseRequest(routes.groups, name, route, ro, method)
return err
}</span>
</pre>
<pre class="file" id="file4" style="display: none">package gonextcloud
import (
"encoding/json"
"github.com/fatih/structs"
req "github.com/levigross/grequests"
"github.com/partitio/gonextcloud/types"
"net/http"
"path"
"strconv"
"strings"
"sync"
)
func (c *Client) UserList() ([]string, error) <span class="cov1" title="1">{
if !c.loggedIn() </span><span class="cov0" title="0">{
return nil, unauthorized
}</span>
<span class="cov1" title="1">u := c.baseURL.ResolveReference(routes.users)
res, err := c.session.Get(u.String(), nil)
res, err := c.baseRequest(routes.users, "", "", nil, http.MethodGet)
//res, err := c.session.Get(u.String(), nil)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
@ -360,65 +398,54 @@ func (c *Client) UserList() ([]string, error) <span class="cov1" title="1">{
return r.Ocs.Data.Users, nil</span>
}
func (c *Client) User(name string) (*types.User, error) <span class="cov8" title="11">{
func (c *Client) User(name string) (*types.User, error) <span class="cov5" title="13">{
if name == "" </span><span class="cov1" title="1">{
return nil, &amp;types.APIError{Message: "name cannot be empty"}
}</span>
<span class="cov8" title="10">if !c.loggedIn() </span><span class="cov0" title="0">{
return nil, unauthorized
}</span>
<span class="cov8" title="10">u := c.baseURL.ResolveReference(routes.users)
u.Path = path.Join(u.Path, name)
res, err := c.session.Get(u.String(), nil)
if err != nil </span><span class="cov0" title="0">{
<span class="cov5" title="12">res, err := c.baseRequest(routes.users, name, "", nil, http.MethodGet)
if err != nil </span><span class="cov1" title="1">{
return nil, err
}</span>
<span class="cov8" title="10">var r types.UserResponse
<span class="cov5" title="11">var r types.UserResponse
js := res.String()
// Nextcloud does not encode JSON properly
js = reformatJSON(js)
if err := json.Unmarshal([]byte(js), &amp;r); err != nil </span><span class="cov1" title="1">{
if err := json.Unmarshal([]byte(js), &amp;r); err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov8" title="9">if r.Ocs.Meta.Statuscode != 100 </span><span class="cov0" title="0">{
e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &amp;e
}</span>
<span class="cov8" title="9">return &amp;r.Ocs.Data, nil</span>
<span class="cov5" title="11">return &amp;r.Ocs.Data, nil</span>
}
func (c *Client) UserSearch(search string) ([]string, error) <span class="cov1" title="1">{
if !c.loggedIn() </span><span class="cov0" title="0">{
return nil, unauthorized
}</span>
<span class="cov1" title="1">u := c.baseURL.ResolveReference(routes.users)
ro := &amp;req.RequestOptions{
Params: map[string]string{"search": search},
}
res, err := c.session.Get(u.String(), ro)
res, err := c.baseRequest(routes.users, "", "", ro, http.MethodGet)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov1" title="1">var r types.UserListResponse
res.JSON(&amp;r)
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov0" title="0">{
e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &amp;e
}</span>
<span class="cov1" title="1">return r.Ocs.Data.Users, nil</span>
return r.Ocs.Data.Users, nil</span>
}
func (c *Client) UserCreate(username string, password string) error <span class="cov3" title="2">{
func (c *Client) UserCreate(username string, password string, user *types.User) error <span class="cov3" title="4">{
ro := &amp;req.RequestOptions{
Data: map[string]string{
"userid": username,
"password": password,
},
}
return c.userBaseRequest("", "", ro, http.MethodPost)
}</span>
if err := c.userBaseRequest("", "", ro, http.MethodPost); err != nil </span><span class="cov1" title="1">{
return err
}</span>
<span class="cov2" title="3">if user == nil </span><span class="cov2" title="2">{
return nil
}</span>
<span class="cov1" title="1">return c.UserUpdate(user)</span>
}
func (c *Client) UserDelete(name string) error <span class="cov1" title="1">{
func (c *Client) UserDelete(name string) error <span class="cov2" title="3">{
return c.userBaseRequest(name, "", nil, http.MethodDelete)
}</span>
@ -440,6 +467,31 @@ func (c *Client) UserSendWelcomeEmail(name string) error <span class="cov0" titl
return c.userBaseRequest(name, "welcome", nil, http.MethodPost)
}</span>
func (c *Client) UserUpdate(user *types.User) error <span class="cov2" title="2">{
m := structs.Map(user)
errs := make(chan types.UpdateError)
var wg sync.WaitGroup
for k := range m </span><span class="cov6" title="22">{
if !ignoredUserField(k) &amp;&amp; m[k].(string) != "" </span><span class="cov5" title="12">{
wg.Add(1)
go func(key string, value string) </span><span class="cov5" title="12">{
defer wg.Done()
if err := c.userUpdateAttribute(user.ID, strings.ToLower(key), value); err != nil </span><span class="cov0" title="0">{
errs &lt;- types.UpdateError{
Field: key,
Error: err,
}
}</span>
}(k, m[k].(string))
}
}
<span class="cov2" title="2">go func() </span><span class="cov2" title="2">{
wg.Wait()
close(errs)
}</span>()
<span class="cov2" title="2">return types.NewUpdateError(errs)</span>
}
func (c *Client) UserUpdateEmail(name string, email string) error <span class="cov1" title="1">{
return c.userUpdateAttribute(name, "email", email)
}</span>
@ -473,22 +525,13 @@ func (c *Client) UserUpdateQuota(name string, quota int) error <span class="cov1
}</span>
func (c *Client) UserGroupList(name string) ([]string, error) <span class="cov1" title="1">{
if !c.loggedIn() </span><span class="cov0" title="0">{
return nil, unauthorized
}</span>
<span class="cov1" title="1">u := c.baseURL.ResolveReference(routes.users)
u.Path = path.Join(u.Path, name, "groups")
res, err := c.session.Get(u.String(), nil)
res, err := c.baseRequest(routes.users, name, "groups", nil, http.MethodGet)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov1" title="1">var r types.GroupListResponse
res.JSON(&amp;r)
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov0" title="0">{
e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &amp;e
}</span>
<span class="cov1" title="1">return r.Ocs.Data.Groups, nil</span>
return r.Ocs.Data.Groups, nil</span>
}
func (c *Client) UserGroupAdd(name string, group string) error <span class="cov1" title="1">{
@ -527,26 +570,22 @@ func (c *Client) UserGroupDemote(name string, group string) error <span class="c
return c.userBaseRequest(name, "subadmins", ro, http.MethodDelete)
}</span>
func (c *Client) UserGroupSubAdminList(name string) ([]string, error) <span class="cov3" title="2">{
func (c *Client) UserGroupSubAdminList(name string) ([]string, error) <span class="cov2" title="2">{
if !c.loggedIn() </span><span class="cov0" title="0">{
return nil, unauthorized
}</span>
<span class="cov3" title="2">u := c.baseURL.ResolveReference(routes.users)
<span class="cov2" title="2">u := c.baseURL.ResolveReference(routes.users)
u.Path = path.Join(u.Path, name, "subadmins")
res, err := c.session.Get(u.String(), nil)
if err != nil </span><span class="cov0" title="0">{
return nil, err
}</span>
<span class="cov3" title="2">var r types.BaseResponse
<span class="cov2" title="2">var r types.BaseResponse
res.JSON(&amp;r)
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov1" title="1">{
e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &amp;e
}</span>
<span class="cov1" title="1">return r.Ocs.Data, nil</span>
return r.Ocs.Data, nil</span>
}
func (c *Client) userUpdateAttribute(name string, key string, value string) error <span class="cov7" title="8">{
func (c *Client) userUpdateAttribute(name string, key string, value string) error <span class="cov6" title="20">{
ro := &amp;req.RequestOptions{
Data: map[string]string{
"key": key,
@ -556,18 +595,19 @@ func (c *Client) userUpdateAttribute(name string, key string, value string) erro
return c.userBaseRequest(name, "", ro, http.MethodPut)
}</span>
func (c *Client) userBaseRequest(name string, route string, ro *req.RequestOptions, method string) error <span class="cov10" title="16">{
res, err := c.baseRequest(routes.users, name, route, ro, method)
if err != nil </span><span class="cov1" title="1">{
return err
}</span>
<span class="cov9" title="15">var r types.UserResponse
res.JSON(&amp;r)
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov0" title="0">{
e := types.ErrorFromMeta(r.Ocs.Meta)
return &amp;e
}</span>
<span class="cov9" title="15">return nil</span>
func (c *Client) userBaseRequest(name string, route string, ro *req.RequestOptions, method string) error <span class="cov7" title="32">{
_, err := c.baseRequest(routes.users, name, route, ro, method)
return err
}</span>
func ignoredUserField(key string) bool <span class="cov7" title="44">{
keys := []string{"ID", "Quota", "Enabled", "Groups", "Language"}
for _, k := range keys </span><span class="cov10" title="180">{
if key == k </span><span class="cov6" title="20">{
return true
}</span>
}
<span class="cov6" title="24">return false</span>
}
</pre>
@ -583,45 +623,45 @@ import (
"strings"
)
func (c *Client) baseRequest(route *url.URL, name string, subroute string, ro *req.RequestOptions, method string) (*req.Response, error) <span class="cov10" title="21">{
func (c *Client) baseRequest(route *url.URL, name string, subroute string, ro *req.RequestOptions, method string) (*req.Response, error) <span class="cov10" title="52">{
if !c.loggedIn() </span><span class="cov1" title="1">{
return nil, unauthorized
}</span>
<span class="cov9" title="20">u := c.baseURL.ResolveReference(route)
if name != "" </span><span class="cov9" title="16">{
<span class="cov9" title="51">u := c.baseURL.ResolveReference(route)
if name != "" </span><span class="cov9" title="42">{
u.Path = path.Join(u.Path, name)
}</span>
<span class="cov9" title="20">if subroute != "" </span><span class="cov6" title="6">{
<span class="cov9" title="51">if subroute != "" </span><span class="cov5" title="7">{
u.Path = path.Join(u.Path, subroute)
}</span>
<span class="cov9" title="20">var (
<span class="cov9" title="51">var (
res *req.Response
err error
)
if method == http.MethodGet </span><span class="cov3" title="2">{
if method == http.MethodGet </span><span class="cov7" title="17">{
res, err = c.session.Get(u.String(), ro)
}</span> else<span class="cov9" title="18"> if method == http.MethodPost </span><span class="cov5" title="5">{
}</span> else<span class="cov9" title="34"> if method == http.MethodPost </span><span class="cov5" title="7">{
res, err = c.session.Post(u.String(), ro)
}</span> else<span class="cov8" title="13"> if method == http.MethodPut </span><span class="cov7" title="10">{
}</span> else<span class="cov8" title="27"> if method == http.MethodPut </span><span class="cov8" title="22">{
res, err = c.session.Put(u.String(), ro)
}</span> else<span class="cov4" title="3"> if method == http.MethodDelete </span><span class="cov4" title="3">{
}</span> else<span class="cov4" title="5"> if method == http.MethodDelete </span><span class="cov4" title="5">{
res, err = c.session.Delete(u.String(), ro)
}</span>
<span class="cov9" title="20">if err != nil </span><span class="cov1" title="1">{
<span class="cov9" title="51">if err != nil </span><span class="cov1" title="1">{
return nil, err
}</span>
// As we cannot read the ReaderCloser twice, we use the string content
<span class="cov9" title="19">js := res.String()
<span class="cov9" title="50">js := res.String()
var r types.BaseResponse
json.Unmarshal([]byte(js), &amp;r)
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov1" title="1">{
if r.Ocs.Meta.Statuscode != 100 </span><span class="cov2" title="2">{
err := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &amp;err
return nil, err
}</span>
<span class="cov9" title="18">return res, nil</span>
<span class="cov9" title="48">return res, nil</span>
}
func reformatJSON(json string) string <span class="cov7" title="10">{
func reformatJSON(json string) string <span class="cov6" title="11">{
// Nextcloud encode boolean as string
json = strings.Replace(json, "\"true\"", "true", -1)
json = strings.Replace(json, "\"false\"", "false", -1)