MCPcopy Create free account
hub / github.com/algolia/cli / Test_CheckACLs

Function Test_CheckACLs

pkg/auth/auth_check_test.go:15–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func Test_CheckACLs(t *testing.T) {
16 // Remove these environment variables before the tests
17 os.Unsetenv("ALGOLIA_APPLICATION_ID")
18 os.Unsetenv("ALGOLIA_API_KEY")
19
20 tests := []struct {
21 name string
22 cmd *cobra.Command
23 adminKey bool
24 ACLs []search.Acl
25 wantErr bool
26 wantErrMessage string
27 }{
28 {
29 name: "need no acls",
30 cmd: &cobra.Command{
31 Annotations: map[string]string{},
32 },
33 adminKey: false,
34 ACLs: []search.Acl{},
35 wantErr: false,
36 },
37 {
38 name: "need admin key, not admin key",
39 cmd: &cobra.Command{
40 Annotations: map[string]string{
41 "acls": "admin",
42 },
43 },
44 adminKey: false,
45 ACLs: []search.Acl{},
46 wantErr: true,
47 wantErrMessage: "this command requires an admin API key. Use the `--api-key` flag with a valid admin API key",
48 },
49 {
50 name: "need admin key, admin key",
51 cmd: &cobra.Command{
52 Annotations: map[string]string{
53 "acls": "admin",
54 },
55 },
56 adminKey: true,
57 ACLs: []search.Acl{},
58 wantErr: false,
59 wantErrMessage: "",
60 },
61 {
62 name: "need ACLs, missing ACLs",
63 cmd: &cobra.Command{
64 Annotations: map[string]string{
65 "acls": "search",
66 },
67 },
68 adminKey: false,
69 ACLs: []search.Acl{},
70 wantErr: true,
71 wantErrMessage: `Missing API key ACL(s): search
72Edit your profile or use the ` + "`--api-key`" + ` flag to provide an API key with the missing ACLs.

Callers

nothing calls this directly

Calls 8

RegisterMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
ErrorResponseFunction · 0.92
NewFactoryFunction · 0.92
CheckACLsFunction · 0.85
ProfileMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected