chore(e2e): add addUsers helper func
This commit is contained in:
parent
74aa28d874
commit
e1ad4c203e
2 changed files with 26 additions and 18 deletions
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/ihexxa/quickshare/src/client"
|
||||
q "github.com/ihexxa/quickshare/src/handlers"
|
||||
"github.com/ihexxa/quickshare/src/userstore"
|
||||
// "github.com/ihexxa/quickshare/src/userstore"
|
||||
)
|
||||
|
||||
func TestConcurrency(t *testing.T) {
|
||||
|
@ -57,23 +57,7 @@ func TestConcurrency(t *testing.T) {
|
|||
|
||||
userCount := 5
|
||||
userPwd := "1234"
|
||||
users := map[string]string{}
|
||||
getUserName := func(id int) string {
|
||||
return fmt.Sprintf("user_%d", id)
|
||||
}
|
||||
|
||||
for i := range make([]int, userCount) {
|
||||
userName := getUserName(i)
|
||||
|
||||
resp, adResp, errs := usersCl.AddUser(userName, userPwd, userstore.UserRole, token)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
} else if resp.StatusCode != 200 {
|
||||
t.Fatal("failed to add user")
|
||||
}
|
||||
|
||||
users[userName] = adResp.ID
|
||||
}
|
||||
users := addUsers(t, addr, userPwd, userCount, token)
|
||||
|
||||
getFilePath := func(name string, i int) string {
|
||||
return fmt.Sprintf("%s/files/home_file_%d", name, i)
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/ihexxa/gocfg"
|
||||
"github.com/ihexxa/quickshare/src/client"
|
||||
fspkg "github.com/ihexxa/quickshare/src/fs"
|
||||
"github.com/ihexxa/quickshare/src/userstore"
|
||||
)
|
||||
|
||||
func startTestServer(config string) *Server {
|
||||
|
@ -51,6 +52,29 @@ func setUpEnv(t *testing.T, rootPath string, adminName, adminPwd string) {
|
|||
}
|
||||
}
|
||||
|
||||
func getUserName(id int) string {
|
||||
return fmt.Sprintf("user_%d", id)
|
||||
}
|
||||
|
||||
func addUsers(t *testing.T, addr, userPwd string, userCount int, adminToken *http.Cookie) map[string]string {
|
||||
usersCl := client.NewSingleUserClient(addr)
|
||||
users := map[string]string{}
|
||||
for i := range make([]int, userCount) {
|
||||
userName := getUserName(i)
|
||||
|
||||
resp, adResp, errs := usersCl.AddUser(userName, userPwd, userstore.UserRole, adminToken)
|
||||
if len(errs) > 0 {
|
||||
t.Fatal(errs)
|
||||
} else if resp.StatusCode != 200 {
|
||||
t.Fatal("failed to add user")
|
||||
}
|
||||
|
||||
users[userName] = adResp.ID
|
||||
}
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
func isServerReady(addr string) bool {
|
||||
retry := 20
|
||||
setCl := client.NewSettingsClient(addr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue