MCPcopy Create free account
hub / github.com/openclaw/gogcli / TestExecute_AuthAdd_JSON

Function TestExecute_AuthAdd_JSON

internal/cmd/execute_auth_add_test.go:15–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestExecute_AuthAdd_JSON(t *testing.T) {
16 store := newMemSecretsStore()
17
18 var gotOpts googleauth.AuthorizeOptions
19 runtime := &app.Runtime{Auth: app.AuthOperations{
20 OpenSecretsStore: func() (secrets.Store, error) { return store, nil },
21 EnsureKeychainAccess: func(context.Context) error { return nil },
22 AuthorizeGoogle: func(_ context.Context, opts googleauth.AuthorizeOptions) (string, error) {
23 gotOpts = opts
24 gotOpts.Services = append([]googleauth.Service{}, opts.Services...)
25 gotOpts.Scopes = append([]string{}, opts.Scopes...)
26 return "rt", nil
27 },
28 FetchAuthorizedIdentity: func(context.Context, string, string, []string, time.Duration) (googleauth.Identity, error) {
29 return googleauth.Identity{Email: "a@b.com"}, nil
30 },
31 }}
32
33 result := executeWithTestRuntime(t, []string{
34 "--json", "auth", "add", "a@b.com", "--services", "calendar,gmail",
35 }, runtime)
36 if result.err != nil {
37 t.Fatalf("Execute: %v", result.err)
38 }
39
40 var parsed struct {
41 Stored bool `json:"stored"`
42 Email string `json:"email"`
43 Services []string `json:"services"`
44 }
45 if err := json.Unmarshal([]byte(result.stdout), &parsed); err != nil {
46 t.Fatalf("json parse: %v\nout=%q", err, result.stdout)
47 }
48 if !parsed.Stored || parsed.Email != "a@b.com" || len(parsed.Services) != 2 {
49 t.Fatalf("unexpected: %#v", parsed)
50 }
51
52 tok, err := store.GetToken(config.DefaultClientName, "a@b.com")
53 if err != nil {
54 t.Fatalf("GetToken: %v", err)
55 }
56 if tok.RefreshToken != "rt" {
57 t.Fatalf("unexpected token: %#v", tok)
58 }
59
60 _ = gotOpts // keep for future assertions; ensures auth add actually called authorizeGoogle.
61}

Callers

nothing calls this directly

Calls 3

newMemSecretsStoreFunction · 0.85
executeWithTestRuntimeFunction · 0.85
GetTokenMethod · 0.65

Tested by

no test coverage detected