chore(e2e): add addUsers helper func

This commit is contained in:
hexxa 2021-09-30 17:12:49 +08:00 committed by Hexxa
parent 74aa28d874
commit e1ad4c203e
2 changed files with 26 additions and 18 deletions

View file

@ -8,7 +8,7 @@ import (
"github.com/ihexxa/quickshare/src/client" "github.com/ihexxa/quickshare/src/client"
q "github.com/ihexxa/quickshare/src/handlers" q "github.com/ihexxa/quickshare/src/handlers"
"github.com/ihexxa/quickshare/src/userstore" // "github.com/ihexxa/quickshare/src/userstore"
) )
func TestConcurrency(t *testing.T) { func TestConcurrency(t *testing.T) {
@ -57,23 +57,7 @@ func TestConcurrency(t *testing.T) {
userCount := 5 userCount := 5
userPwd := "1234" userPwd := "1234"
users := map[string]string{} users := addUsers(t, addr, userPwd, userCount, token)
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
}
getFilePath := func(name string, i int) string { getFilePath := func(name string, i int) string {
return fmt.Sprintf("%s/files/home_file_%d", name, i) return fmt.Sprintf("%s/files/home_file_%d", name, i)

View file

@ -15,6 +15,7 @@ import (
"github.com/ihexxa/gocfg" "github.com/ihexxa/gocfg"
"github.com/ihexxa/quickshare/src/client" "github.com/ihexxa/quickshare/src/client"
fspkg "github.com/ihexxa/quickshare/src/fs" fspkg "github.com/ihexxa/quickshare/src/fs"
"github.com/ihexxa/quickshare/src/userstore"
) )
func startTestServer(config string) *Server { 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 { func isServerReady(addr string) bool {
retry := 20 retry := 20
setCl := client.NewSettingsClient(addr) setCl := client.NewSettingsClient(addr)