Files
larksuite--cli/internal/cmdutil/testing_test.go
T
wehub-resource-sync bf9395e022
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
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

62 lines
1.5 KiB
Go

// 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()
}