Tests retructuration

This commit is contained in:
Adphi 2018-10-16 09:34:56 +02:00
parent 9e549dd740
commit 74ee331f4f
4 changed files with 567 additions and 427 deletions

View File

@ -1,42 +1,3 @@
/*
Package client is a Go client for the Nextcloud Provisioning API.
For more information about the Provisioning API, see the documentation:
https://docs.nextcloud.com/server/13/admin_manual/configuration_user/user_provisioning_api.html
Usage
You use the library by creating a client object and calling methods on it.
For example, to list all the Nextcloud's instance users:
package main
import (
"fmt"
"gitlab.adphi.fr/partitio/Nextcloud-Partitio/gonextcloud/client"
)
func main() {
url := "https://www.mynextcloud.com"
username := "admin"
password := "password"
c, err := client.NewClient(url)
if err != nil {
panic(err)
}
if err := c.Login(username, password); err != nil {
panic(err)
}
defer c.Logout()
users, err := c.UserList()
if err != nil {
panic(err)
}
fmt.Println("Users :", users)
}
*/
package gonextcloud package gonextcloud
import ( import (

40
doc.go Normal file
View File

@ -0,0 +1,40 @@
/*
Package client is a Go client for the Nextcloud Provisioning API.
For more information about the Provisioning API, see the documentation:
https://docs.nextcloud.com/server/13/admin_manual/configuration_user/user_provisioning_api.html
Usage
You use the library by creating a client object and calling methods on it.
For example, to list all the Nextcloud's instance users:
package main
import (
"fmt"
"gitlab.adphi.fr/partitio/Nextcloud-Partitio/gonextcloud/client"
)
func main() {
url := "https://www.mynextcloud.com"
username := "admin"
password := "password"
c, err := client.NewClient(url)
if err != nil {
panic(err)
}
if err := c.Login(username, password); err != nil {
panic(err)
}
defer c.Logout()
users, err := c.UserList()
if err != nil {
panic(err)
}
fmt.Println("Users :", users)
}
*/
package gonextcloud

View File

@ -1,9 +1,8 @@
package gonextcloud package gonextcloud
import ( import (
"gitlab.adphi.fr/partitio/Nextcloud-Partitio/gonextcloud/types"
"github.com/partitio/swarmmanager/libnextcloudpartitio/utils"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.adphi.fr/partitio/Nextcloud-Partitio/gonextcloud/types"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -12,11 +11,6 @@ import (
"testing" "testing"
) )
var config = Config{}
var c *Client
const password = "somecomplicatedpassword"
type Config struct { type Config struct {
URL string `yaml:"url"` URL string `yaml:"url"`
Login string `yaml:"login"` Login string `yaml:"login"`
@ -27,6 +21,529 @@ type Config struct {
NotExistingGroup string `yaml:"not-existing-group"` NotExistingGroup string `yaml:"not-existing-group"`
} }
const password = "somecomplicatedpassword"
type test = func(t *testing.T)
var (
config = Config{}
c *Client
groupID = 37
provisionningTests = []struct {
string
test
}{
{
"TestLoadConfig",
func(t *testing.T) {
err := LoadConfig()
assert.NoError(t, err)
},
},
{
"create client",
func(t *testing.T) {
var err error
c, err = NewClient(config.URL)
assert.NoError(t, err, "aie")
},
},
{
"login failed",
func(t *testing.T) {
err := c.Login("", "")
assert.Error(t, err)
},
},
{
"login",
func(t *testing.T) {
err := c.Login(config.Login, config.Password)
assert.NoError(t, err)
},
},
{
"user list",
func(t *testing.T) {
us, err := c.UserList()
assert.NoError(t, err)
assert.Contains(t, us, config.Login)
},
},
{
"existing user",
func(t *testing.T) {
u, err := c.User(config.Login)
assert.NoError(t, err)
assert.NotNil(t, u)
},
},
{
"empty user",
func(t *testing.T) {
u, err := c.User("")
assert.Error(t, err)
assert.Empty(t, u)
},
},
{
"TestNonExistingUser",
func(t *testing.T) {
_, err := c.User(config.NotExistingUser)
assert.Error(t, err)
},
},
{
"TestUserSearch",
func(t *testing.T) {
us, err := c.UserSearch(config.Login)
assert.NoError(t, err)
assert.Contains(t, us, config.Login)
},
},
{
"TestUserCreate",
func(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, password, nil)
assert.NoError(t, err)
},
},
//{
// "TestUserCreateFull",
// func(t *testing.T) {
// if err := initClient(); err != nil {
// return
// }
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
// user := &types.User{
// ID: username,
// Displayname: strings.ToUpper(username),
// Email: "some@address.com",
// Address: "Main Street, City",
// Twitter: "@me",
// Phone: "42 42 242 424",
// Website: "my.site.com",
// }
// err := c.UserCreate(username, password, user)
// assert.NoError(t, err)
// u, err := c.User(username)
// assert.NoError(t, err)
// o := structs.Map(user)
// r := structs.Map(u)
// for k := range o {
// if ignoredUserField(k) {
// continue
// }
// assert.Equal(t, o[k], r[k])
// }
// // Clean up
// err = c.UserDelete(u.ID)
// assert.NoError(t, err)
// },
//},
//
//{
// "TestUserUpdate",
// func(t *testing.T) {
// if err := initClient(); err != nil {
// return
// }
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
// err := c.UserCreate(username, password, nil)
// assert.NoError(t, err)
// user := &types.User{
// ID: username,
// Displayname: strings.ToUpper(username),
// Email: "some@address.com",
// Address: "Main Street, City",
// Twitter: "@me",
// Phone: "42 42 242 424",
// Website: "my.site.com",
// }
// err = c.UserUpdate(user)
// assert.NoError(t, err)
// u, err := c.User(username)
// assert.NoError(t, err)
// o := structs.Map(user)
// r := structs.Map(u)
// for k := range o {
// if ignoredUserField(k) {
// continue
// }
// assert.Equal(t, o[k], r[k])
// }
// // Clean up
// err = c.UserDelete(u.ID)
// assert.NoError(t, err)
// },
//},
{
"TestUserCreateExisting",
func(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, password, nil)
assert.Error(t, err)
},
},
{
"TestGroupList",
func(t *testing.T) {
gs, err := c.GroupList()
assert.NoError(t, err)
assert.Contains(t, gs, "admin")
},
},
{
"TestGroupCreate",
func(t *testing.T) {
err := c.GroupCreate(config.NotExistingGroup)
assert.NoError(t, err)
},
},
{
"TestUserUpdateEmail",
func(t *testing.T) {
email := "my@mail.com"
err := c.UserUpdateEmail(config.NotExistingUser, email)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.Equal(t, email, u.Email)
},
},
{
"TestUserUpdateDisplayName",
func(t *testing.T) {
displayName := "Display Name"
err := c.UserUpdateDisplayName(config.NotExistingUser, displayName)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.Equal(t, displayName, u.Displayname)
},
},
{
"TestUserUpdatePhone",
func(t *testing.T) {
phone := "+33 42 42 42 42"
err := c.UserUpdatePhone(config.NotExistingUser, phone)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.Equal(t, phone, u.Phone)
},
},
{
"TestUserUpdateAddress",
func(t *testing.T) {
address := "Main Street, Galifrey"
err := c.UserUpdateAddress(config.NotExistingUser, address)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.Equal(t, address, u.Address)
},
},
{
"TestUserUpdateWebSite",
func(t *testing.T) {
website := "www.doctor.who"
err := c.UserUpdateWebSite(config.NotExistingUser, website)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.Equal(t, website, u.Website)
},
},
{
"TestUserUpdateTwitter",
func(t *testing.T) {
twitter := "@doctorwho"
err := c.UserUpdateTwitter(config.NotExistingUser, twitter)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.Equal(t, twitter, u.Twitter)
},
},
{
"TestUserUpdateQuota",
func(t *testing.T) {
quota := 1024 * 1024 * 1024
err := c.UserUpdateQuota(config.NotExistingUser, quota)
assert.NoError(t, err)
// TODO : Find better verification : A never connected User does not have quota available
//u, err := c.User(config.NotExistingUser)
//assert.NoError(t, err)
//assert.Equal(t, quota, u.Quota.Quota)
},
},
{
"TestUserUpdatePassword",
func(t *testing.T) {
password := "newcomplexpassword"
err := c.UserUpdatePassword(config.NotExistingUser, password)
assert.NoError(t, err)
}},
{
"TestUserGroupAdd",
func(t *testing.T) {
err := c.UserGroupAdd(config.NotExistingUser, config.NotExistingGroup)
assert.NoError(t, err)
gs, err := c.UserGroupList(config.NotExistingUser)
assert.NoError(t, err)
assert.Contains(t, gs, config.NotExistingGroup)
},
},
{
"TestUserGroupSubAdminList",
func(t *testing.T) {
gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
assert.NoError(t, err)
assert.Empty(t, gs)
},
},
{
"TestUserGroupPromote",
func(t *testing.T) {
err := c.UserGroupPromote(config.NotExistingUser, config.NotExistingGroup)
assert.NoError(t, err)
gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
assert.NoError(t, err)
assert.Contains(t, gs, config.NotExistingGroup)
},
},
{
"TestUserGroupDemote",
func(t *testing.T) {
err := c.UserGroupDemote(config.NotExistingUser, config.NotExistingGroup)
assert.NoError(t, err)
//gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
//assert.NoError(t, err)
//assert.Empty(t, gs)
},
},
{
"TestUserDisable",
func(t *testing.T) {
err := c.UserDisable(config.NotExistingUser)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.False(t, u.Enabled)
},
},
{
"TestUserEnable",
func(t *testing.T) {
err := c.UserEnable(config.NotExistingUser)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
if err != nil {
t.Fail()
return
}
assert.True(t, u.Enabled)
},
},
{
"TestGroupDelete",
func(t *testing.T) {
err := c.GroupDelete(config.NotExistingGroup)
assert.NoError(t, err)
},
},
{
"TestUserDelete",
func(t *testing.T) {
err := c.UserDelete(config.NotExistingUser)
assert.NoError(t, err)
},
},
{
"TestInvalidBaseRequest",
func(t *testing.T) {
c.baseURL = &url.URL{}
_, err := c.baseRequest(http.MethodGet, routes.capabilities, nil, "admin", "invalid")
c = nil
assert.Error(t, err)
},
},
{
"TestShareList",
func(t *testing.T) {
if err := initClient(); err != nil {
return
}
s, err := c.SharesList()
assert.NoError(t, err)
assert.NotNil(t, s)
},
},
{
"TestLogout",
func(t *testing.T) {
err := c.Logout()
assert.NoError(t, err)
assert.Nil(t, c.session.HTTPClient.Jar)
},
},
{
"TestLoggedIn",
func(t *testing.T) {
c := &Client{}
c.capabilities = &types.Capabilities{}
assert.False(t, c.loggedIn())
},
},
{
"TestLoginInvalidURL",
func(t *testing.T) {
c, _ = NewClient("")
err := c.Login("", "")
assert.Error(t, err)
},
},
{
"TestBaseRequest",
func(t *testing.T) {
c, _ = NewClient("")
_, err := c.baseRequest(http.MethodGet, routes.capabilities, nil, "admin", "invalid")
assert.Error(t, err)
},
},
}
groupFoldersTests = []struct {
string
test
}{
{
"TestGroupFoldersCreate",
func(t *testing.T) {
// Recreate client
var err error
groupID, err = c.GroupFoldersCreate("API")
assert.NoError(t, err)
},
},
{
"TestGroupFoldersList",
func(t *testing.T) {
gfs, err := c.GroupFoldersList()
assert.NoError(t, err)
assert.NotNil(t, gfs[groupID])
},
},
{
"TestGroupFolders",
func(t *testing.T) {
gf, err := c.GroupFolders(groupID)
assert.NoError(t, err)
assert.NotNil(t, gf)
},
},
{
"TestGroupFolderRename",
func(t *testing.T) {
err := c.GroupFoldersRename(groupID, "API_Renamed")
assert.NoError(t, err)
},
},
{
"TestGroupFoldersAddGroup",
func(t *testing.T) {
err := c.GroupFoldersAddGroup(groupID, "admin")
assert.NoError(t, err)
},
},
{
"TestGroupFoldersSetGroupPermissions",
func(t *testing.T) {
err := c.GroupFoldersSetGroupPermissions(groupID, "admin", types.ReadPermission)
assert.NoError(t, err)
},
},
{
"TestGroupFoldersSetQuota",
func(t *testing.T) {
err := c.GroupFoldersSetQuota(groupID, 100)
assert.NoError(t, err)
},
},
{
"TestGroupFolderRemoveGroup",
func(t *testing.T) {
err := c.GroupFoldersRemoveGroup(groupID, "admin")
assert.NoError(t, err)
},
},
}
)
func TestClient(t *testing.T) {
if err := initClient(); err != nil {
t.Fatal(err)
}
for _, tt := range provisionningTests {
t.Run(tt.string, tt.test)
}
}
func TestGroupFolders(t *testing.T) {
c = nil
if err := initClient(); err != nil {
t.Fatal(err)
}
for _, tt := range groupFoldersTests {
t.Run(tt.string, tt.test)
}
}
// LoadConfig loads the test configuration // LoadConfig loads the test configuration
func LoadConfig() error { func LoadConfig() error {
f, err := os.Open("./config.yml") f, err := os.Open("./config.yml")
@ -40,387 +557,6 @@ func LoadConfig() error {
return yaml.Unmarshal(b, &config) return yaml.Unmarshal(b, &config)
} }
func TestLoadConfig(t *testing.T) {
err := LoadConfig()
assert.NoError(t, err)
}
func TestClient(t *testing.T) {
var err error
c, err = NewClient(config.URL)
assert.NoError(t, err, "aie")
}
func TestLoginFail(t *testing.T) {
err := c.Login("", "")
assert.Error(t, err)
}
func TestLogin(t *testing.T) {
err := c.Login(config.Login, config.Password)
assert.NoError(t, err)
}
func TestUserList(t *testing.T) {
us, err := c.UserList()
assert.NoError(t, err)
assert.Contains(t, us, config.Login)
}
func TestExistingUser(t *testing.T) {
u, err := c.User(config.Login)
assert.NoError(t, err)
assert.NotNil(t, u)
}
func TestEmptyUser(t *testing.T) {
u, err := c.User("")
assert.Error(t, err)
assert.Empty(t, u)
}
func TestNonExistingUser(t *testing.T) {
_, err := c.User(config.NotExistingUser)
assert.Error(t, err)
}
func TestUserSearch(t *testing.T) {
us, err := c.UserSearch(config.Login)
assert.NoError(t, err)
assert.Contains(t, us, config.Login)
}
func TestUserCreate(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, password, nil)
assert.NoError(t, err)
}
//func TestUserCreateFull(t *testing.T) {
// if err := initClient(); err != nil {
// return
// }
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
// user := &types.User{
// ID: username,
// Displayname: strings.ToUpper(username),
// Email: "some@address.com",
// Address: "Main Street, City",
// Twitter: "@me",
// Phone: "42 42 242 424",
// Website: "my.site.com",
// }
// err := c.UserCreate(username, password, user)
// assert.Nil(t, err)
// u, err := c.User(username)
// assert.NoError(t, err)
// o := structs.Map(user)
// r := structs.Map(u)
// for k := range o {
// if ignoredUserField(k) {
// continue
// }
// assert.Equal(t, o[k], r[k])
// }
// // Clean up
// err = c.UserDelete(u.ID)
// assert.NoError(t, err)
//}
//func TestUserUpdate(t *testing.T) {
// if err := initClient(); err != nil {
// return
// }
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
// err := c.UserCreate(username, password, nil)
// assert.Nil(t, err)
// user := &types.User{
// ID: username,
// Displayname: strings.ToUpper(username),
// Email: "some@address.com",
// Address: "Main Street, City",
// Twitter: "@me",
// Phone: "42 42 242 424",
// Website: "my.site.com",
// }
// err = c.UserUpdate(user)
// assert.Nil(t, err)
// u, err := c.User(username)
// assert.Nil(t, err)
// o := structs.Map(user)
// r := structs.Map(u)
// for k := range o {
// if ignoredUserField(k) {
// continue
// }
// assert.Equal(t, o[k], r[k])
// }
// // Clean up
// err = c.UserDelete(u.ID)
// assert.NoError(t, err)
//}
func TestUserCreateExisting(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, password, nil)
assert.Error(t, err)
}
func TestGroupList(t *testing.T) {
gs, err := c.GroupList()
assert.NoError(t, err)
assert.Contains(t, gs, "admin")
}
func TestGroupCreate(t *testing.T) {
err := c.GroupCreate(config.NotExistingGroup)
assert.NoError(t, err)
}
func TestUserUpdateEmail(t *testing.T) {
email := "my@mail.com"
err := c.UserUpdateEmail(config.NotExistingUser, email)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.Equal(t, email, u.Email)
}
func TestUserUpdateDisplayName(t *testing.T) {
displayName := "Display Name"
err := c.UserUpdateDisplayName(config.NotExistingUser, displayName)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.Equal(t, displayName, u.Displayname)
}
func TestUserUpdatePhone(t *testing.T) {
phone := "+33 42 42 42 42"
err := c.UserUpdatePhone(config.NotExistingUser, phone)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.Equal(t, phone, u.Phone)
}
func TestUserUpdateAddress(t *testing.T) {
address := "Main Street, Galifrey"
err := c.UserUpdateAddress(config.NotExistingUser, address)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.Equal(t, address, u.Address)
}
func TestUserUpdateWebSite(t *testing.T) {
website := "www.doctor.who"
err := c.UserUpdateWebSite(config.NotExistingUser, website)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.Equal(t, website, u.Website)
}
func TestUserUpdateTwitter(t *testing.T) {
twitter := "@doctorwho"
err := c.UserUpdateTwitter(config.NotExistingUser, twitter)
assert.NoError(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.Equal(t, twitter, u.Twitter)
}
func TestUserUpdateQuota(t *testing.T) {
quota := 1024 * 1024 * 1024
err := c.UserUpdateQuota(config.NotExistingUser, quota)
assert.NoError(t, err)
// TODO : Find better verification : A never connected User does not have quota available
//u, err := c.User(config.NotExistingUser)
//assert.Nil(t, err)
//assert.Equal(t, quota, u.Quota.Quota)
}
func TestUserUpdatePassword(t *testing.T) {
password := "newcomplexpassword"
err := c.UserUpdatePassword(config.NotExistingUser, password)
assert.NoError(t, err)
}
func TestUserGroupAdd(t *testing.T) {
err := c.UserGroupAdd(config.NotExistingUser, config.NotExistingGroup)
assert.Nil(t, err)
gs, err := c.UserGroupList(config.NotExistingUser)
assert.NoError(t, err)
assert.Contains(t, gs, config.NotExistingGroup)
}
func TestUserGroupSubAdminList(t *testing.T) {
gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
assert.NoError(t, err)
assert.Empty(t, gs)
}
func TestUserGroupPromote(t *testing.T) {
err := c.UserGroupPromote(config.NotExistingUser, config.NotExistingGroup)
assert.Nil(t, err)
gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
assert.NoError(t, err)
assert.Contains(t, gs, config.NotExistingGroup)
}
func TestUserGroupDemote(t *testing.T) {
err := c.UserGroupDemote(config.NotExistingUser, config.NotExistingGroup)
assert.NoError(t, err)
//gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
//assert.Nil(t, err)
//assert.Empty(t, gs)
}
func TestUserDisable(t *testing.T) {
err := c.UserDisable(config.NotExistingUser)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.False(t, u.Enabled)
}
func TestUserEnable(t *testing.T) {
err := c.UserEnable(config.NotExistingUser)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.NoError(t, err)
assert.True(t, u.Enabled)
}
func TestGroupDelete(t *testing.T) {
err := c.GroupDelete(config.NotExistingGroup)
assert.Nil(t, err)
}
func TestUserDelete(t *testing.T) {
err := c.UserDelete(config.NotExistingUser)
assert.NoError(t, err)
}
func TestInvalidBaseRequest(t *testing.T) {
c.baseURL = &url.URL{}
_, err := c.baseRequest(http.MethodGet, routes.capabilities, nil, "admin", "invalid")
c = nil
assert.Error(t, err)
}
func TestShareList(t *testing.T) {
if err := initClient(); err != nil {
return
}
s, err := c.SharesList()
assert.NoError(t, err)
assert.NotNil(t, s)
}
func TestLogout(t *testing.T) {
err := c.Logout()
assert.NoError(t, err)
assert.Nil(t, c.session.HTTPClient.Jar)
}
func TestLoggedIn(t *testing.T) {
c := &Client{}
c.capabilities = &types.Capabilities{}
assert.False(t, c.loggedIn())
}
func TestLoginInvalidURL(t *testing.T) {
c, _ = NewClient("")
err := c.Login("", "")
assert.Error(t, err)
}
func TestBaseRequest(t *testing.T) {
c, _ = NewClient("")
_, err := c.baseRequest(http.MethodGet, routes.capabilities, nil, "admin", "invalid")
assert.Error(t, err)
}
var groupID = 37
func TestGroupFoldersCreate(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
var err error
groupID, err = c.GroupFoldersCreate("API")
assert.NoError(t, err)
}
func TestGroupFoldersList(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
gfs, err := c.GroupFoldersList()
assert.NoError(t, err)
utils.PrettyPrint(gfs)
assert.NotNil(t, gfs[groupID])
}
func TestGroupFolders(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
gf, err := c.GroupFolders(groupID)
assert.NoError(t, err)
utils.PrettyPrint(gf)
assert.NotNil(t, gf)
}
func TestGroupFolderRename(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
err := c.GroupFoldersRename(groupID, "API_Renamed")
assert.NoError(t, err)
}
func TestGroupFoldersAddGroup(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
err := c.GroupFoldersAddGroup(groupID, "admin")
assert.NoError(t, err)
}
func TestGroupFoldersSetGroupPermissions(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
err := c.GroupFoldersSetGroupPermissions(groupID, "admin", types.ReadPermission)
assert.NoError(t, err)
}
func TestGroupFoldersSetQuota(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
err := c.GroupFoldersSetQuota(groupID, 100)
assert.NoError(t, err)
}
func TestGroupFolderRemoveGroup(t *testing.T) {
c = nil
if err := initClient(); err != nil {
return
}
err := c.GroupFoldersRemoveGroup(groupID, "admin")
assert.NoError(t, err)
}
func initClient() error { func initClient() error {
if c == nil { if c == nil {
if err := LoadConfig(); err != nil { if err := LoadConfig(); err != nil {

View File

@ -59,6 +59,7 @@ func (c *Client) UserSearch(search string) ([]string, error) {
// UserCreate create a new user // UserCreate create a new user
func (c *Client) UserCreate(username string, password string, user *types.User) error { func (c *Client) UserCreate(username string, password string, user *types.User) error {
// Create base User
ro := &req.RequestOptions{ ro := &req.RequestOptions{
Data: map[string]string{ Data: map[string]string{
"userid": username, "userid": username,
@ -68,9 +69,11 @@ func (c *Client) UserCreate(username string, password string, user *types.User)
if err := c.userBaseRequest(http.MethodPost, ro); err != nil { if err := c.userBaseRequest(http.MethodPost, ro); err != nil {
return err return err
} }
// Check if we need to add user details information
if user == nil { if user == nil {
return nil return nil
} }
// Add user details information
return c.UserUpdate(user) return c.UserUpdate(user)
} }