mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 22:24:31 +08:00
* feat(auth): add scope hint for missing authorization errors * fix(auth): handle existing hints in missing scope error * refactor(auth): centralize user authorization error detection * fix(auth): handle nil error case in IsNeedUserAuthorizationError
39 lines
986 B
Go
39 lines
986 B
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package auth
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/larksuite/cli/internal/output"
|
|
)
|
|
|
|
func TestIsNeedUserAuthorizationError(t *testing.T) {
|
|
t.Run("nil error", func(t *testing.T) {
|
|
if IsNeedUserAuthorizationError(nil) {
|
|
t.Fatal("expected nil error not to match")
|
|
}
|
|
})
|
|
|
|
t.Run("direct auth error", func(t *testing.T) {
|
|
if !IsNeedUserAuthorizationError(&NeedAuthorizationError{UserOpenId: "u_1"}) {
|
|
t.Fatal("expected direct NeedAuthorizationError to match")
|
|
}
|
|
})
|
|
|
|
t.Run("wrapped exit error", func(t *testing.T) {
|
|
err := output.ErrNetwork("API call failed: %s", &NeedAuthorizationError{})
|
|
if !IsNeedUserAuthorizationError(err) {
|
|
t.Fatal("expected wrapped ExitError to match")
|
|
}
|
|
})
|
|
|
|
t.Run("other error", func(t *testing.T) {
|
|
err := output.ErrNetwork("API call failed: timeout")
|
|
if IsNeedUserAuthorizationError(err) {
|
|
t.Fatal("expected unrelated error not to match")
|
|
}
|
|
})
|
|
}
|