-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.go
44 lines (34 loc) · 891 Bytes
/
test_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package bitbucket
import "os"
func getUser() string {
user := os.Getenv("BITBUCKET_USER")
return user
}
func getPassword() string {
pass := os.Getenv("BITBUCKET_PASSWORD")
return pass
}
func newTestV2Impl() *V2Impl {
return NewV2BasicAuth(getUser(), getPassword())
}
func newTestV1Impl() *V1Impl {
return NewV1BasicAuth(getUser(), getPassword())
}
func getTeamName(v2Impl *V2Impl) (string, error) {
teams, err := v2Impl.Teams.List(ListTeamsOpts{Role: AdminRole, Pagelen: 1})
if err != nil {
return "", err
}
return teams.Values[0]["username"].(string), nil
}
func getRepoAndTeam(v2Impl *V2Impl) (team string, repo string, err error) {
team, err = getTeamName(v2Impl)
if err != nil {
return
}
repos, err := v2Impl.Repositories.ListByOwner(team, ListReposByOwnerOpts{})
if err != nil {
return "", "", err
}
return team, repos.Values[0]["slug"].(string), nil
}