Files
LocalAI/pkg/testnetwork/guard_test.go
T
Richard Palethorpe d4b47a6e36 test: add offline resource infrastructure
Introduce versioned resource manifests, a checksum-verified CAS preparer, offline test wrappers, and a guarded network transport. Replace live Hugging Face, GitHub, and OCI cases with deterministic fixtures and inject fixture metadata into importer discovery.

Assisted-by: Codex:gpt-5
Signed-off-by: Richard Palethorpe <io@richiejp.com>
2026-07-29 12:57:25 +01:00

36 lines
964 B
Go

// SPDX-License-Identifier: MIT
package testnetwork_test
import (
"context"
"errors"
"net"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/mudler/LocalAI/pkg/testnetwork"
)
var _ = Describe("Guard", func() {
It("blocks a public IP before dialing", func() {
_, err := testnetwork.LocalGuard().DialContext(context.Background(), "tcp", "203.0.113.1:443")
Expect(err).To(MatchError(ContainSubstring("public dial blocked")))
})
It("allows loopback fixtures", func() {
guard := testnetwork.LocalGuard()
called := false
guard.Dial = func(_ context.Context, network, address string) (net.Conn, error) {
called = true
Expect(network).To(Equal("tcp"))
Expect(address).To(Equal("127.0.0.1:8080"))
return nil, errors.New("fixture dial sentinel")
}
_, err := guard.DialContext(context.Background(), "tcp", "127.0.0.1:8080")
Expect(err).To(MatchError("fixture dial sentinel"))
Expect(called).To(BeTrue())
})
})