FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sourcegraph/dev/authtest/organization_test.go at main · TiO2/sourcegraph · GitHub
TiO2
/
sourcegraph
Public
forked from
sourcegraph/sourcegraph-public-snapshot
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sourcegraph
/
dev
/
authtest
/
organization_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
110 lines (103 loc) · 2.64 KB
Breadcrumbs
sourcegraph
/
dev
/
authtest
/
organization_test.go
Copy path
File metadata and controls
110 lines (103 loc) · 2.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package
authtest
import
(
"fmt"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sourcegraph/sourcegraph/internal/gqltestutil"
)
func
TestOrganization
(
t
*
testing.
T
) {
const
testOrgName
=
"authtest-organization"
orgID
,
err
:=
client
.
CreateOrganization
(
testOrgName
,
testOrgName
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
func
() {
err
:=
client
.
DeleteOrganization
(
orgID
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
// Create a test user (authtest-user-organization) which is not a member of
// "authtest-organization", the user should not have access to any of the
// organization's resources.
const
testUsername
=
"authtest-user-organization"
userClient
,
err
:=
gqltestutil
.
SignUp
(
*
baseURL
,
testUsername
+
"@sourcegraph.com"
,
testUsername
,
"mysecurepassword"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
func
() {
err
:=
client
.
DeleteUser
(
userClient
.
AuthenticatedUserID
(),
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
t
.
Run
(
"view organization"
,
func
(
t
*
testing.
T
) {
org
,
err
:=
userClient
.
Organization
(
testOrgName
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
false
,
org
.
ViewerIsMember
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
tests
:=
[]
struct
{
name
string
run
func
()
error
wantErr
string
}{
{
name
:
"settings cascade"
,
run
:
func
()
error
{
_
,
err
:=
userClient
.
SettingsCascade
(
orgID
)
return
err
},
wantErr
:
"current user is not an org member"
,
},
{
name
:
"overwrite settings"
,
run
:
func
()
error
{
return
userClient
.
OverwriteSettings
(
orgID
,
"test config"
)
},
wantErr
:
"current user is not an org member"
,
},
{
name
:
"update organization"
,
run
:
func
()
error
{
return
userClient
.
UpdateOrganization
(
orgID
,
"new name"
)
},
wantErr
:
"current user is not an org member"
,
},
{
name
:
"view organization memebers"
,
run
:
func
()
error
{
_
,
err
:=
userClient
.
OrganizationMembers
(
orgID
)
return
err
},
wantErr
:
"must be a member of this organization to view members"
,
},
{
name
:
"invite user to organization"
,
run
:
func
()
error
{
_
,
err
:=
userClient
.
InviteUserToOrganization
(
orgID
,
testUsername
,
""
)
return
err
},
wantErr
:
"current user is not an org member"
,
},
{
name
:
"remove user from organization"
,
run
:
func
()
error
{
return
userClient
.
RemoveUserFromOrganization
(
userClient
.
AuthenticatedUserID
(),
orgID
)
},
wantErr
:
"current user is not an org member"
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing.
T
) {
got
:=
fmt
.
Sprintf
(
"%v"
,
test
.
run
())
if
!
strings
.
Contains
(
got
,
test
.
wantErr
) {
t
.
Fatalf
(
"Want %q but got %q"
,
test
.
wantErr
,
got
)
}
})
}
}
Back
|
FazBrowse Home
|
New Git URL