| 27 | const CleanupTimeout = 30 * time.Second |
| 28 | |
| 29 | func 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. |
| 69 | type Request struct { |