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
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmdutil
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
)
|
|
|
|
func TestCachedHttpClientFunc_ReturnsSameInstance(t *testing.T) {
|
|
fn := cachedHttpClientFunc(&Factory{IOStreams: &IOStreams{ErrOut: io.Discard}})
|
|
|
|
c1, err := fn()
|
|
if err != nil {
|
|
t.Fatalf("first call: %v", err)
|
|
}
|
|
if c1 == nil {
|
|
t.Fatal("first call returned nil")
|
|
}
|
|
|
|
c2, err := fn()
|
|
if err != nil {
|
|
t.Fatalf("second call: %v", err)
|
|
}
|
|
if c1 != c2 {
|
|
t.Error("expected same *http.Client instance on second call (cache hit)")
|
|
}
|
|
}
|
|
|
|
func TestCachedHttpClientFunc_HasTimeout(t *testing.T) {
|
|
fn := cachedHttpClientFunc(&Factory{IOStreams: &IOStreams{ErrOut: io.Discard}})
|
|
c, _ := fn()
|
|
if c.Timeout == 0 {
|
|
t.Error("expected non-zero timeout")
|
|
}
|
|
}
|
|
|
|
func TestCachedHttpClientFunc_HasRedirectPolicy(t *testing.T) {
|
|
fn := cachedHttpClientFunc(&Factory{IOStreams: &IOStreams{ErrOut: io.Discard}})
|
|
c, _ := fn()
|
|
if c.CheckRedirect == nil {
|
|
t.Error("expected CheckRedirect to be set (safeRedirectPolicy)")
|
|
}
|
|
}
|