Improved tests with random names and added docs

This commit is contained in:
Adphi 2018-10-16 15:24:44 +02:00
parent 1cc321d657
commit 91afc73ef6
5 changed files with 24 additions and 11 deletions

View File

@ -11,7 +11,7 @@ lint: ## Lint the files
@golint -set_exit_status ${PKG_LIST} @golint -set_exit_status ${PKG_LIST}
test: ## Run unittests test: ## Run unittests
@go test -v ${PKG_LIST} @go test -v .
race: dep ## Run data race detector race: dep ## Run data race detector
@go test -v -race ${PKG_LIST} @go test -v -race ${PKG_LIST}

2
doc.go
View File

@ -1,5 +1,5 @@
/* /*
Package client is a Go client for the Nextcloud Provisioning API. Package gonextcloud is a Go client for the Nextcloud Provisioning API.
For more information about the Provisioning API, see the documentation: For more information about the Provisioning API, see the documentation:
https://docs.nextcloud.com/server/13/admin_manual/configuration_user/user_provisioning_api.html https://docs.nextcloud.com/server/13/admin_manual/configuration_user/user_provisioning_api.html

View File

@ -76,7 +76,6 @@ var (
func(t *testing.T) { func(t *testing.T) {
us, err := c.UserList() us, err := c.UserList()
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, us, config.Login) assert.Contains(t, us, config.Login)
}, },
}, },
@ -195,7 +194,7 @@ var (
{ {
"TestUserCreateExisting", "TestUserCreateExisting",
func(t *testing.T) { func(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, password, nil) err := c.UserCreate(config.Login, password, nil)
assert.Error(t, err) assert.Error(t, err)
}, },
}, },
@ -480,11 +479,9 @@ func TestUserCreateWithoutPassword(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// Nextcloud does not seems to like recreating a deleted user // Nextcloud does not seems to like recreating a deleted user
rand.Seed(time.Now().Unix()) err := c.UserCreateWithoutPassword(config.NotExistingUser, config.Email, strings.Title(config.NotExistingUser))
n := fmt.Sprintf("%s-%s", config.NotExistingUser, strconv.Itoa(rand.Int()))
err := c.UserCreateWithoutPassword(n, config.Email, strings.Title(config.NotExistingUser))
assert.NoError(t, err) assert.NoError(t, err)
err = c.UserDelete(n) err = c.UserDelete(config.NotExistingUser)
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -534,11 +531,13 @@ func LoadConfig() error {
if e != "" { if e != "" {
config.Email = e config.Email = e
} }
config.NotExistingUser = fmt.Sprintf("%s-%s", config.NotExistingUser, strconv.Itoa(rand.Int()))
return nil return nil
} }
func initClient() error { func initClient() error {
if c == nil { if c == nil {
rand.Seed(time.Now().Unix())
if err := LoadConfig(); err != nil { if err := LoadConfig(); err != nil {
return err return err
} }

View File

@ -8,6 +8,7 @@ import (
"strconv" "strconv"
) )
//GroupFoldersList returns the groups folders
func (c *Client) GroupFoldersList() (map[int]types.GroupFolder, error) { func (c *Client) GroupFoldersList() (map[int]types.GroupFolder, error) {
res, err := c.baseRequest(http.MethodGet, routes.groupfolders, nil) res, err := c.baseRequest(http.MethodGet, routes.groupfolders, nil)
if err != nil { if err != nil {
@ -19,6 +20,7 @@ func (c *Client) GroupFoldersList() (map[int]types.GroupFolder, error) {
return gfs, nil return gfs, nil
} }
//GroupFolders returns the group folder details
func (c *Client) GroupFolders(id int) (types.GroupFolder, error) { func (c *Client) GroupFolders(id int) (types.GroupFolder, error) {
res, err := c.baseRequest(http.MethodGet, routes.groupfolders, nil, strconv.Itoa(id)) res, err := c.baseRequest(http.MethodGet, routes.groupfolders, nil, strconv.Itoa(id))
if err != nil { if err != nil {
@ -32,6 +34,7 @@ func (c *Client) GroupFolders(id int) (types.GroupFolder, error) {
return r.Ocs.Data.FormatGroupFolder(), nil return r.Ocs.Data.FormatGroupFolder(), nil
} }
//GroupFoldersCreate creates a group folder
func (c *Client) GroupFoldersCreate(name string) (id int, err error) { func (c *Client) GroupFoldersCreate(name string) (id int, err error) {
// TODO: Validate Folder name // TODO: Validate Folder name
ro := &req.RequestOptions{ ro := &req.RequestOptions{
@ -49,6 +52,7 @@ func (c *Client) GroupFoldersCreate(name string) (id int, err error) {
return id, nil return id, nil
} }
//GroupFoldersRename renames the group folder
func (c *Client) GroupFoldersRename(groupID int, name string) error { func (c *Client) GroupFoldersRename(groupID int, name string) error {
ro := &req.RequestOptions{ ro := &req.RequestOptions{
Data: map[string]string{ Data: map[string]string{
@ -64,10 +68,8 @@ func (c *Client) GroupFoldersRename(groupID int, name string) error {
} }
//TODO func (c *Client) GroupFoldersDelete(id int) error { //TODO func (c *Client) GroupFoldersDelete(id int) error {
// // GroupFolders's response does not give any clues about success or failure
// return nil
//}
//GroupFoldersAddGroup adds group to folder
func (c *Client) GroupFoldersAddGroup(folderID int, groupName string) error { func (c *Client) GroupFoldersAddGroup(folderID int, groupName string) error {
ro := &req.RequestOptions{ ro := &req.RequestOptions{
Data: map[string]string{ Data: map[string]string{
@ -82,6 +84,7 @@ func (c *Client) GroupFoldersAddGroup(folderID int, groupName string) error {
return nil return nil
} }
//GroupFoldersRemoveGroup remove a group from the group folder
func (c *Client) GroupFoldersRemoveGroup(folderID int, groupName string) error { func (c *Client) GroupFoldersRemoveGroup(folderID int, groupName string) error {
// GroupFolders's response does not give any clues about success or failure // GroupFolders's response does not give any clues about success or failure
_, err := c.baseRequest(http.MethodDelete, routes.groupfolders, nil, strconv.Itoa(folderID), "groups", groupName) _, err := c.baseRequest(http.MethodDelete, routes.groupfolders, nil, strconv.Itoa(folderID), "groups", groupName)
@ -91,6 +94,7 @@ func (c *Client) GroupFoldersRemoveGroup(folderID int, groupName string) error {
return nil return nil
} }
//GroupFoldersSetGroupPermissions set groups permissions
func (c *Client) GroupFoldersSetGroupPermissions(folderID int, groupName string, permission types.SharePermission) error { func (c *Client) GroupFoldersSetGroupPermissions(folderID int, groupName string, permission types.SharePermission) error {
ro := &req.RequestOptions{ ro := &req.RequestOptions{
Data: map[string]string{ Data: map[string]string{

View File

@ -9,6 +9,7 @@ import (
"sync" "sync"
) )
//SharesList list all shares of the logged in user
func (c *Client) SharesList() ([]types.Share, error) { func (c *Client) SharesList() ([]types.Share, error) {
res, err := c.baseRequest(http.MethodGet, routes.shares, nil) res, err := c.baseRequest(http.MethodGet, routes.shares, nil)
if err != nil { if err != nil {
@ -19,6 +20,7 @@ func (c *Client) SharesList() ([]types.Share, error) {
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
//Shares return shares from a specific file or folder
func (c *Client) Shares(path string, reshares bool, subfiles bool) ([]types.Share, error) { func (c *Client) Shares(path string, reshares bool, subfiles bool) ([]types.Share, error) {
ro := &req.RequestOptions{ ro := &req.RequestOptions{
Params: map[string]string{ Params: map[string]string{
@ -36,6 +38,7 @@ func (c *Client) Shares(path string, reshares bool, subfiles bool) ([]types.Shar
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
//Share Get information about a known Share
func (c *Client) Share(shareID string) (types.Share, error) { func (c *Client) Share(shareID string) (types.Share, error) {
res, err := c.baseRequest(http.MethodGet, routes.shares, nil, shareID) res, err := c.baseRequest(http.MethodGet, routes.shares, nil, shareID)
if err != nil { if err != nil {
@ -46,6 +49,7 @@ func (c *Client) Share(shareID string) (types.Share, error) {
return r.Ocs.Data[0], nil return r.Ocs.Data[0], nil
} }
//ShareCreate create a share
func (c *Client) ShareCreate( func (c *Client) ShareCreate(
path string, path string,
shareType types.ShareType, shareType types.ShareType,
@ -77,11 +81,13 @@ func (c *Client) ShareCreate(
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
//ShareDelete Remove the given share.
func (c *Client) ShareDelete(shareID int) error { func (c *Client) ShareDelete(shareID int) error {
_, err := c.baseRequest(http.MethodDelete, routes.shares, nil, strconv.Itoa(shareID)) _, err := c.baseRequest(http.MethodDelete, routes.shares, nil, strconv.Itoa(shareID))
return err return err
} }
// ShareUpdate update share details
// expireDate expireDate expects a well formatted date string, e.g. YYYY-MM-DD // expireDate expireDate expects a well formatted date string, e.g. YYYY-MM-DD
func (c *Client) ShareUpdate(shareUpdate types.ShareUpdate) error { func (c *Client) ShareUpdate(shareUpdate types.ShareUpdate) error {
errs := make(chan types.UpdateError) errs := make(chan types.UpdateError)
@ -130,19 +136,23 @@ func (c *Client) ShareUpdate(shareUpdate types.ShareUpdate) error {
return types.NewUpdateError(errs) return types.NewUpdateError(errs)
} }
// ShareUpdateExpireDate updates the share's expire date
// expireDate expects a well formatted date string, e.g. YYYY-MM-DD // expireDate expects a well formatted date string, e.g. YYYY-MM-DD
func (c *Client) ShareUpdateExpireDate(shareID int, expireDate string) error { func (c *Client) ShareUpdateExpireDate(shareID int, expireDate string) error {
return c.baseShareUpdate(strconv.Itoa(shareID), "expireDate", expireDate) return c.baseShareUpdate(strconv.Itoa(shareID), "expireDate", expireDate)
} }
//ShareUpdatePublicUpload enable or disable public upload
func (c *Client) ShareUpdatePublicUpload(shareID int, public bool) error { func (c *Client) ShareUpdatePublicUpload(shareID int, public bool) error {
return c.baseShareUpdate(strconv.Itoa(shareID), "publicUpload", strconv.FormatBool(public)) return c.baseShareUpdate(strconv.Itoa(shareID), "publicUpload", strconv.FormatBool(public))
} }
//ShareUpdatePassword updates share password
func (c *Client) ShareUpdatePassword(shareID int, password string) error { func (c *Client) ShareUpdatePassword(shareID int, password string) error {
return c.baseShareUpdate(strconv.Itoa(shareID), "password", password) return c.baseShareUpdate(strconv.Itoa(shareID), "password", password)
} }
//ShareUpdatePermissions update permissions
func (c *Client) ShareUpdatePermissions(shareID int, permissions types.SharePermission) error { func (c *Client) ShareUpdatePermissions(shareID int, permissions types.SharePermission) error {
return c.baseShareUpdate(strconv.Itoa(shareID), "permissions", strconv.Itoa(int(permissions))) return c.baseShareUpdate(strconv.Itoa(shareID), "permissions", strconv.Itoa(int(permissions)))
} }