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,61 @@
|
||||
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/larksuite/cli/internal/core"
|
||||
"github.com/larksuite/cli/internal/httpmock"
|
||||
"github.com/larksuite/cli/internal/output"
|
||||
)
|
||||
|
||||
func TestTestFactory_ReplacesGlobals(t *testing.T) {
|
||||
config := &core.CliConfig{
|
||||
AppID: "test-app", AppSecret: "test-secret",
|
||||
Brand: core.BrandFeishu,
|
||||
}
|
||||
|
||||
f, stdout, stderr, reg := TestFactory(t, config)
|
||||
|
||||
// Factory should return our config
|
||||
got, err := f.Config()
|
||||
if err != nil {
|
||||
t.Fatalf("Config() error: %v", err)
|
||||
}
|
||||
if got.AppID != "test-app" {
|
||||
t.Errorf("want AppID test-app, got %s", got.AppID)
|
||||
}
|
||||
|
||||
// IOStreams.Out/ErrOut should be our buffers
|
||||
output.PrintJson(f.IOStreams.Out, map[string]string{"key": "value"})
|
||||
if !strings.Contains(stdout.String(), `"key"`) {
|
||||
t.Error("output.PrintJson did not write to test stdout")
|
||||
}
|
||||
|
||||
output.PrintError(f.IOStreams.ErrOut, "test error")
|
||||
if !strings.Contains(stderr.String(), "test error") {
|
||||
t.Error("output.PrintError did not write to test stderr")
|
||||
}
|
||||
|
||||
// Register a stub so Verify passes
|
||||
reg.Register(&httpmock.Stub{
|
||||
URL: "/test",
|
||||
Body: "ok",
|
||||
})
|
||||
// Use the stub via Factory HttpClient
|
||||
httpClient, err := f.HttpClient()
|
||||
if err != nil {
|
||||
t.Fatalf("HttpClient() error: %v", err)
|
||||
}
|
||||
baseURL := core.ResolveOpenBaseURL(core.BrandFeishu)
|
||||
req, _ := http.NewRequest("GET", baseURL+"/test", nil)
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("HttpClient request error: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user