(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func 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 |
| 72 | Edit your profile or use the ` + "`--api-key`" + ` flag to provide an API key with the missing ACLs. |
nothing calls this directly
no test coverage detected