chore: import upstream snapshot with attribution
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/larksuite/cli/internal/cmdutil"
|
||||
"github.com/larksuite/cli/internal/core"
|
||||
)
|
||||
|
||||
func TestTestNewRuntimeContextForAPIWiresFields(t *testing.T) {
|
||||
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
|
||||
cfg := &core.CliConfig{AppID: "self-test-app", AppSecret: "secret", Brand: core.BrandFeishu}
|
||||
f, _, _, _ := cmdutil.TestFactory(t, cfg)
|
||||
cmd := &cobra.Command{Use: "testing-helper"}
|
||||
|
||||
ctx := context.Background()
|
||||
rctx := TestNewRuntimeContextForAPI(ctx, cmd, cfg, f, core.AsBot)
|
||||
if rctx == nil {
|
||||
t.Fatal("TestNewRuntimeContextForAPI returned nil")
|
||||
}
|
||||
if rctx.Cmd != cmd {
|
||||
t.Errorf("Cmd not wired")
|
||||
}
|
||||
if rctx.Config != cfg {
|
||||
t.Errorf("Config not wired")
|
||||
}
|
||||
if rctx.Factory != f {
|
||||
t.Errorf("Factory not wired")
|
||||
}
|
||||
if !rctx.resolvedAs.IsBot() {
|
||||
t.Errorf("resolvedAs not set to bot, got %q", rctx.resolvedAs)
|
||||
}
|
||||
if rctx.Ctx() != ctx {
|
||||
t.Errorf("ctx not wired")
|
||||
}
|
||||
|
||||
// User identity should also be accepted — the whole reason for making
|
||||
// the parameter explicit is to let user-identity code paths use this
|
||||
// helper instead of forking a second one.
|
||||
userRctx := TestNewRuntimeContextForAPI(ctx, cmd, cfg, f, core.AsUser)
|
||||
if userRctx.resolvedAs != core.AsUser {
|
||||
t.Errorf("resolvedAs AsUser not preserved, got %q", userRctx.resolvedAs)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user