MCPcopy Index your code
hub / github.com/larksuite/cli / SkipWithoutUserToken

Function SkipWithoutUserToken

tests/cli_e2e/core.go:29–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27const CleanupTimeout = 30 * time.Second
28
29func SkipWithoutUserToken(t *testing.T) {
30 t.Helper()
31 if os.Getenv("LARKSUITE_CLI_USER_ACCESS_TOKEN") != "" {
32 return
33 }
34
35 ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
36 defer cancel()
37
38 result, err := RunCmd(ctx, Request{
39 Args: []string{"auth", "status", "--verify"},
40 })
41 if err != nil {
42 t.Skipf("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and failed to check local user login via `lark-cli auth status --verify`: %v", err)
43 }
44 if result.ExitCode != 0 {
45 t.Skipf("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and local user login check failed: exit=%d stderr=%s", result.ExitCode, strings.TrimSpace(result.Stderr))
46 }
47
48 stdout := strings.TrimSpace(result.Stdout)
49 if stdout == "" {
50 t.Skip("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and `lark-cli auth status --verify` returned empty stdout")
51 }
52 if !gjson.Valid(stdout) {
53 t.Skipf("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and `lark-cli auth status --verify` returned non-JSON stdout: %s", stdout)
54 }
55
56 if identity := gjson.Get(stdout, "identity").String(); identity != "user" {
57 t.Skip("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and local auth is not a verified user login")
58 }
59 if verified := gjson.Get(stdout, "verified"); verified.Exists() && !verified.Bool() {
60 verifyErr := gjson.Get(stdout, "verifyError").String()
61 if verifyErr != "" {
62 t.Skipf("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and local user login verification failed: %s", verifyErr)
63 }
64 t.Skip("skipped: LARKSUITE_CLI_USER_ACCESS_TOKEN not set and local user login verification failed")
65 }
66}
67
68// Request describes one lark-cli invocation.
69type Request struct {

Callers 1

TestSkipWithoutUserTokenFunction · 0.85

Calls 4

RunCmdFunction · 0.85
GetMethod · 0.65
BoolMethod · 0.65
StringMethod · 0.45

Tested by 1

TestSkipWithoutUserTokenFunction · 0.68